Class NullSafeTranslator<P,D>
java.lang.Object
com.googlecode.objectify.impl.translate.NullSafeTranslator<P,D>
- All Implemented Interfaces:
Translator<P,
D>
- Direct Known Subclasses:
ClassTranslator
,ValueTranslator
Handles null checking so we don't have to do it everywhere. Handles NullValue where appropriate.
- Author:
- Jeff Schnitzer invalid input: '<'[email protected]>
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionfinal P
load
(com.google.cloud.datastore.Value<D> node, LoadContext ctx, Path path) Loads the content of the specified datastore node, returning the pojo equivalent.protected abstract P
loadSafe
(com.google.cloud.datastore.Value<D> node, LoadContext ctx, Path path) Implement this, returning a proper translated valuefinal com.google.cloud.datastore.Value<D>
save
(P pojo, boolean index, SaveContext ctx, Path path) Translates a pojo (or some component thereof) into a format suitable for storage in the datastore.protected abstract com.google.cloud.datastore.Value<D>
saveSafe
(P pojo, boolean index, SaveContext ctx, Path path) Implement this, returning a proper translated value
-
Constructor Details
-
NullSafeTranslator
public NullSafeTranslator()
-
-
Method Details
-
load
public final P load(com.google.cloud.datastore.Value<D> node, LoadContext ctx, Path path) throws SkipException Description copied from interface:Translator
Loads the content of the specified datastore node, returning the pojo equivalent.
There is one special return value: If a Resultinvalid input: '<'?> is returned, the content of the Result will be used instead, but delayed until ctx.done() is called. This happens at the end of a "round" of load operations and is the magic trick that makes populating entity references work efficiently.
- Specified by:
load
in interfaceTranslator<P,
D> - Parameters:
node
- is the part of the native datastore entity tree we are transforming.ctx
- holds state information during an entity load.path
- is the current path to this translator- Returns:
- an assembled pojo corresponding to the node subtree; if null is returned, that is the real value!
- Throws:
SkipException
- if the return value should be abandoned.- See Also:
-
save
public final com.google.cloud.datastore.Value<D> save(P pojo, boolean index, SaveContext ctx, Path path) throws SkipException Description copied from interface:Translator
Translates a pojo (or some component thereof) into a format suitable for storage in the datastore.- Specified by:
save
in interfaceTranslator<P,
D> - Parameters:
pojo
- is an object from the pojo entity graph; possibly the whole graph or possibly just a leaf field.index
- is whether the instruction so far is to index or not index property valuespath
- is the path that we have taken to get here, which could be long due to re-entrant translators (ie, an embedded pojo that also has a reference to the same class).- Returns:
- something suitable for storage in the datastore.
- Throws:
SkipException
- if the return value should be abandoned
-
loadSafe
protected abstract P loadSafe(com.google.cloud.datastore.Value<D> node, LoadContext ctx, Path path) throws SkipException Implement this, returning a proper translated value- Parameters:
node
- will never be null or NullValue- Throws:
SkipException
-
saveSafe
protected abstract com.google.cloud.datastore.Value<D> saveSafe(P pojo, boolean index, SaveContext ctx, Path path) throws SkipException Implement this, returning a proper translated value- Parameters:
pojo
- will never be null- Throws:
SkipException
-