com.googlecode.objectify.impl.load.Setter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of objectify Show documentation
Show all versions of objectify Show documentation
*** THIS VERSION UPLOADED FOR USE WITH CEDAR-COMMON, TO AVOID DEPENDENCIES ON GOOGLE CODE-BASED MAVEN REPOSITORIES. *** The simplest convenient interface to the Google App Engine datastore
The newest version!
package com.googlecode.objectify.impl.load;
import com.googlecode.objectify.impl.LoadContext;
/**
* A setter knows how to set a value in an object graph. It may be composed of
* a variety of internal setters that know how to set a value deep in an object graph.
* The value being set is a leaf value from the datastore; that is,
* something that it persists directly (basic type or collection of basic types).
*
* For example, imagine a Setter for a Person entity with property "name.firstName".
*
* - Transmog will find a property in the Entity called "name.firstName" with value "Bob".
* - Transmog will look up a Setter for "name.firstName".
* - Transmog will call setter.set(rootPojo, "Bob")
* - The EmbeddedClassSetter will create a Person object in rootPojo.name
* - The EmbeddedClassSetter will delegate to a LeafSetter, passing in the Person
* - The LeafSetter will set the name field on the Person object.
*
*
* Setters are a linear chain like a linked list. They are also immutable. You
* extend the chain by calling extend(), passing in the new tail; this produces an
* entirely new list.
*/
abstract public class Setter implements Cloneable
{
/** The next setter to execute in the chain */
Setter next;
/**
* Called by the Transmog to set a value on an object. Might actually delegate to
* some composite setter to actually set a value deep in the structure.
*/
abstract public void set(Object toPojo, Object value, LoadContext context);
/**
* @return the next setter in the chain, or null if there is none
*/
public Setter getNext() { return this.next; }
/**
* Extends the whole chain, adding a setter to the tail. Since the setters
* are immutable, this returns an entirely new list with the tail at the end.
*/
public Setter extend(Setter tail)
{
Setter cloned = this.clone();
Setter traverse = cloned;
while (traverse.next != null)
traverse = traverse.next;
traverse.next = tail;
return cloned;
}
/**
* Create a copy of this Setter and all child setters in the chain.
*/
@Override
public Setter clone()
{
try
{
Setter cloned = (Setter)super.clone();
if (cloned.next != null)
cloned.next = cloned.next.clone();
return cloned;
}
catch (CloneNotSupportedException e) { throw new RuntimeException(e); }
}
}