Interface Batch
-
- All Superinterfaces:
DatastoreBatchWriter,DatastoreWriter
@NotThreadSafe public interface Batch extends DatastoreBatchWriter
An interface to represent a batch of write operations. Any write operation that is applied on a batch will only be sent to the Datastore uponsubmit(). A usage example:Entity entity1 = datastore.get(key1); Batch batch = datastore.newBatch(); Entity entity2 = Entity.newBuilder(key2).set("name", "John").build(); entity1 = Entity.newBuilder(entity1).clear().setNull("bla").build(); Entity entity3 = Entity.newBuilder(key3).set("title", "title").build(); batch.update(entity1); batch.add(entity2, entity3); batch.submit();WARNING: This class maintains an internal state in terms of
LinkedHashMapandLinkedHashSetwhich gets updated on every method call performing CRUD operations to record the mutations. SinceLinkedHashMapis not thread safe as per its documentation, This class too should not be treated as a thread safe class.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interfaceBatch.Response
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description Entityadd(FullEntity<?> entity)Datastore add operation: inserts the provided entity.List<Entity>add(FullEntity<?>... entities)Datastore add operation: inserts the provided entities.DatastoregetDatastore()Returns the batch associatedDatastore.Batch.Responsesubmit()Submit the batch to the Datastore.-
Methods inherited from interface com.google.cloud.datastore.DatastoreBatchWriter
addWithDeferredIdAllocation, delete, isActive, put, put, putWithDeferredIdAllocation, update
-
-
-
-
Method Detail
-
add
Entity add(FullEntity<?> entity)
Datastore add operation: inserts the provided entity. This method will automatically allocate an id if necessary. Ifentityhas a complete key and was already marked for deletion in this writer, the operation will be changed toDatastoreBatchWriter.put(com.google.cloud.datastore.FullEntity<?>).If an entity for
entity.getKey()does not exists,entityis inserted. Otherwise,submit()will throw aDatastoreExceptionwithBaseServiceException.getReason()equal to"ALREADY_EXISTS".- Specified by:
addin interfaceDatastoreBatchWriter- Specified by:
addin interfaceDatastoreWriter- Parameters:
entity- the entity to add- Returns:
- an
Entitywith the same properties and a key that is either newly allocated or the same one if key is already complete
-
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 toDatastoreBatchWriter.put(com.google.cloud.datastore.FullEntity<?>).If none of entities' keys exist, all entities are inserted. If any of entities' keys already exists,
submit()will throw aDatastoreExceptionwithBaseServiceException.getReason()equal to"ALREADY_EXISTS". All entities inentitieswhose key did not exist are inserted.- Specified by:
addin interfaceDatastoreBatchWriter- Specified by:
addin interfaceDatastoreWriter- Returns:
- a list of
Entityordered by input with the same properties and a key that is either newly allocated or the same one if was already complete - See Also:
DatastoreWriter.add(FullEntity)
-
submit
Batch.Response submit()
Submit the batch to the Datastore.- Throws:
DatastoreException- if there was any failure or if batch is not longer active
-
-