Class StructuredQuery<V> (2.23.0)

publicabstractclass StructuredQuery<V>extendsQuery<V>implementsRecordQuery<V>

An implementation of a Google Cloud Datastore Query that can be constructed by providing all the specific query elements.

A usage example:

A simple query that returns all entities for a specific kind


Query<Entity>query=Query.newEntityQueryBuilder().setKind(kind).build();
QueryResults<Entity>results=datastore.run(query);
while(results.hasNext()){
Entityentity=results.next();
...
}

A simple key-only query of all entities for a specific kind


Query<Key>keyOnlyQuery=Query.newKeyQueryBuilder().setKind(KIND1).build();
QueryResults<Key>results=datastore.run(keyOnlyQuery);
...

A less trivial example of a projection query that returns the first 10 results of "age" and "name" properties (sorted and grouped by "age") with an age greater than 18


Query<ProjectionEntity>query=Query.newProjectionEntityQueryBuilder()
.setKind(kind)
.setProjection(Projection.property("age"),Projection.first("name"))
.setFilter(PropertyFilter.gt("age",18))
.setGroupBy("age")
.setOrderBy(OrderBy.asc("age"))
.setLimit(10)
.build();
QueryResults<ProjectionEntity>results=datastore.run(query);
...

See Also: Datastore queries

Inheritance

Object > Query > StructuredQuery<V>

Implements

com.google.cloud.datastore.RecordQuery<V>

Type Parameter

Name Description
V

Methods

equals(Object obj)

publicbooleanequals(Objectobj)
Parameter
Name Description
obj Object
Returns
Type Description
boolean
Overrides

getDistinctOn()

publicList<String>getDistinctOn()

Returns the distinct on clause for this query.

Returns
Type Description
List<String>

getEndCursor()

publicCursorgetEndCursor()

Returns the end cursor for this query.

Returns
Type Description
Cursor

getFilter()

publicStructuredQuery.FiltergetFilter()

Returns the filter for this query.

Returns
Type Description
StructuredQuery.Filter

getKind()

publicStringgetKind()

Returns the kind for this query.

Returns
Type Description
String

getLimit()

publicIntegergetLimit()

Returns the limit for this query.

Returns
Type Description
Integer

getOffset()

publicintgetOffset()

Returns the offset for this query.

Returns
Type Description
int

getOrderBy()

publicList<StructuredQuery.OrderBy>getOrderBy()

Returns the order by clause for this query.

Returns
Type Description
List<OrderBy>

getProjection()

publicList<String>getProjection()

Returns the projection for this query.

Returns
Type Description
List<String>

getStartCursor()

publicCursorgetStartCursor()

Returns the start cursor for this query.

Returns
Type Description
Cursor

getType()

publicQuery.ResultType<V>getType()
Returns
Type Description
ResultType<V>

hashCode()

publicinthashCode()
Returns
Type Description
int
Overrides

nextQuery(RunQueryResponse responsePb)

publicStructuredQuery<V>nextQuery(RunQueryResponseresponsePb)
Parameter
Name Description
responsePb RunQueryResponse
Returns
Type Description
StructuredQuery<V>

populatePb(RunQueryRequest.Builder requestPb)

publicvoidpopulatePb(RunQueryRequest.BuilderrequestPb)
Parameter
Name Description
requestPb RunQueryRequest.Builder

toBuilder()

publicabstractStructuredQuery.Builder<V>toBuilder()
Returns
Type Description
Builder<V>

toString()

publicStringtoString()
Returns
Type Description
String
Overrides

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.