Interface ObjectToKeyFactory
- All Known Implementing Classes:
DatastoreServiceObjectToKeyFactory
public interface ObjectToKeyFactory
An interface for creating Datastore Keys from objects and ID values.
- Since:
- 1.1
-
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.
-
Method Details
-
getIncompleteKey
Get anIncompleteKey
(a Key without ID part) from a kind name.- Parameters:
kindName
- the kind name- Returns:
- an IncompleteKey.
-
getKeyFromId
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.- 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
com.google.cloud.datastore.Key getKeyFromObject(Object entity, DatastorePersistentEntity datastorePersistentEntity) Get aKey
from an entity.- 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
com.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. Only Key ids are allowed in entities if ancestors are present.- 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.
-