Interface PreparedQuery (2.0.0)

public interface PreparedQuery

Contains methods for fetching and returning entities from a Query. If the Query specified a sort order, Entities are returned in that order. Otherwise, the order is undefined.

A PreparedQuery does not cache results. Each use of PreparedQuery results in a new trip to the datastore.

Methods

asIterable()

public abstract Iterable<Entity> asIterable()

Equivalent to #asIterable(FetchOptions) but uses default FetchOptions.

Returns
Type Description
Iterable<Entity>

asIterable(FetchOptions fetchOptions)

public abstract Iterable<Entity> asIterable(FetchOptions fetchOptions)

Retrieves the Query Entities as an Iterable using the provided FetchOptions.

Each use of Iterable#iterator results in an entirely new and independent Iterator. See Also: FetchOptions

Parameter
Name Description
fetchOptions FetchOptions

The fetch options to apply.

Returns
Type Description
Iterable<Entity>

The result of the PreparedQuery, represented as an Iterable.

asIterator()

public abstract Iterator<Entity> asIterator()

Equivalent to #asIterator(FetchOptions) but uses default FetchOptions.

Returns
Type Description
Iterator<Entity>

asIterator(FetchOptions fetchOptions)

public abstract Iterator<Entity> asIterator(FetchOptions fetchOptions)

Retrieves the Query Entities as an Iterator using the provided FetchOptions. See Also: FetchOptions

Parameter
Name Description
fetchOptions FetchOptions

The fetch strategy to apply.

Returns
Type Description
Iterator<Entity>

The result of the PreparedQuery, represented as an Iterator.

asList(FetchOptions fetchOptions)

public abstract List<Entity> asList(FetchOptions fetchOptions)

Retrieves the Query Entities as a List using the provided FetchOptions.

Note that if FetchOptions#getLimit() is greater than the number of Entities, the length of the returned List will be smaller thanFetchOptions#getLimit().

To operate on large result sets, you should prefer #asIterable and #asIterator, which stream the results from the datastore. See Also: FetchOptions

Parameter
Name Description
fetchOptions FetchOptions

The fetch options to apply.

Returns
Type Description
List<Entity>

The result of the PreparedQuery, represented as a List.

asQueryResultIterable()

public abstract QueryResultIterable<Entity> asQueryResultIterable()

Similar to #asIterable() except a QueryResultIterable is returned. Call this method to have (indirect) access to Cursors for your result set.

Returns
Type Description
QueryResultIterable<Entity>

asQueryResultIterable(FetchOptions fetchOptions)

public abstract QueryResultIterable<Entity> asQueryResultIterable(FetchOptions fetchOptions)

Similar to #asIterable(FetchOptions) except a QueryResultIterable is returned. Call this method to have (indirect) access to Cursors for your result set.

Parameter
Name Description
fetchOptions FetchOptions
Returns
Type Description
QueryResultIterable<Entity>

asQueryResultIterator()

public abstract QueryResultIterator<Entity> asQueryResultIterator()

Similar to #asIterator() except a QueryResultIterator is returned. Call this method to have access to Cursors for your result set.

Returns
Type Description
QueryResultIterator<Entity>

asQueryResultIterator(FetchOptions fetchOptions)

public abstract QueryResultIterator<Entity> asQueryResultIterator(FetchOptions fetchOptions)

Similar to #asIterator(FetchOptions) except a QueryResultIterator is returned. Call this method to have access to Cursors for your result set.

Parameter
Name Description
fetchOptions FetchOptions
Returns
Type Description
QueryResultIterator<Entity>

asQueryResultList(FetchOptions fetchOptions)

public abstract QueryResultList<Entity> asQueryResultList(FetchOptions fetchOptions)

Similar to #asList except a QueryResultIterator is returned.

Parameter
Name Description
fetchOptions FetchOptions
Returns
Type Description
QueryResultList<Entity>

asSingleEntity()

public abstract Entity asSingleEntity()

Retrieves the one and only result for the Query.

Returns
Type Description
Entity

the single, matching result, or null if no entities match

Exceptions
Type Description
PreparedQuery.TooManyResultsException

if more than one result is returned from the Query.

countEntities() (deprecated)

public abstract int countEntities()

Deprecated. Use #countEntities(FetchOptions) instead. Calling this function imposes a maximum result limit of 1000.

Retrieves the number of Entities that currently match this Query.

Returns
Type Description
int

a count >= 0

countEntities(FetchOptions fetchOptions)

public abstract int countEntities(FetchOptions fetchOptions)

Retrieves the number of Entities that currently match this Query.

Parameter
Name Description
fetchOptions FetchOptions
Returns
Type Description
int

a count >= 0