Class ValueTranslator<P,​D>

  • All Implemented Interfaces:
    Translator<P,​D>

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

    Translator that should be extended for typical atomic values. Does a little bit of expected type checking and handles indexing for us.

    Author:
    Jeff Schnitzer
    • Constructor Detail

      • ValueTranslator

        public ValueTranslator​(com.google.cloud.datastore.ValueType... expectedValueTypes)
    • Method Detail

      • loadValue

        protected abstract P loadValue​(com.google.cloud.datastore.Value<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 com.google.cloud.datastore.Value<D> saveValue​(P value,
                                                                         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