Package com.google.cloud.datastore
Interface DatastoreBatchWriter
-
- All Superinterfaces:
DatastoreWriter
- All Known Subinterfaces:
Batch
,Transaction
- All Known Implementing Classes:
BaseDatastoreBatchWriter
@NotThreadSafe public interface DatastoreBatchWriter extends DatastoreWriter
An interface to represent a batch of write operations. All write operation for a batch writer will be applied to the Datastore in one RPC call.WARNING: This class maintains an internal state in terms of
LinkedHashMap
andLinkedHashSet
which gets updated on every method call performing CRUD operations to record the mutations. SinceLinkedHashMap
is not thread safe as per its documentation, This class too should not be treated as a thread safe class.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description Entity
add(FullEntity<?> entity)
Datastore add operation: inserts the provided entity.List<Entity>
add(FullEntity<?>... entities)
Datastore add operation: inserts the provided entities.void
addWithDeferredIdAllocation(FullEntity<?>... entities)
Datastore add operation.void
delete(Key... keys)
A datastore delete operation.boolean
isActive()
Returnstrue
if still active (write operations were not sent to the Datastore).Entity
put(FullEntity<?> entity)
A Datastore put (a.k.a upsert) operation: inserts an entity if it does not exist, updates it otherwise.List<Entity>
put(FullEntity<?>... entities)
A Datastore put (a.k.a upsert) operation: creates an entity if it does not exist, updates it otherwise.void
putWithDeferredIdAllocation(FullEntity<?>... entities)
Datastore put operation.void
update(Entity... entities)
A Datastore update operation.
-
-
-
Method Detail
-
addWithDeferredIdAllocation
void addWithDeferredIdAllocation(FullEntity<?>... entities)
Datastore add operation. This method will also allocate id for any entity with an incomplete key. As opposed toadd(FullEntity)
andadd(FullEntity...)
, this method will defer any necessary id allocation to submit time.- Throws:
IllegalArgumentException
- if any of the given entities is missing a keyDatastoreException
- if a given entity with a complete key was already added to this writer or if not active
-
add
Entity add(FullEntity<?> entity)
Datastore add operation: inserts the provided entity. This method will automatically allocate an id if necessary. Ifentity
has a complete key and was already marked for deletion in this writer, the operation will be changed toput(com.google.cloud.datastore.FullEntity<?>)
.- Specified by:
add
in interfaceDatastoreWriter
- Parameters:
entity
- the entity to add- Returns:
- an
Entity
with the same properties and a key that is either newly allocated or the same one if key is already complete - Throws:
DatastoreException
- if a given entity with the same complete key was already added to this writer, if writer is not active or if id allocation for an entity with an incomplete key failed
-
add
List<Entity> add(FullEntity<?>... entities)
Datastore add operation: inserts the provided entities. This method will automatically allocate id for any entity with an incomplete key. For entities with complete keys that were marked for deletion in this writer the operation will be changed toput(com.google.cloud.datastore.FullEntity<?>)
.- Specified by:
add
in interfaceDatastoreWriter
- Returns:
- a list of
Entity
ordered by input with the same properties and a key that is either newly allocated or the same one if was already complete - Throws:
DatastoreException
- if a given entity with the same complete key was already added to this writer, if writer is not active or if id allocation for an entity with an incomplete key failed- See Also:
DatastoreWriter.add(FullEntity)
-
update
void update(Entity... entities)
A Datastore update operation. The operation will fail if an entity with the same key does not already exist. This operation will be converted toput(com.google.cloud.datastore.FullEntity<?>)
operation for entities that were already added or put in this writer.- Specified by:
update
in interfaceDatastoreWriter
- Throws:
DatastoreException
- if an entity is marked for deletion in this writer or if not active
-
delete
void delete(Key... keys)
A datastore delete operation. It is OK to request the deletion of a non-existing key. This operation will also remove from this batch any prior writes for entities with the same keys.- Specified by:
delete
in interfaceDatastoreWriter
- Throws:
DatastoreException
- if not active
-
putWithDeferredIdAllocation
void putWithDeferredIdAllocation(FullEntity<?>... entities)
Datastore put operation. This method will also allocate id for any entity with an incomplete key. As opposed toput(FullEntity)
andput(FullEntity...)
, this method will defer any necessary id allocation to submit time.- Throws:
IllegalArgumentException
- if any of the given entities is missing a keyDatastoreException
- if not active
-
put
Entity put(FullEntity<?> entity)
A Datastore put (a.k.a upsert) operation: inserts an entity if it does not exist, updates it otherwise. This method will automatically allocate an id if necessary. This operation will also remove from this writer any prior writes for the same entity.- Specified by:
put
in interfaceDatastoreWriter
- Parameters:
entity
- the entity to put- Returns:
- an
Entity
with the same properties and a key that is either newly allocated or the same one if key is already complete - Throws:
DatastoreException
- if not active or if id allocation for an entity with an incomplete key failed
-
put
List<Entity> put(FullEntity<?>... entities)
A Datastore put (a.k.a upsert) operation: creates an entity if it does not exist, updates it otherwise. This method will automatically allocate id for any entity with an incomplete key. This operation will also remove from this writer any prior writes for the same entities.- Specified by:
put
in interfaceDatastoreWriter
- Returns:
- a list of updated or inserted
Entity
, ordered by input. Returned keys are either newly allocated or the same one if was already complete. - Throws:
DatastoreException
- if not active or if id allocation for an entity with an incomplete key failed
-
isActive
boolean isActive()
Returnstrue
if still active (write operations were not sent to the Datastore).
-
-