Class ValueTranslator<P,​D>

All Implemented Interfaces:
Translator<P,​D>

public abstract class ValueTranslator<P,​D>
extends ProjectionSafeTranslator<P,​D>

A bit of code that does the required type checking and casting so that we have nice typed methods. Also handles the RawValue case of projection queries. Note that null checking has already been done.

Author:
Jeff Schnitzer
  • Constructor Details

    • ValueTranslator

      public ValueTranslator(Class<D> datastoreClass)
    • ValueTranslator

      public ValueTranslator(Class<D> datastoreClass, Class<? extends D> projectionClass)
      Sometimes the projection class is more specific than the datastore class
  • Method Details

    • loadSafe2

      protected final P loadSafe2(D value, LoadContext ctx, Path path) throws SkipException
      Description copied from class: ProjectionSafeTranslator
      Decode from a property value as stored in the datastore to a type that will be stored in a pojo.
      Specified by:
      loadSafe2 in class ProjectionSafeTranslator<P,​D>
      Parameters:
      value - will not be null and will not be RawValue
      Returns:
      the format which should be stored in the pojo; a null means store a literal null!
      Throws:
      SkipException - if this field subtree should be skipped
    • saveSafe

      protected final D 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,​D>
      Parameters:
      pojo - will never be null
      Throws:
      SkipException
    • loadValue

      protected abstract P loadValue(D value, LoadContext ctx, Path path) throws SkipException
      Decode from a property value as stored in the datastore to a type that will be stored in a pojo.
      Parameters:
      value - will not be null and will actually be the correct type
      Returns:
      the format which should be stored in the pojo; a null means store a literal null!
      Throws:
      SkipException - if this field subtree should be skipped
    • saveValue

      protected abstract D saveValue(P value, boolean index, SaveContext ctx, Path path) throws SkipException
      Encode from a normal pojo value to a format that the datastore understands. Note that a null return value is a literal instruction to store a null.
      Parameters:
      value - will not be null
      Returns:
      the format which should be stored in the datastore; null means actually store a null!
      Throws:
      SkipException - if this subtree should be skipped