public class SimpleQueryWrapper<H extends SimpleQueryWrapper<H,T>,T> extends Object implements SimpleQuery<T>, Cloneable
class MySimpleQuery<T> extends SimpleQueryWrapper<MyQuery<T>, T>
Constructor and Description |
---|
SimpleQueryWrapper(SimpleQuery<T> base) |
Modifier and Type | Method and Description |
---|---|
H |
ancestor(Object keyOrEntity)
Restricts result set only to objects which have the given ancestor
somewhere in the chain.
|
H |
chunk(int value)
Sets the internal chunking and prefetching strategy within the low-level API.
|
H |
chunkAll()
Sets the internal chunking and prefetching strategy within the low-level API to attempt to get all
results at once.
|
protected H |
clone() |
int |
count()
Count the total number of values in the result.
|
H |
distinct(boolean value)
Determines whether this is a SELECT DISTINCT query.
|
H |
endAt(com.google.appengine.api.datastore.Cursor value)
Ends query results at the specified Cursor.
|
SimpleQuery<T> |
filterKey(Object value)
An alias for
filterKey("=", value) |
H |
filterKey(String condition,
Object value)
Create a filter on the key of an entity.
|
LoadResult<T> |
first()
Gets the first entity in the result set.
|
H |
hybrid(boolean force)
This method forces Objectify to (or not to) hybridize the query into a keys-only fetch plus batch get.
|
com.google.appengine.api.datastore.QueryResultIterable<T> |
iterable()
Starts an asynchronous query which will return entities.
|
com.google.appengine.api.datastore.QueryResultIterator<T> |
iterator() |
QueryKeys<T> |
keys()
Switches to a keys-only query.
|
H |
limit(int value)
Limit the fetched result set to a certain number of values.
|
List<T> |
list()
Execute the query and get the results as a List.
|
H |
offset(int value)
Starts the query results at a particular zero-based offset.
|
H |
startAt(com.google.appengine.api.datastore.Cursor value)
Starts query results at the specified Cursor.
|
String |
toString()
Generates a string that consistently and uniquely specifies this query.
|
public SimpleQueryWrapper(SimpleQuery<T> base)
public H filterKey(String condition, Object value)
SimpleQuery
Create a filter on the key of an entity. Examples:
filterKey(">=", key)
(standard inequalities)filterKey("=", key)
(wouldn't you rather do a load-by-key?)filterKey("", key)
(if no operator, = is assumed)filterKey("!=", key)
filterKey("in", keyList)
(wouldn't you rather do a batch load-by-key?)The key parameter can be anything key-ish; a Key>, a native datastore key, a Ref, a pojo entity, etc.
See the Google documentation for indexes for an explanation of what you can and cannot filter for.
filterKey
in interface SimpleQuery<T>
public SimpleQuery<T> filterKey(Object value)
SimpleQuery
filterKey("=", value)
filterKey
in interface SimpleQuery<T>
public H ancestor(Object keyOrEntity)
SimpleQuery
ancestor
in interface SimpleQuery<T>
keyOrEntity
- can be a Key, a Keypublic H limit(int value)
SimpleQuery
limit
in interface SimpleQuery<T>
value
- must be >= 0. A value of 0 indicates no limit.public H offset(int value)
SimpleQuery
offset
in interface SimpleQuery<T>
value
- must be >= 0public H startAt(com.google.appengine.api.datastore.Cursor value)
SimpleQuery
startAt
in interface SimpleQuery<T>
public H endAt(com.google.appengine.api.datastore.Cursor value)
SimpleQuery
endAt
in interface SimpleQuery<T>
public String toString()
SimpleQuery
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 interface QueryExecute<T>
toString
in interface SimpleQuery<T>
toString
in class Object
public LoadResult<T> first()
QueryExecute
first
in interface QueryExecute<T>
public int count()
SimpleQuery
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.
Immediately executes the query; there is no async version of this method.
WARNING: Each counted entity is billed as a "datastore minor operation". Counting large numbers of entities can quickly create massive bills.
count
in interface SimpleQuery<T>
public com.google.appengine.api.datastore.QueryResultIterable<T> iterable()
QueryExecute
Starts an asynchronous query which will return entities.
Note that since the Query
iterable
in interface QueryExecute<T>
public List<T> list()
QueryExecute
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.
list
in interface QueryExecute<T>
public H chunk(int value)
SimpleQuery
chunk
in interface SimpleQuery<T>
value
- must be >= 0public H chunkAll()
SimpleQuery
Sets the internal chunking and prefetching strategy within the low-level API to attempt to get all results at once. Affects performance only; the result set will be the same.
Same as chunk(Integer.MAX_VALUE).
chunkAll
in interface SimpleQuery<T>
public H distinct(boolean value)
SimpleQuery
distinct
in interface SimpleQuery<T>
public H hybrid(boolean force)
SimpleQuery
This method forces Objectify to (or not to) hybridize the query into a keys-only fetch plus batch get.
If Objectify knows you are fetching an entity type that can be cached, it automatically converts queries into a "hybrid" of keys-only query followed by a batch fetch of the keys. This is cheaper (keys-only results are 1/7th the price of a full fetch) and, if the cache hits, significantly faster. However, there are some circumstances in which you may wish to force behavior one way or another:
For the most part, hybridization only affects the performance and cost of queries. However, it is possible
for hybridization to alter the content of the result set. In the HRD, queries
always have EVENTUAL consistency but get operations may have either STRONG or EVENTUAL consistency depending
on the read policy (see Objectify.consistency()
. The keys-only query results will always be EVENTUAL and may
return data that has been deleted, but Objectify will exclude these results when the more-current batch get fails to return
data. So the count of the returned data may actually be less than the limit(), even if there are plenty of
actual results. hybrid(false)
will prevent this behavior.
Note that in hybrid queries, the chunk size defines the batch size.
hybrid
in interface SimpleQuery<T>
public com.google.appengine.api.datastore.QueryResultIterator<T> iterator()
public QueryKeys<T> keys()
SimpleQuery
keys
in interface SimpleQuery<T>
Copyright © 2013. All Rights Reserved.