Class ClassTranslator<P>

java.lang.Object
com.googlecode.objectify.impl.translate.NullSafeTranslator<P,​com.google.appengine.api.datastore.PropertyContainer>
com.googlecode.objectify.impl.translate.ClassTranslator<P>
All Implemented Interfaces:
Translator<P,​com.google.appengine.api.datastore.PropertyContainer>

public class ClassTranslator<P>
extends NullSafeTranslator<P,​com.google.appengine.api.datastore.PropertyContainer>

Some common code for Translators which know how to convert a POJO type into a PropertiesContainer. This might be polymorphic; we get polymorphism when @Subclasses are registered on this translator.

Author:
Jeff Schnitzer
  • Field Details

    • DISCRIMINATOR_PROPERTY

      public static final String DISCRIMINATOR_PROPERTY
      Name of the out-of-band discriminator property in a PropertyContainer
      See Also:
      Constant Field Values
    • DISCRIMINATOR_INDEX_PROPERTY

      public static final String DISCRIMINATOR_INDEX_PROPERTY
      Name of the list property which will hold all indexed discriminator values
      See Also:
      Constant Field Values
  • Constructor Details

  • Method Details

    • getDeclaredClass

      public Class<P> getDeclaredClass()
      Returns:
      the class we translate
    • getDiscriminator

      public String getDiscriminator()
      Returns:
      the discriminator for this class, or null if this is not a @Subclass
    • getPopulator

      public Populator<P> getPopulator()
      Get the populator associated with this class.
    • getCreator

      public Creator<P> getCreator()
      Get the creator associated with this class.
    • loadSafe

      public P loadSafe(com.google.appengine.api.datastore.PropertyContainer container, LoadContext ctx, Path path) throws SkipException
      Description copied from class: NullSafeTranslator
      Implement this, returning a proper translated value
      Specified by:
      loadSafe in class NullSafeTranslator<P,​com.google.appengine.api.datastore.PropertyContainer>
      Parameters:
      container - will never be null
      Throws:
      SkipException
    • saveSafe

      public com.google.appengine.api.datastore.PropertyContainer saveSafe(P pojo, boolean index, SaveContext ctx, Path path) throws SkipException
      Description copied from class: NullSafeTranslator
      Implement this, returning a proper translated value
      Specified by:
      saveSafe in class NullSafeTranslator<P,​com.google.appengine.api.datastore.PropertyContainer>
      Parameters:
      pojo - will never be null
      Throws:
      SkipException
    • registerSubclass

      public void registerSubclass(ClassTranslator<? extends P> translator)
      Register a subclass translator with this class translator. That way if we get called upon to translate an instance of the subclass, we will forward to the correct translator.