com.googlecode.objectify.impl
Class Transmog<T>

java.lang.Object
  extended by com.googlecode.objectify.impl.Transmog<T>

public class Transmog<T>
extends java.lang.Object

Class which knows how to load data from Entity to POJO and save data from POJO to Entity.

Note that this class completely ignores @Id and @Parent fields.

To understand this code, you must first understand that a "leaf" value is anything that can be put into the datastore in a single property. Simple types like String, and Enum, and Key are leaf nodes, but so are Collections and arrays of these basic types. @Embedded values are nonleaf - they branch the persistance graph, producing multiple properties in a datastore Entity.

Also realize that there are two separate dimensions to understand. Misunderstanding the two related graphs will make this code very confusing:

The core structures that operate at runtime are Setters (for loading datastore Entities into typed pojos) and Savers (for saving the fields of typed pojos into datastore Entities). They are NOT parallel hierarchies, and they work very differently:

Author:
Jeff Schnitzer

Constructor Summary
Transmog(Conversions conversions, java.lang.Class<T> clazz)
          Creats a transmog for the specified class, introspecting it and discovering how to load/save its properties.
 
Method Summary
 void load(com.google.appengine.api.datastore.Entity fromEntity, T toPojo)
          Loads the property data in an Entity into a POJO.
 void loadSingleValue(java.lang.String key, java.lang.Object value, java.lang.Object toPojo, LoadContext context)
          Loads the single value value into toPojo using key as the key within the entity.
 void save(T fromPojo, com.google.appengine.api.datastore.Entity toEntity)
          Saves the fields of a POJO into the properties of an Entity.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Transmog

public Transmog(Conversions conversions,
                java.lang.Class<T> clazz)
Creats a transmog for the specified class, introspecting it and discovering how to load/save its properties.

Method Detail

load

public void load(com.google.appengine.api.datastore.Entity fromEntity,
                 T toPojo)
Loads the property data in an Entity into a POJO. Does not affect id/parent (ie key) fields; those are assumed to already have been set.

Parameters:
fromEntity - is a raw datastore entity
toPojo - is your typed entity

loadSingleValue

public void loadSingleValue(java.lang.String key,
                            java.lang.Object value,
                            java.lang.Object toPojo,
                            LoadContext context)
Loads the single value value into toPojo using key as the key within the entity. Will use any of rootSetters or might delegate through a map setter.

Parameters:
key - the key for this value
value - the value from the datastore
toPojo - the target pojo to load into

save

public void save(T fromPojo,
                 com.google.appengine.api.datastore.Entity toEntity)
Saves the fields of a POJO into the properties of an Entity. Does not affect id/parent (ie key) fields; those are assumed to already have been set.

Parameters:
fromPojo - is your typed entity
toEntity - is a raw datastore entity


Copyright © 2011 Jeff Schnitzer and a gang of pirates. All Rights Reserved. Build version: 3.1