Class ClassTranslatorFactory<P>

  • All Implemented Interfaces:
    TranslatorFactory<P,​com.google.cloud.datastore.FullEntity<?>>

    public class ClassTranslatorFactory<P>
    extends Object
    implements TranslatorFactory<P,​com.google.cloud.datastore.FullEntity<?>>

    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.

    Author:
    Jeff Schnitzer
    • Constructor Detail

      • ClassTranslatorFactory

        public ClassTranslatorFactory()
    • Method Detail

      • create

        public ClassTranslator<P> create​(TypeKey<P> tk,
                                         CreateContext ctx,
                                         Path path)
        Description copied from interface: TranslatorFactory
        Create a translator for a type.
        Specified by:
        create in interface TranslatorFactory<P,​com.google.cloud.datastore.FullEntity<?>>
        Parameters:
        tk - defines the type which is to be translated
        path - is where this type was discovered, important for logging and exceptions
        Returns:
        null if this factory does not know how to deal with that situation.