Package com.google.cloud.datastore
Class BaseDatastoreBatchWriter
- java.lang.Object
-
- com.google.cloud.datastore.BaseDatastoreBatchWriter
-
- All Implemented Interfaces:
DatastoreBatchWriter,DatastoreWriter
public abstract class BaseDatastoreBatchWriter extends Object implements DatastoreBatchWriter
Base class for DatastoreBatchWriter.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete 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.voidaddWithDeferredIdAllocation(FullEntity<?>... entities)Datastore add operation.protected voiddeactivate()voiddelete(Key... keys)A datastore delete operation.protected abstract DatastoregetDatastore()protected StringgetName()booleanisActive()Returnstrueif still active (write operations were not sent to the Datastore).protected DatastoreExceptionnewInvalidRequest(String msg, Object... params)Entityput(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.voidputWithDeferredIdAllocation(FullEntity<?>... entities)Datastore put operation.protected Map<Key,FullEntity<Key>>toAdd()protected List<FullEntity<IncompleteKey>>toAddAutoId()protected Set<Key>toDelete()protected List<Mutation>toMutationPbList()protected Map<Key,FullEntity<Key>>toPut()protected Map<Key,FullEntity<Key>>toUpdate()voidupdate(Entity... entities)A Datastore update operation.protected voidvalidateActive()
-
-
-
Method Detail
-
addWithDeferredIdAllocation
public final void addWithDeferredIdAllocation(FullEntity<?>... entities)
Description copied from interface:DatastoreBatchWriterDatastore add operation. This method will also allocate id for any entity with an incomplete key. As opposed toDatastoreBatchWriter.add(FullEntity)andDatastoreBatchWriter.add(FullEntity...), this method will defer any necessary id allocation to submit time.- Specified by:
addWithDeferredIdAllocationin interfaceDatastoreBatchWriter
-
add
public final Entity add(FullEntity<?> entity)
Description copied from interface:DatastoreBatchWriterDatastore 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<?>).- 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
public final List<Entity> add(FullEntity<?>... entities)
Description copied from interface:DatastoreBatchWriterDatastore 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<?>).- 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)
-
update
@SafeVarargs public final void update(Entity... entities)
Description copied from interface:DatastoreBatchWriterA Datastore update operation. The operation will fail if an entity with the same key does not already exist. This operation will be converted toDatastoreBatchWriter.put(com.google.cloud.datastore.FullEntity<?>)operation for entities that were already added or put in this writer.- Specified by:
updatein interfaceDatastoreBatchWriter- Specified by:
updatein interfaceDatastoreWriter
-
put
public final Entity put(FullEntity<?> entity)
Description copied from interface:DatastoreBatchWriterA 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:
putin interfaceDatastoreBatchWriter- Specified by:
putin interfaceDatastoreWriter- Parameters:
entity- the entity to put- Returns:
- an
Entitywith the same properties and a key that is either newly allocated or the same one if key is already complete
-
putWithDeferredIdAllocation
public final void putWithDeferredIdAllocation(FullEntity<?>... entities)
Description copied from interface:DatastoreBatchWriterDatastore put operation. This method will also allocate id for any entity with an incomplete key. As opposed toDatastoreBatchWriter.put(FullEntity)andDatastoreBatchWriter.put(FullEntity...), this method will defer any necessary id allocation to submit time.- Specified by:
putWithDeferredIdAllocationin interfaceDatastoreBatchWriter
-
put
public final List<Entity> put(FullEntity<?>... entities)
Description copied from interface:DatastoreBatchWriterA 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:
putin interfaceDatastoreBatchWriter- Specified by:
putin 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.
-
delete
public final void delete(Key... keys)
Description copied from interface:DatastoreBatchWriterA 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:
deletein interfaceDatastoreBatchWriter- Specified by:
deletein interfaceDatastoreWriter
-
isActive
public boolean isActive()
Description copied from interface:DatastoreBatchWriterReturnstrueif still active (write operations were not sent to the Datastore).- Specified by:
isActivein interfaceDatastoreBatchWriter
-
getName
protected String getName()
-
toAdd
protected Map<Key,FullEntity<Key>> toAdd()
-
toAddAutoId
protected List<FullEntity<IncompleteKey>> toAddAutoId()
-
toUpdate
protected Map<Key,FullEntity<Key>> toUpdate()
-
toPut
protected Map<Key,FullEntity<Key>> toPut()
-
deactivate
protected void deactivate()
-
validateActive
protected void validateActive()
-
newInvalidRequest
protected DatastoreException newInvalidRequest(String msg, Object... params)
-
getDatastore
protected abstract Datastore getDatastore()
-
-