Interface PreparedQuery
-
public interface PreparedQuery
Contains methods for fetching and returning entities from aQuery
. If theQuery
specified a sort order,Entities
are returned in that order. Otherwise, the order is undefined.A
PreparedQuery
does not cache results. Each use ofPreparedQuery
results in a new trip to the datastore.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface and Description static class
PreparedQuery.TooManyResultsException
Indicates that too many results were found forasSingleEntity()
.
-
Method Summary
-
-
-
Method Detail
-
asList
java.util.List<Entity> asList(FetchOptions fetchOptions)
Retrieves theQuery
Entities
as aList
using the providedFetchOptions
.Note that if
FetchOptions.getLimit()
is greater than the number ofEntities
, the length of the returnedList
will be smaller thanFetchOptions.getLimit()
.To operate on large result sets, you should prefer
asIterable(com.google.appengine.api.datastore.FetchOptions)
andasIterator(com.google.appengine.api.datastore.FetchOptions)
, which stream the results from the datastore.- Parameters:
fetchOptions
- The fetch options to apply.- Returns:
- The result of the PreparedQuery, represented as a
List
. - Throws:
java.lang.IllegalStateException
- If the query being executed is associated with aTransaction
that is not active.- See Also:
FetchOptions
-
asQueryResultList
QueryResultList<Entity> asQueryResultList(FetchOptions fetchOptions)
Similar toasList(com.google.appengine.api.datastore.FetchOptions)
except aQueryResultIterator
is returned.
-
asIterable
java.lang.Iterable<Entity> asIterable(FetchOptions fetchOptions)
Retrieves theQuery
Entities
as anIterable
using the providedFetchOptions
.Each use of
Iterable.iterator()
results in an entirely new and independentIterator
.- Parameters:
fetchOptions
- The fetch options to apply.- Returns:
- The result of the PreparedQuery, represented as an
Iterable
. - Throws:
java.lang.IllegalStateException
- If the query being executed is associated with aTransaction
that is not active.- See Also:
FetchOptions
-
asQueryResultIterable
QueryResultIterable<Entity> asQueryResultIterable(FetchOptions fetchOptions)
Similar toasIterable(FetchOptions)
except aQueryResultIterable
is returned. Call this method to have (indirect) access toCursor
s for your result set.
-
asIterable
java.lang.Iterable<Entity> asIterable()
Equivalent toasIterable(FetchOptions)
but uses defaultFetchOptions
.
-
asQueryResultIterable
QueryResultIterable<Entity> asQueryResultIterable()
Similar toasIterable()
except aQueryResultIterable
is returned. Call this method to have (indirect) access toCursor
s for your result set.
-
asIterator
java.util.Iterator<Entity> asIterator(FetchOptions fetchOptions)
- Parameters:
fetchOptions
- The fetch strategy to apply.- Returns:
- The result of the PreparedQuery, represented as an
Iterator
. - Throws:
java.lang.IllegalStateException
- If the query being executed is associated with aTransaction
that is not active.- See Also:
FetchOptions
-
asIterator
java.util.Iterator<Entity> asIterator()
Equivalent toasIterator(FetchOptions)
but uses defaultFetchOptions
.
-
asQueryResultIterator
QueryResultIterator<Entity> asQueryResultIterator(FetchOptions fetchOptions)
Similar toasIterator(FetchOptions)
except aQueryResultIterator
is returned. Call this method to have access toCursor
s for your result set.
-
asQueryResultIterator
QueryResultIterator<Entity> asQueryResultIterator()
Similar toasIterator()
except aQueryResultIterator
is returned. Call this method to have access toCursor
s for your result set.
-
asSingleEntity
Entity asSingleEntity() throws PreparedQuery.TooManyResultsException
Retrieves the one and only result for theQuery
.- Returns:
- the single, matching result, or
null
if no entities match - Throws:
PreparedQuery.TooManyResultsException
- if more than one result is returned from theQuery
.java.lang.IllegalStateException
- If the query being executed is associated with aTransaction
that is not active.
-
countEntities
int countEntities(FetchOptions fetchOptions)
- Returns:
- a count >= 0
- Throws:
java.lang.IllegalStateException
- If the query being executed is associated with aTransaction
that is not active.
-
countEntities
@Deprecated int countEntities()
Deprecated. UsecountEntities(FetchOptions)
instead. Calling this function imposes a maximum result limit of 1000.- Returns:
- a count >= 0
- Throws:
java.lang.IllegalStateException
- If the query being executed is associated with aTransaction
that is not active.
-
-