Class DatastoreServiceObjectToKeyFactory
java.lang.Object
com.google.cloud.spring.data.datastore.core.convert.DatastoreServiceObjectToKeyFactory
- All Implemented Interfaces:
ObjectToKeyFactory
Implementation of
ObjectToKeyFactory
where the key factories are provided by the
Datastore Service.- Since:
- 1.1
-
Constructor Summary
ConstructorDescriptionDatastoreServiceObjectToKeyFactory
(Supplier<com.google.cloud.datastore.Datastore> datastore) -
Method Summary
Modifier and TypeMethodDescriptioncom.google.cloud.datastore.Key
allocateKeyForObject
(Object entity, DatastorePersistentEntity datastorePersistentEntity, com.google.cloud.datastore.Key... ancestors) Allocates a new IDKey
for the given entity object and sets the allocated ID value in the object.com.google.cloud.datastore.IncompleteKey
getIncompleteKey
(String kindName) Get anIncompleteKey
(a Key without ID part) from a kind name.com.google.cloud.datastore.Key
getKeyFromId
(Object id, String kindName) Get aKey
from a provided ID value and a kind name.com.google.cloud.datastore.Key
getKeyFromObject
(Object entity, DatastorePersistentEntity datastorePersistentEntity) Get aKey
from an entity.
-
Constructor Details
-
DatastoreServiceObjectToKeyFactory
-
-
Method Details
-
getIncompleteKey
Description copied from interface:ObjectToKeyFactory
Get anIncompleteKey
(a Key without ID part) from a kind name.- Specified by:
getIncompleteKey
in interfaceObjectToKeyFactory
- Parameters:
kindName
- the kind name- Returns:
- an IncompleteKey.
-
getKeyFromId
Description copied from interface:ObjectToKeyFactory
Get aKey
from a provided ID value and a kind name. If the given ID value is already a Key then this is the Key returned. Otherwise a Key is created with the given kind name and the given ID value as the only and root value.- Specified by:
getKeyFromId
in interfaceObjectToKeyFactory
- Parameters:
id
- the ID value that can be the root single ID value or a fully formed Key.kindName
- the kind name used if the ID value provided is not a fully formed Key.- Returns:
- a Key.
-
getKeyFromObject
public com.google.cloud.datastore.Key getKeyFromObject(Object entity, DatastorePersistentEntity datastorePersistentEntity) Description copied from interface:ObjectToKeyFactory
Get aKey
from an entity.- Specified by:
getKeyFromObject
in interfaceObjectToKeyFactory
- Parameters:
entity
- the entity that whose ID value we want to form into a Key.datastorePersistentEntity
- the metadata of the given entity.- Returns:
- a Key.
-
allocateKeyForObject
public com.google.cloud.datastore.Key allocateKeyForObject(Object entity, DatastorePersistentEntity datastorePersistentEntity, com.google.cloud.datastore.Key... ancestors) Description copied from interface:ObjectToKeyFactory
Allocates a new IDKey
for the given entity object and sets the allocated ID value in the object. Only Key ids are allowed in entities if ancestors are present.- Specified by:
allocateKeyForObject
in interfaceObjectToKeyFactory
- Parameters:
entity
- the object for which to get and set the ID value.datastorePersistentEntity
- the persistent entity metadata for the entity object.ancestors
- ancestors that should be added to the entity- Returns:
- the newly allocated Key.
-