Class Keys

java.lang.Object
com.googlecode.objectify.impl.Keys

public class Keys extends Object

Gives us a slightly more organized interface for manipulating keys. While this is part of Objectify's public interface, you probably shouldn't use it. It's subject to change without notice. If you want to work with keys, use the Key.create() methods.

Author:
Jeff Schnitzer invalid input: '<'[email protected]>
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static <B extends com.google.cloud.datastore.BaseKey.Builder<B>>
    B
    adjustNamespace(B builder, String namespace)
    Be sensitive to the thread local namespace, if set
    static com.google.cloud.datastore.KeyFactory
    adjustNamespace(com.google.cloud.datastore.KeyFactory keyFactory, String namespace)
    Be sensitive to the thread local namespace, if set
    <T> Key<T>
    anythingToKey(Object keyOrEntity, String namespaceHint)
    Gets the Key given an object that might be a Key, Key, or entity.
    com.google.cloud.datastore.Key
    anythingToRawKey(Object keyOrEntity, String namespaceHint)
    Gets the raw datstore Key given an object that might be a Key, Key, or entity.
    <T> Key<T>
    createKey(String namespace, Key<?> parent, Class<T> kind, long id)
    namespace and parent are mutually exclusive
    <T> Key<T>
    createKey(String namespace, Key<?> parent, Class<T> kind, String name)
    namespace and parent are mutually exclusive
    <T> Key<T>
    createKeyAny(String namespace, Key<?> parent, Class<T> kind, Object id)
    Construct a Keyinvalid input: '<'?> from a Long or String id namespace and parent are mutually exclusive
    <T> List<Key<T>>
    createKeys(String namespace, Key<?> parent, Class<T> kind, Iterable<?> ids)
    Make a list of Keyinvalid input: '<'?>s
    com.google.cloud.datastore.Key
    createRaw(String namespace, com.google.cloud.datastore.Key parent, String kind, long id)
    namespace and parent are mutually exclusive
    com.google.cloud.datastore.Key
    createRaw(String namespace, com.google.cloud.datastore.Key parent, String kind, String name)
    namespace and parent are mutually exclusive
    com.google.cloud.datastore.Key
    createRawAny(String namespace, com.google.cloud.datastore.Key parent, String kind, Object id)
    Construct a Key from a Long or String id
    com.google.cloud.datastore.IncompleteKey
    createRawIncomplete(String namespace, com.google.cloud.datastore.Key parent, String kind)
    namespace and parent are mutually exclusive
    static com.google.cloud.datastore.Key
    fromUrlSafe(String urlSafeKey)
    Understands both the legacy format "ag1zfnZvb2Rvb2R5bmUwcgcLEgFCGAEM" and new format, providing the key either way.
    static <S> com.google.cloud.datastore.Value<S>
    getIdValue(com.google.cloud.datastore.IncompleteKey key)
    Gets the String or Long id from the key as a Value, or null if incomplete
    static com.google.cloud.datastore.Key
    getKey(com.google.cloud.datastore.FullEntity<?> entity)
     
    <T> KeyMetadata<T>
    getMetadata(Key<T> key)
     
    <T> KeyMetadata<T>
     
    <T> KeyMetadata<T>
     
    <T> Key<T>
    keyOf(T pojo, String namespaceHint)
     
    static com.google.cloud.datastore.Key
    raw(Key<?> key)
    Null-safe extraction of the raw key
    com.google.cloud.datastore.Key
    rawKeyOf(Object pojo, String namespaceHint)
     
    boolean
     
    static com.google.cloud.datastore.Key[]
    toArray(Collection<com.google.cloud.datastore.Key> collection)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Keys

      public Keys()
  • Method Details

    • keyOf

      public <T> Key<T> keyOf(T pojo, String namespaceHint)
      Returns:
      the Keyinvalid input: '<'?> for a registered pojo entity.
    • rawKeyOf

      public com.google.cloud.datastore.Key rawKeyOf(Object pojo, String namespaceHint)
      Returns:
      the native datastore key for a registered pojo entity (or FullEntity).
    • getMetadataSafe

      public <T> KeyMetadata<T> getMetadataSafe(Class<T> clazz)
      Returns:
      the metadata for a registered pojo, or throw exception if none
      Throws:
      IllegalStateException - if the pojo class has not been registered
    • getMetadataSafe

      public <T> KeyMetadata<T> getMetadataSafe(T pojo)
      Returns:
      the metadata for a registeerd pojo, or throw exception if none
      Throws:
      IllegalStateException - if the pojo class has not been registered
    • getMetadata

      public <T> KeyMetadata<T> getMetadata(Key<T> key)
      Returns:
      the metadata for a registered pojo, or null if there is none
    • anythingToKey

      public <T> Key<T> anythingToKey(Object keyOrEntity, String namespaceHint)

      Gets the Key given an object that might be a Key, Key, or entity.

      Parameters:
      keyOrEntity - must be a Key, Key, or registered entity.
      Throws:
      NullPointerException - if keyOrEntity is null
      IllegalArgumentException - if keyOrEntity is not a Key, Key, or registered entity
    • anythingToRawKey

      public com.google.cloud.datastore.Key anythingToRawKey(Object keyOrEntity, String namespaceHint)

      Gets the raw datstore Key given an object that might be a Key, Key, or entity.

      Parameters:
      keyOrEntity - must be a Key, Key, or registered entity.
      Throws:
      NullPointerException - if keyOrEntity is null
      IllegalArgumentException - if keyOrEntity is not a Key, Key, or registered entity
    • getKey

      public static com.google.cloud.datastore.Key getKey(com.google.cloud.datastore.FullEntity<?> entity)
      Returns:
      the Key, or throw an exception if entity's key is missing or incomplete
    • requiresAutogeneratedId

      public boolean requiresAutogeneratedId(Object entity)
      Returns:
      true of the entity has a null id which can be autogenerated on save
    • createRaw

      public com.google.cloud.datastore.Key createRaw(String namespace, com.google.cloud.datastore.Key parent, String kind, long id)
      namespace and parent are mutually exclusive
      Parameters:
      parent - can be null for root keys
    • createRaw

      public com.google.cloud.datastore.Key createRaw(String namespace, com.google.cloud.datastore.Key parent, String kind, String name)
      namespace and parent are mutually exclusive
      Parameters:
      parent - can be null for root keys
    • createRawAny

      public com.google.cloud.datastore.Key createRawAny(String namespace, com.google.cloud.datastore.Key parent, String kind, Object id)
      Construct a Key from a Long or String id
      Parameters:
      id - must be either Long or String
    • createRawIncomplete

      public com.google.cloud.datastore.IncompleteKey createRawIncomplete(String namespace, com.google.cloud.datastore.Key parent, String kind)
      namespace and parent are mutually exclusive
      Parameters:
      parent - can be null for root keys
    • createKey

      public <T> Key<T> createKey(String namespace, Key<?> parent, Class<T> kind, long id)
      namespace and parent are mutually exclusive
      Parameters:
      parent - can be null for root keys
    • createKey

      public <T> Key<T> createKey(String namespace, Key<?> parent, Class<T> kind, String name)
      namespace and parent are mutually exclusive
      Parameters:
      parent - can be null for root keys
    • createKeyAny

      public <T> Key<T> createKeyAny(String namespace, Key<?> parent, Class<T> kind, Object id)
      Construct a Keyinvalid input: '<'?> from a Long or String id namespace and parent are mutually exclusive
      Parameters:
      id - must be either Long or String
    • raw

      public static com.google.cloud.datastore.Key raw(Key<?> key)
      Null-safe extraction of the raw key
    • createKeys

      public <T> List<Key<T>> createKeys(String namespace, Key<?> parent, Class<T> kind, Iterable<?> ids)
      Make a list of Keyinvalid input: '<'?>s
      Parameters:
      namespace - must be exclusive with parent; only one can be provided
      parent - must be exclusive with namespace; only one can be provided
      ids - must contain either Long or String
    • toArray

      public static com.google.cloud.datastore.Key[] toArray(Collection<com.google.cloud.datastore.Key> collection)
    • getIdValue

      public static <S> com.google.cloud.datastore.Value<S> getIdValue(com.google.cloud.datastore.IncompleteKey key)
      Gets the String or Long id from the key as a Value, or null if incomplete
    • fromUrlSafe

      public static com.google.cloud.datastore.Key fromUrlSafe(String urlSafeKey)
      Understands both the legacy format "ag1zfnZvb2Rvb2R5bmUwcgcLEgFCGAEM" and new format, providing the key either way.
    • adjustNamespace

      public static com.google.cloud.datastore.KeyFactory adjustNamespace(com.google.cloud.datastore.KeyFactory keyFactory, String namespace)
      Be sensitive to the thread local namespace, if set
    • adjustNamespace

      public static <B extends com.google.cloud.datastore.BaseKey.Builder<B>> B adjustNamespace(B builder, String namespace)
      Be sensitive to the thread local namespace, if set