Interface QueryResults<V> (2.26.4)

publicinterface QueryResults<V>extendsIterator<V>

The result of a Google Cloud Datastore query submission. When the result is not typed it is possible to cast it to its appropriate type according to the #getResultClass value. Results are loaded lazily in batches, where batch size is set by Cloud Datastore. As a result, it is possible to get a DatastoreException upon hasNext or next calls.

Implements

Iterator<V>

Type Parameter

Name Description
V

Methods

getCursorAfter()

publicabstractCursorgetCursorAfter()

Returns the Cursor for the point after the value returned in the last #next call. This cursor can be used to issue subsequent queries (with the same constraints) that may return additional results.

A simple use case:


Query<Entity>query=Query.newEntityQueryBuilder()
.setKind("Person")
.setFilter(PropertyFilter.eq("favoriteFood","pizza"))
.build();
QueryResults<Entity>results=datastore.run(query);
// Consume some results (using results.next()) and do any other actions as necessary.
query=query.toBuilder().setStartCursor(results.getCursorAfter()).build();
results=datastore.run(query);// now we will iterate over all entities not yet consumed
Returns
Type Description
Cursor

getExplainMetrics()

publicdefaultOptional<ExplainMetrics>getExplainMetrics()
Returns
Type Description
Optional<ExplainMetrics>

getMoreResults()

publicabstractQueryResultBatch.MoreResultsTypegetMoreResults()

Returns MoreResults state of the query after the current batch.

Returns
Type Description
QueryResultBatch.MoreResultsType

getResultClass()

publicabstractClass<?>getResultClass()

Returns the actual class of the result's values.

Returns
Type Description
Class<?>

getSkippedResults()

publicabstractintgetSkippedResults()

Returns the number of results skipped, typically because of an offset.

A simple use case to count entities:


Query<Key>query=Query.newKeyQueryBuilder().setOffset(Integer.MAX_VALUE).build();
QueryResults<Key>result=datasore.datastore.run(query);
if(!result.hasNext()){
intnumberOfEntities=result.getSkippedResults();
}
Returns
Type Description
int

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025年11月19日 UTC.