public class Transmog<T> extends Object
Transmogrifies POJO entities into datastore Entity objects and vice-versa.
TODO: long explanation of how this works.
Constructor and Description |
---|
Transmog(ObjectifyFactory fact,
Class<T> clazz)
Creats a transmog for the specified class, introspecting it and discovering
how to load/save its properties.
|
Modifier and Type | Method and Description |
---|---|
KeyMetadata<T> |
getKeyMetadata() |
Node |
load(com.google.appengine.api.datastore.Entity fromEntity)
Turn the Entity into the hierarchical set of Nodes that the translation system understands.
|
T |
load(com.google.appengine.api.datastore.Entity fromEntity,
LoadContext ctx)
Create a pojo from the Entity.
|
T |
load(Node root,
LoadContext ctx)
Public just for testing
|
com.google.appengine.api.datastore.Entity |
save(Node root)
Turn a hierarchical series of Nodes into the standard Entity storage format.
|
com.google.appengine.api.datastore.Entity |
save(T fromPojo,
SaveContext ctx)
Creates an Entity that has been set up with the content of the pojo, including key fields.
|
Node |
saveToNode(T fromPojo,
SaveContext ctx)
Public just for testing
|
public Transmog(ObjectifyFactory fact, Class<T> clazz)
public KeyMetadata<T> getKeyMetadata()
public T load(com.google.appengine.api.datastore.Entity fromEntity, LoadContext ctx) throws LoadException
fromEntity
- is a raw datastore entityLoadException
public T load(Node root, LoadContext ctx) throws LoadException
LoadException
public com.google.appengine.api.datastore.Entity save(T fromPojo, SaveContext ctx)
fromPojo
- is your typed entitypublic Node saveToNode(T fromPojo, SaveContext ctx)
public Node load(com.google.appengine.api.datastore.Entity fromEntity)
Turn the Entity into the hierarchical set of Nodes that the translation system understands. This is done in two steps. The first converts to a literal structure of the Entity - this is normally the same as the POJO structure, but @Embed collections are "collectionized" such that the leaf property values are the collections. The second step de-collectionizes the entity nodes, repositioning the collections from the leaf levels up to the place in the hierarchy where the embedded classes are.
Also adds id/parent fields to the root Node.
Public only for testing purposes.
P.S. an exercise for the reader: Try to do this in one pass! Watch out for the ^null collection.
public com.google.appengine.api.datastore.Entity save(Node root)
Turn a hierarchical series of Nodes into the standard Entity storage format. Unlike the load process, this happens in one step, going straight to the "collectionized" format that @Embed collections are stored in.
Public only so we can test.
Copyright © 2013. All Rights Reserved.