public class ClassTranslatorFactory<P> extends Object implements TranslatorFactory<P,com.google.appengine.api.datastore.PropertyContainer>
Translator which maps classes, both normal embedded classes and Entity classes.
Entity classes are just like any other class except they have @Id and @Parent fields and a kind. When translating to native datastore structure (Entity for top level, EmbeddedEntity for an embedded field) then these attributes are stored in the Key structure, not as properties.
An entity class is any class which has the @Entity annotation anywhere in its superclass hierarchy.
Note that entities can be embedded in other objects; they are still entities. The difference between an embedded class and an embedded entity is that the entity has a Key.
One noteworthy issue is that we must ensure there is only one classtranslator for any given class. Normally the discovery process creates a separate translator for each set of annotations, however, this screws up the subclass registration process, which needs to register at each parent class translator. Since field annotations are actually irrelevant to the internal function of a ClassTranslator, we can just cache class translators here in the factory. There will never be more than one translator for a given class, even though many TypeKeys may point at it.
Constructor and Description |
---|
ClassTranslatorFactory() |
Modifier and Type | Method and Description |
---|---|
ClassTranslator<P> |
create(TypeKey<P> tk,
CreateContext ctx,
Path path)
Create a translator for a type.
|
static <P> ClassTranslator<P> |
createEmbeddedClassTranslator(Class<P> clazz,
CreateContext ctx,
Path path) |
static <P> ClassTranslator<P> |
createEntityClassTranslator(Class<P> clazz,
CreateContext ctx,
Path path) |
public ClassTranslator<P> create(TypeKey<P> tk, CreateContext ctx, Path path)
TranslatorFactory
create
in interface TranslatorFactory<P,com.google.appengine.api.datastore.PropertyContainer>
tk
- defines the type which is to be translatedpath
- is where this type was discovered, important for logging and exceptionspublic static <P> ClassTranslator<P> createEntityClassTranslator(Class<P> clazz, CreateContext ctx, Path path)
public static <P> ClassTranslator<P> createEmbeddedClassTranslator(Class<P> clazz, CreateContext ctx, Path path)
Copyright © 2016. All rights reserved.