com.googlecode.objectify.impl
Class ConcreteEntityMetadata<T>

java.lang.Object
  extended by com.googlecode.objectify.impl.ConcreteEntityMetadata<T>
All Implemented Interfaces:
EntityMetadata<T>

public class ConcreteEntityMetadata<T>
extends java.lang.Object
implements EntityMetadata<T>

Knows how to map between datastore Entity objects and your typed POJO objects. An instance of this class knows how to perform mapping of a specific subclass.

Author:
Jeff Schnitzer

Field Summary
protected  Cached cached
          The cached annotation, or null if entity should not be cached
protected  java.lang.Class<T> entityClass
           
protected  java.lang.reflect.Constructor<T> entityClassConstructor
           
protected  java.lang.reflect.Field idField
          We treat the @Id key field specially - it will be either Long id or String name
protected  java.lang.String kind
          The kind that is associated with the class, ala ObjectifyFactory.getKind(Class)
protected  java.lang.reflect.Field nameField
           
protected  java.lang.reflect.Field parentField
          If the entity has a @Parent field, treat it specially
protected  java.util.List<java.lang.reflect.Method> postLoadMethods
          Any methods in the hierarchy annotated with @PostLoad, could be null
protected  java.util.List<java.lang.reflect.Method> prePersistMethods
          Any methods in the hierarchy annotated with @PrePersist, could be null
protected  Transmog<T> transmog
          For translating between pojos and entities
 
Constructor Summary
ConcreteEntityMetadata(Conversions conversions, java.lang.Class<T> clazz)
          Inspects and stores the metadata for a particular entity class.
 
Method Summary
 java.lang.Integer getCacheExpirySeconds()
          Get the expiry associated with this kind, defined by the @Cached annotation.
 java.lang.Class<T> getEntityClass()
          Gets the class associated with this entity.
 java.lang.String getKind()
           
 com.google.appengine.api.datastore.Key getRawKey(java.lang.Object obj)
          Gets a key composed of the relevant id and parent fields in the object.
 boolean hasParentField()
           
 boolean isIdField(java.lang.String propertyName)
           
 boolean isNameField(java.lang.String propertyName)
           
 void setKey(T obj, com.google.appengine.api.datastore.Key key)
          Sets the relevant id and parent fields of the object to the values stored in the key.
 com.google.appengine.api.datastore.Entity toEntity(T pojo, Objectify ofy)
          Converts an object to a datastore Entity with the appropriate Key type.
 T toObject(com.google.appengine.api.datastore.Entity ent, Objectify ofy)
          Converts an entity to an object of the appropriate type for this metadata structure.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

entityClass

protected java.lang.Class<T> entityClass

entityClassConstructor

protected java.lang.reflect.Constructor<T> entityClassConstructor

kind

protected java.lang.String kind
The kind that is associated with the class, ala ObjectifyFactory.getKind(Class)


idField

protected java.lang.reflect.Field idField
We treat the @Id key field specially - it will be either Long id or String name


nameField

protected java.lang.reflect.Field nameField

parentField

protected java.lang.reflect.Field parentField
If the entity has a @Parent field, treat it specially


prePersistMethods

protected java.util.List<java.lang.reflect.Method> prePersistMethods
Any methods in the hierarchy annotated with @PrePersist, could be null


postLoadMethods

protected java.util.List<java.lang.reflect.Method> postLoadMethods
Any methods in the hierarchy annotated with @PostLoad, could be null


transmog

protected Transmog<T> transmog
For translating between pojos and entities


cached

protected Cached cached
The cached annotation, or null if entity should not be cached

Constructor Detail

ConcreteEntityMetadata

public ConcreteEntityMetadata(Conversions conversions,
                              java.lang.Class<T> clazz)
Inspects and stores the metadata for a particular entity class.

Parameters:
clazz - must be a properly-annotated Objectify entity class.
Method Detail

getKind

public java.lang.String getKind()
Specified by:
getKind in interface EntityMetadata<T>
Returns:
the datastore kind associated with this metadata

getCacheExpirySeconds

public java.lang.Integer getCacheExpirySeconds()
Description copied from interface: EntityMetadata
Get the expiry associated with this kind, defined by the @Cached annotation. For polymorphic types, this is always the instruction on the root @Entity - you cannot provide per-type caching.

Specified by:
getCacheExpirySeconds in interface EntityMetadata<T>
Returns:
null means DO NOT CACHE, 0 means "no limit", otherwise # of seconds

toObject

public T toObject(com.google.appengine.api.datastore.Entity ent,
                  Objectify ofy)
Description copied from interface: EntityMetadata
Converts an entity to an object of the appropriate type for this metadata structure. Does not check that the entity is appropriate; that should be done when choosing which EntityMetadata to call.

Specified by:
toObject in interface EntityMetadata<T>

toEntity

public com.google.appengine.api.datastore.Entity toEntity(T pojo,
                                                          Objectify ofy)
Description copied from interface: EntityMetadata
Converts an object to a datastore Entity with the appropriate Key type.

Specified by:
toEntity in interface EntityMetadata<T>

setKey

public void setKey(T obj,
                   com.google.appengine.api.datastore.Key key)
Description copied from interface: EntityMetadata
Sets the relevant id and parent fields of the object to the values stored in the key.

Specified by:
setKey in interface EntityMetadata<T>
Parameters:
obj - must be of the entityClass type for this metadata.

getRawKey

public com.google.appengine.api.datastore.Key getRawKey(java.lang.Object obj)
Description copied from interface: EntityMetadata
Gets a key composed of the relevant id and parent fields in the object.

Specified by:
getRawKey in interface EntityMetadata<T>
Parameters:
obj - must be of the entityClass type for this metadata.

isIdField

public boolean isIdField(java.lang.String propertyName)
Specified by:
isIdField in interface EntityMetadata<T>
Returns:
true if the property name corresponds to a Long/long @Id field. If the entity has a String name @Id, this will return false.

isNameField

public boolean isNameField(java.lang.String propertyName)
Specified by:
isNameField in interface EntityMetadata<T>
Returns:
true if the property name corresponds to a String @Id field. If the entity has a Long/long @Id, this will return false.

hasParentField

public boolean hasParentField()
Specified by:
hasParentField in interface EntityMetadata<T>
Returns:
true if the entity has a parent field

getEntityClass

public java.lang.Class<T> getEntityClass()
Description copied from interface: EntityMetadata
Gets the class associated with this entity. For concrete metadata it will be the actual class; for polymorphic metadata this will be the base class.

Specified by:
getEntityClass in interface EntityMetadata<T>


Copyright © 2011 Jeff Schnitzer and a gang of pirates. All Rights Reserved. Build version: 3.1