Package com.google.cloud.datastore
Class StructuredQuery<V>
java.lang.Object
com.google.cloud.datastore.Query<V>
com.google.cloud.datastore.StructuredQuery<V>
- Type Parameters:
V- the type of the result values this query will produce
- All Implemented Interfaces:
RecordQuery<V>,Serializable
- Direct Known Subclasses:
EntityQuery,KeyQuery,ProjectionEntityQuery
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()) {
Entity entity = 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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceInterface for StructuredQuery builders.static final classA class representing a filter composed of a combination of other filters.static classstatic final classstatic final classA class representing a filter based on a single property or ancestor.Nested classes/interfaces inherited from class com.google.cloud.datastore.Query
Query.ResultType<V> -
Method Summary
Modifier and TypeMethodDescriptionbooleanReturns the distinct on clause for this query.Returns the end cursor for this query.Returns the filter for this query.getKind()Returns the kind for this query.getLimit()Returns the limit for this query.intReturns the offset for this query.Returns the order by clause for this query.Returns the projection for this query.Returns the start cursor for this query.getType()inthashCode()nextQuery(RunQueryResponse responsePb) voidpopulatePb(RunQueryRequest.Builder requestPb) abstract StructuredQuery.Builder<V>toString()Methods inherited from class com.google.cloud.datastore.Query
getNamespace, newAggregationQueryBuilder, newEntityQueryBuilder, newGqlQueryBuilder, newGqlQueryBuilder, newKeyQueryBuilder, newProjectionEntityQueryBuilder
-
Method Details
-
toString
-
hashCode
public int hashCode() -
equals
-
getKind
Returns the kind for this query. -
getProjection
Returns the projection for this query. -
getFilter
Returns the filter for this query. -
getDistinctOn
Returns the distinct on clause for this query. -
getOrderBy
Returns the order by clause for this query. -
getStartCursor
Returns the start cursor for this query. -
getEndCursor
Returns the end cursor for this query. -
getOffset
public int getOffset()Returns the offset for this query. -
getLimit
Returns the limit for this query. -
toBuilder
-
getType
- Specified by:
getTypein interfaceRecordQuery<V>
-
populatePb
- Specified by:
populatePbin interfaceRecordQuery<V>
-
nextQuery
- Specified by:
nextQueryin interfaceRecordQuery<V>
-