com.googlecode.objectify.impl.save.EmbeddedMultivalueFieldSaver 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.save;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import com.google.appengine.api.datastore.Entity;
import com.googlecode.objectify.annotation.Indexed;
import com.googlecode.objectify.annotation.Unindexed;
import com.googlecode.objectify.impl.TypeUtils;
import com.googlecode.objectify.impl.conv.Conversions;
/**
* Base class for EmbeddedArrayFieldSaver and EmbeddedCollectionFieldSaver
* that handles most of the logic. The subclasses need only understand how to
* get the component type and how to make an iterator.
*/
abstract public class EmbeddedMultivalueFieldSaver extends FieldSaver
{
/** Used to actually save the object in the field */
ClassSaver classSaver;
/**
* @param field must be an array type
* @param ignoreClassIndexing see the FieldSaver javadocs
* @param collectionize must always be false because we cannot nest embedded arrays
* or collections. This parameter is here so that it is always passed in the code,
* never forgotten, and will always generate the appropriate runtime error.
*/
public EmbeddedMultivalueFieldSaver(Conversions conv, Class examinedClass, Field field, boolean ignoreClassIndexing, boolean collectionize)
{
super(examinedClass, field, ignoreClassIndexing, collectionize);
if (collectionize)
throw new IllegalStateException("You cannot nest multiple @Embedded arrays or collections. A second was found at " + field);
boolean ignoreClassIndexingAnnotations =
this.field.isAnnotationPresent(Indexed.class) || this.field.isAnnotationPresent(Unindexed.class);
// Now we collectionize everything on down
// We use our indexed state to define everything below us
this.classSaver = new ClassSaver(conv, this.getComponentType(), ignoreClassIndexingAnnotations, true, true);
}
/** Gets the component type of the field */
abstract protected Class getComponentType();
/** Gets an iterator from the array or collection passed in */
abstract protected Collection