Package com.googlecode.objectify.impl
Class KeyMetadata<P>
java.lang.Object
com.googlecode.objectify.impl.KeyMetadata<P>
Figures out what to do with key fields on POJO entities.
- Author:
- Jeff Schnitzer <[email protected]>
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncom.google.cloud.datastore.Key
getCompleteKey
(P pojo, String namespaceHint) Gets a key composed of the relevant id and parent fields in the object.Class<?>
com.google.cloud.datastore.IncompleteKey
getIncompleteKey
(P pojo, String namespaceHint) Gets a key composed of the relevant id and parent fields in the object.getKind()
boolean
boolean
boolean
requiresAutogeneratedId
(P entity) Change this slightly to just a null check on the id so that null String will be allowed.<K extends com.google.cloud.datastore.IncompleteKey>
voidSets the key on a container from the POJO.void
setKey
(P pojo, com.google.cloud.datastore.FullEntity<?> container, LoadContext ctx, Path containerPath) Sets the key (from the container) onto the POJO id/parent fields.void
Sets the numeric id fieldboolean
shouldLoadParent
(Set<Class<?>> enabledGroups)
-
Constructor Details
-
KeyMetadata
-
-
Method Details
-
setKey
public void setKey(P pojo, com.google.cloud.datastore.FullEntity<?> container, LoadContext ctx, Path containerPath) Sets the key (from the container) onto the POJO id/parent fields. Also doublechecks to make sure that the key fields aren't present in the container, which means we're in a very bad state. -
setKey
public <K extends com.google.cloud.datastore.IncompleteKey> void setKey(com.google.cloud.datastore.FullEntity.Builder<K> container, P pojo) Sets the key on a container from the POJO. -
getKind
- Returns:
- the datastore kind associated with this metadata
-
getIncompleteKey
Gets a key composed of the relevant id and parent fields in the object.- Parameters:
pojo
- must be of the entityClass type for this metadata.namespaceHint
- is a namespace that will be used if one is not specified in the pojo- Returns:
- either a Key or IncompleteKey depending on whether the id is null or not
-
getCompleteKey
Gets a key composed of the relevant id and parent fields in the object.- Parameters:
pojo
- must be of the entityClass type for this metadata.- Throws:
IllegalArgumentException
- if pojo has an incomplete key
-
getParentFieldName
- Returns:
- the name of the parent field, or null if there wasn't one
-
getIdFieldName
- Returns:
- the name of the id field
-
getIdFieldType
- Returns:
- the java type of the id field; it will be either Long.class, Long.TYPE, or String.class
-
hasParentField
public boolean hasParentField()- Returns:
- true if the entity has a parent field
-
shouldLoadParent
- Returns:
- true if the parent should be loaded given the enabled fetch groups
-
isIdGeneratable
public boolean isIdGeneratable()- Returns:
- true if the id field is uppercase-Long, which can be genearted.
-
setLongId
Sets the numeric id field -
requiresAutogeneratedId
Change this slightly to just a null check on the id so that null String will be allowed. The advantage of this is that we'll get a consistent error message when you actually try to save a null String id, instead of the weird things that will happen when you try to generate a Key for the object.- Returns:
- true if this entity object has a null id
-