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 upon #submit. 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();
Implements
DatastoreBatchWriterMethods
add(FullEntity<?> entity)
public abstract Entity add(FullEntity<?> entity)
Datastore add operation: inserts the provided entity. This method will automatically allocate
an id if necessary. If entity
has a complete key and was already marked for deletion in this
writer, the operation will be changed to #put.
If an entity for entity.getKey()
does not exists, entity
is inserted.
Otherwise, #submit() will throw a DatastoreException with DatastoreException#getReason() equal to "ALREADY_EXISTS"
.
Name | Description |
entity | FullEntity<?> |
Type | Description |
Entity |
add(FullEntity<?>[] entities)
public abstract 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 to #put.
If none of entities' keys exist, all entities are inserted. If any of entities' keys already
exists, #submit() will throw a DatastoreException with DatastoreException#getReason() equal to "ALREADY_EXISTS"
. All entities in
entities
whose key did not exist are inserted.
Name | Description |
entities | FullEntity<?>[] |
Type | Description |
List<Entity> |
getDatastore()
public abstract Datastore getDatastore()
Returns the batch associated Datastore.
Type | Description |
Datastore |
submit()
public abstract Batch.Response submit()
Submit the batch to the Datastore.
Type | Description |
Batch.Response |