Class DatastoreServiceObjectToKeyFactory

java.lang.Object
com.google.cloud.spring.data.datastore.core.convert.DatastoreServiceObjectToKeyFactory
All Implemented Interfaces:
ObjectToKeyFactory

public class DatastoreServiceObjectToKeyFactory extends Object implements ObjectToKeyFactory
Implementation of ObjectToKeyFactory where the key factories are provided by the Datastore Service.
Since:
1.1
  • Constructor Details

    • DatastoreServiceObjectToKeyFactory

      public DatastoreServiceObjectToKeyFactory(Supplier<com.google.cloud.datastore.Datastore> datastore)
  • Method Details

    • getIncompleteKey

      public com.google.cloud.datastore.IncompleteKey getIncompleteKey(String kindName)
      Description copied from interface: ObjectToKeyFactory
      Get an IncompleteKey (a Key without ID part) from a kind name.
      Specified by:
      getIncompleteKey in interface ObjectToKeyFactory
      Parameters:
      kindName - the kind name
      Returns:
      an IncompleteKey.
    • getKeyFromId

      public com.google.cloud.datastore.Key getKeyFromId(Object id, String kindName)
      Description copied from interface: ObjectToKeyFactory
      Get a Key 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 interface ObjectToKeyFactory
      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 a Key from an entity.
      Specified by:
      getKeyFromObject in interface ObjectToKeyFactory
      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 ID Key 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 interface ObjectToKeyFactory
      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.