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

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

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

The interface by which POJOs and datastore Entity objects are translated back and forth. Subclasses implement specific mapping, including polymorphic mapping.

Author:
Jeff Schnitzer

Field Summary
static java.lang.String DISCRIMINATOR_INDEX_PROPERTY
          Name of the list property which will hold all indexed discriminator values
static java.lang.String DISCRIMINATOR_PROPERTY
          Name of the out-of-band discriminator property in a raw Entity
 
Constructor Summary
PolymorphicEntityMetadata(java.lang.Class<T> clazz, ConcreteEntityMetadata<T> baseMetadata)
          Initializes this metadata structure with the specified class.
 
Method Summary
<S extends T>
void
addSubclass(java.lang.Class<S> clazz, ConcreteEntityMetadata<S> subclassMeta)
          Registers a @Subclass in a polymorphic hierarchy.
 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

DISCRIMINATOR_PROPERTY

public static final java.lang.String DISCRIMINATOR_PROPERTY
Name of the out-of-band discriminator property in a raw Entity

See Also:
Constant Field Values

DISCRIMINATOR_INDEX_PROPERTY

public static final java.lang.String DISCRIMINATOR_INDEX_PROPERTY
Name of the list property which will hold all indexed discriminator values

See Also:
Constant Field Values
Constructor Detail

PolymorphicEntityMetadata

public PolymorphicEntityMetadata(java.lang.Class<T> clazz,
                                 ConcreteEntityMetadata<T> baseMetadata)
Initializes this metadata structure with the specified class.

Parameters:
baseMetadata - is the metadata for the @Entity class that defines the kind of the hierarchy
Method Detail

addSubclass

public <S extends T> void addSubclass(java.lang.Class<S> clazz,
                                      ConcreteEntityMetadata<S> subclassMeta)
Registers a @Subclass in a polymorphic hierarchy.

Parameters:
clazz - must have the @Subclass annotation

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