public abstract class NullSafeTranslator<P,D> extends Object implements Translator<P,D>
Handles null checking so we don't have to do it everywhere.
Constructor and Description |
---|
NullSafeTranslator() |
Modifier and Type | Method and Description |
---|---|
P |
load(D node,
LoadContext ctx,
Path path)
Loads the content of the specified datastore node, returning the pojo equivalent.
|
protected abstract P |
loadSafe(D node,
LoadContext ctx,
Path path)
Implement this, returning a proper translated 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 D |
saveSafe(P pojo,
boolean index,
SaveContext ctx,
Path path)
Implement this, returning a proper translated value
|
public final P load(D node, LoadContext ctx, Path path) throws SkipException
Translator
Loads the content of the specified datastore node, returning the pojo equivalent.
There is one special return value: If a Result> 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.
load
in interface Translator<P,D>
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 translatorSkipException
- if the return value should be abandoned.LoadEngine
public final D save(P pojo, boolean index, SaveContext ctx, Path path) throws SkipException
Translator
save
in interface Translator<P,D>
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).SkipException
- if the return value should be abandonedprotected abstract P loadSafe(D node, LoadContext ctx, Path path) throws SkipException
node
- will never be nullSkipException
protected abstract D saveSafe(P pojo, boolean index, SaveContext ctx, Path path) throws SkipException
pojo
- will never be nullSkipException
Copyright © 2016. All rights reserved.