|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface Query<T>
This is similar to the datastore Query object, but better understands real class objects - it allows you to filter and sort by the key field normally.
The methods of this class follow the GAE/Python Query class rather than the GAE/Java Query class because the Python version is much more convenient to use. The Java version seems to have been designed for machines, not humans. You will appreciate the improvement.
Construct this class by calling Objectify.query()
Note that this class is Iterable; to get results, call iterator().
To obtain a Cursor
call Query.iterator().getCursor()
.
This cursor can be resumed with Query.cursor()
.
Method Summary | ||
---|---|---|
Query<T> |
ancestor(java.lang.Object keyOrEntity)
Restricts result set only to objects which have the given ancestor somewhere in the chain. |
|
Query<T> |
chunkSize(int value)
Sets the internal chunking strategy within the low-level API. |
|
Query<T> |
clone()
|
|
int |
count()
Count the total number of values in the result. |
|
Query<T> |
endCursor(com.google.appengine.api.datastore.Cursor value)
Ends query results at the specified Cursor. |
|
com.google.appengine.api.datastore.QueryResultIterable<T> |
fetch()
Starts an asynchronous query. |
|
com.google.appengine.api.datastore.QueryResultIterable<Key<T>> |
fetchKeys()
Prepares an Iterable that will obtain the keys of the results. |
|
|
fetchParentKeys()
Execute a keys-only query and then extract parent keys, returning them as a Set. |
|
|
fetchParents()
Gets the parent keys and then fetches the actual entities. |
|
Query<T> |
filter(java.lang.String condition,
java.lang.Object value)
Create a filter based on the specified condition and value, using the same syntax as the GAE/Python query class. |
|
T |
get()
Gets the first entity in the result set. |
|
Key<T> |
getKey()
Get the key of the first entity in the result set. |
|
Query<T> |
limit(int value)
Limit the fetched result set to a certain number of values. |
|
java.util.List<T> |
list()
Execute the query and get the results as a List. |
|
java.util.List<Key<T>> |
listKeys()
Execute a keys-only query and get the results as a List. |
|
Query<T> |
offset(int value)
Starts the query results at a particular zero-based offset. |
|
Query<T> |
order(java.lang.String condition)
Sorts based on a property. |
|
Query<T> |
prefetchSize(int value)
Sets the number of results retreived on the first call to the datastore. |
|
Query<T> |
startCursor(com.google.appengine.api.datastore.Cursor value)
Starts query results at the specified Cursor. |
|
java.lang.String |
toString()
Generates a string that consistently and uniquely specifies this query. |
Methods inherited from interface com.google.appengine.api.datastore.QueryResultIterable |
---|
iterator |
Method Detail |
---|
Query<T> filter(java.lang.String condition, java.lang.Object value)
Create a filter based on the specified condition and value, using the same syntax as the GAE/Python query class. Examples:
filter("age >=", age)
filter("age =", age)
filter("age", age)
(if no operator, = is assumed)filter("age !=", age)
filter("age in", ageList)
The space is required. Filtering a condition of
"age>="
will perform an equality test on an entity property
with that exact name. You can't create properties like this with Objectify,
but you can with the Low-Level API.
See the Google documentation for indexes for an explanation of what you can and cannot filter for.
In addition to filtering on indexed properties, you can filter on @Id properties
if this query is restricted to a Class
You can not filter on @Parent properties. Use
the ancestor()
method instead.
Query<T> order(java.lang.String condition)
Sorts based on a property. Examples:
order("age")
order("-age")
(descending sort)You can sort on id properties if this query is
restricted to a Class
You can not sort on @Parent properties.
Query<T> ancestor(java.lang.Object keyOrEntity)
keyOrEntity
- can be a Key, a KeyQuery<T> limit(int value)
value
- must be >= 0. A value of 0 indicates no limit.Query<T> offset(int value)
value
- must be >= 0Query<T> startCursor(com.google.appengine.api.datastore.Cursor value)
Query<T> endCursor(com.google.appengine.api.datastore.Cursor value)
Query<T> chunkSize(int value)
value
- must be > 0Query<T> prefetchSize(int value)
value
- must be >= 0java.lang.String toString()
Generates a string that consistently and uniquely specifies this query. There is no way to convert this string back into a query and there is no guarantee that the string will be consistent across versions of Objectify.
In particular, this value is useful as a key for a simple memcache query cache.
toString
in class java.lang.Object
T get()
Key<T> getKey()
com.google.appengine.api.datastore.QueryResultIterable<T> fetch()
com.google.appengine.api.datastore.QueryResultIterable<Key<T>> fetchKeys()
<V> java.util.Set<Key<V>> fetchParentKeys()
java.lang.IllegalStateException
- if any member of the query result does not have a parent.<V> java.util.Map<Key<V>,V> fetchParents()
ofy.get(query.fetchParentKeys())
.
java.lang.IllegalStateException
- if any member of the query result does not have a parent.int count()
Count the total number of values in the result. limit and offset are obeyed.
This is somewhat faster than fetching, but the time still grows with the number of results. The datastore actually walks through the result set and counts for you.
java.util.List<T> list()
Execute the query and get the results as a List. The list will be equivalent to a simple ArrayList; you can iterate through it multiple times without incurring additional datastore cost.
Note that you must be careful about limit()ing the size of the list returned; you can easily exceed the practical memory limits of Appengine by querying for a very large dataset.
java.util.List<Key<T>> listKeys()
Execute a keys-only query and get the results as a List. This is more efficient than fetching the actual results.
The size and scope considerations of list() apply; don't fetch more data than you can fit in a simple ArrayList.
Query<T> clone()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |