Package com.googlecode.objectify.impl
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
-
-
Constructor Summary
Constructors Constructor Description Keys()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <B extends com.google.cloud.datastore.BaseKey.Builder<B>>
BadjustNamespace(B builder, String namespace)Be sensitive to the thread local namespace, if setstatic com.google.cloud.datastore.KeyFactoryadjustNamespace(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 Keygiven an object that might be a Key, Key , or entity. com.google.cloud.datastore.KeyanythingToRawKey(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 Key> 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 Key>scom.google.cloud.datastore.KeycreateRaw(String namespace, com.google.cloud.datastore.Key parent, String kind, long id)namespace and parent are mutually exclusivecom.google.cloud.datastore.KeycreateRaw(String namespace, com.google.cloud.datastore.Key parent, String kind, String name)namespace and parent are mutually exclusivecom.google.cloud.datastore.KeycreateRawAny(String namespace, com.google.cloud.datastore.Key parent, String kind, Object id)Construct a Key from a Long or String idcom.google.cloud.datastore.IncompleteKeycreateRawIncomplete(String namespace, com.google.cloud.datastore.Key parent, String kind)namespace and parent are mutually exclusivestatic com.google.cloud.datastore.KeyfromUrlSafe(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 incompletestatic com.google.cloud.datastore.KeygetKey(com.google.cloud.datastore.FullEntity<?> entity)<T> KeyMetadata<T>getMetadata(Key<T> key)<T> KeyMetadata<T>getMetadataSafe(Class<T> clazz)<T> KeyMetadata<T>getMetadataSafe(T pojo)<T> Key<T>keyOf(T pojo, String namespaceHint)static com.google.cloud.datastore.Keyraw(Key<?> key)Null-safe extraction of the raw keycom.google.cloud.datastore.KeyrawKeyOf(Object pojo, String namespaceHint)booleanrequiresAutogeneratedId(Object entity)static com.google.cloud.datastore.Key[]toArray(Collection<com.google.cloud.datastore.Key> collection)
-
-
-
Method Detail
-
keyOf
public <T> Key<T> keyOf(T pojo, String namespaceHint)
- Returns:
- the Key> 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 nullIllegalArgumentException- 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 nullIllegalArgumentException- 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 Key> 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 Key>s- Parameters:
namespace- must be exclusive with parent; only one can be providedparent- must be exclusive with namespace; only one can be providedids- 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
-
-