Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
*** 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
package com.googlecode.objectify.impl;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Comparator;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import com.google.appengine.api.datastore.Cursor;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.FetchOptions;
import com.google.appengine.api.datastore.KeyFactory;
import com.google.appengine.api.datastore.PreparedQuery;
import com.google.appengine.api.datastore.Query.FilterOperator;
import com.google.appengine.api.datastore.Query.FilterPredicate;
import com.google.appengine.api.datastore.Query.SortDirection;
import com.google.appengine.api.datastore.Query.SortPredicate;
import com.google.appengine.api.datastore.QueryResultIterable;
import com.google.appengine.api.datastore.QueryResultIterator;
import com.googlecode.objectify.Key;
import com.googlecode.objectify.Objectify;
import com.googlecode.objectify.ObjectifyFactory;
import com.googlecode.objectify.Query;
import com.googlecode.objectify.annotation.Subclass;
import com.googlecode.objectify.util.TranslatingQueryResultIterator;
/**
* Implementation of Query.
*
* @author Jeff Schnitzer
*/
public class QueryImpl implements Query, Cloneable
{
/** */
ObjectifyFactory factory;
Objectify ofy;
/** We need to track this because it enables the ability to filter/sort by id */
Class classRestriction;
/** The actual datastore query constructed by this object */
com.google.appengine.api.datastore.Query actual;
/** */
int limit;
int offset;
Cursor startCursor;
Cursor endCursor;
Integer chunkSize;
Integer prefetchSize;
/** */
public QueryImpl(ObjectifyFactory fact, Objectify objectify)
{
this.factory = fact;
this.ofy = objectify;
this.actual = new com.google.appengine.api.datastore.Query();
}
/** */
public QueryImpl(ObjectifyFactory fact, Objectify objectify, Class clazz)
{
this.factory = fact;
this.ofy = objectify;
this.actual = new com.google.appengine.api.datastore.Query(Key.getKind(clazz));
// If this is a polymorphic subclass, add an extra filter
Subclass sub = clazz.getAnnotation(Subclass.class);
if (sub != null)
{
String discriminator = sub.name().length() > 0 ? sub.name() : clazz.getSimpleName();
this.actual.addFilter(PolymorphicEntityMetadata.DISCRIMINATOR_INDEX_PROPERTY, FilterOperator.EQUAL, discriminator);
}
this.classRestriction = clazz;
}
/** @return the underlying datastore query object */
protected com.google.appengine.api.datastore.Query getActual()
{
return this.actual;
}
/* (non-Javadoc)
* @see com.googlecode.objectify.Query#filter(java.lang.String, java.lang.Object)
*/
@Override
public Query filter(String condition, Object value)
{
String[] parts = condition.trim().split(" ");
if (parts.length < 1 || parts.length > 2)
throw new IllegalArgumentException("'" + condition + "' is not a legal filter condition");
String prop = parts[0].trim();
FilterOperator op = (parts.length == 2) ? this.translate(parts[1]) : FilterOperator.EQUAL;
// If we have a class restriction, check to see if the property is the @Id
if (this.classRestriction != null)
{
EntityMetadata meta = this.factory.getMetadata(this.classRestriction);
if (meta.isIdField(prop) || meta.isNameField(prop))
{
if (meta.hasParentField())
throw new IllegalStateException("Cannot (yet) filter by @Id fields on entities which have @Parent fields. Tried '" + prop + "' on " + this.classRestriction.getName() + ".");
boolean isNumericId = meta.isIdField(prop);
if (op == FilterOperator.IN)
{
if (!(value instanceof Iterable || value instanceof Object[]))
throw new IllegalStateException("IN operator requires a collection value. Value was " + value);
if (value instanceof Object[])
value = Arrays.asList(((Object[])value));
// This is a bit complicated - we need to make a list of vanilla datastore Key objects.
List