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 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.protected void
deactivate()
void
delete(Key... keys)
A datastore delete operation.protected abstract Datastore
getDatastore()
protected String
getName()
boolean
isActive()
Returnstrue
if still active (write operations were not sent to the Datastore).protected DatastoreException
newInvalidRequest(String msg, Object... params)
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.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()
void
update(Entity... entities)
A Datastore update operation.protected void
validateActive()
-
-
-
Method Detail
-
addWithDeferredIdAllocation
public final void addWithDeferredIdAllocation(FullEntity<?>... entities)
Description copied from interface:DatastoreBatchWriter
Datastore 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:
addWithDeferredIdAllocation
in interfaceDatastoreBatchWriter
-
add
public final Entity add(FullEntity<?> entity)
Description copied from interface:DatastoreBatchWriter
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 toDatastoreBatchWriter.put(com.google.cloud.datastore.FullEntity<?>)
.- Specified by:
add
in interfaceDatastoreBatchWriter
- 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
-
add
public final List<Entity> add(FullEntity<?>... entities)
Description copied from interface:DatastoreBatchWriter
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<?>)
.- Specified by:
add
in interfaceDatastoreBatchWriter
- 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 - See Also:
DatastoreWriter.add(FullEntity)
-
update
@SafeVarargs public final void update(Entity... entities)
Description copied from interface:DatastoreBatchWriter
A 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:
update
in interfaceDatastoreBatchWriter
- Specified by:
update
in interfaceDatastoreWriter
-
put
public final Entity put(FullEntity<?> entity)
Description copied from interface:DatastoreBatchWriter
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 interfaceDatastoreBatchWriter
- 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
-
putWithDeferredIdAllocation
public final void putWithDeferredIdAllocation(FullEntity<?>... entities)
Description copied from interface:DatastoreBatchWriter
Datastore 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:
putWithDeferredIdAllocation
in interfaceDatastoreBatchWriter
-
put
public final List<Entity> put(FullEntity<?>... entities)
Description copied from interface:DatastoreBatchWriter
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 interfaceDatastoreBatchWriter
- 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.
-
delete
public final void delete(Key... keys)
Description copied from interface:DatastoreBatchWriter
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 interfaceDatastoreBatchWriter
- Specified by:
delete
in interfaceDatastoreWriter
-
isActive
public boolean isActive()
Description copied from interface:DatastoreBatchWriter
Returnstrue
if still active (write operations were not sent to the Datastore).- Specified by:
isActive
in 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()
-
-