# Class StructuredQuery&lt;V&gt; (3.1.0)

3.1.0 (latest) 2.40.0 2.37.0 2.36.0 2.34.0 2.33.3 2.32.3 2.31.4 2.30.0 2.29.1 2.28.2 2.27.1 2.26.4 2.25.2 2.24.3 2.23.0 2.22.0 2.21.3 2.20.2 2.19.2 2.18.5 2.17.6

    public abstract class StructuredQuery<V> extends Query<V> implements RecordQuery<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()) {
       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: [Datastore queries](https://cloud.google.com/appengine/docs/java/datastore/queries)

## Inheritance

[Object](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html) \> [Query](https://docs.cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.cloud.datastore.Query) \> StructuredQuery\<V\>

## Implements

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

## Inherited Members

[Query.\<V\>newGqlQueryBuilder(Query.ResultType\<V\>,String)](https://docs.cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.cloud.datastore.Query#com_google_cloud_datastore_Query__V_newGqlQueryBuilder_com_google_cloud_datastore_Query_ResultType_V__java_lang_String_) [Query.getNamespace()](https://docs.cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.cloud.datastore.Query#com_google_cloud_datastore_Query_getNamespace__) [Query.newAggregationQueryBuilder()](https://docs.cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.cloud.datastore.Query#com_google_cloud_datastore_Query_newAggregationQueryBuilder__) [Query.newEntityQueryBuilder()](https://docs.cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.cloud.datastore.Query#com_google_cloud_datastore_Query_newEntityQueryBuilder__) [Query.newGqlQueryBuilder(String)](https://docs.cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.cloud.datastore.Query#com_google_cloud_datastore_Query_newGqlQueryBuilder_java_lang_String_) [Query.newKeyQueryBuilder()](https://docs.cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.cloud.datastore.Query#com_google_cloud_datastore_Query_newKeyQueryBuilder__) [Query.newProjectionEntityQueryBuilder()](https://docs.cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.cloud.datastore.Query#com_google_cloud_datastore_Query_newProjectionEntityQueryBuilder__) [Object.clone()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#clone--) [Object.equals(Object)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals-java.lang.Object-) [Object.finalize()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#finalize--) [Object.getClass()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#getClass--) [Object.hashCode()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--) [Object.notify()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notify--) [Object.notifyAll()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notifyAll--) [Object.toString()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--) [Object.wait()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait--) [Object.wait(long)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-) [Object.wait(long,int)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-int-)

| ## Type Parameter ||
|---|---|
| **Name** | **Description** |
| `V` |   |

## Methods

### equals(Object obj)

    public boolean equals(Object obj)

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `obj` | `https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

**Overrides** [Object.equals(Object)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals-java.lang.Object-)

### getDistinctOn()

    public List<String> getDistinctOn()

Returns the distinct on clause for this query.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/util/List.html<https://docs.oracle.com/javase/8/docs/api/java/lang/String.html>` |   |

### getEndCursor()

    public Cursor getEndCursor()

Returns the end cursor for this query.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.cloud.datastore.Cursor` |   |

### getFilter()

    public StructuredQuery.Filter getFilter()

Returns the filter for this query.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.cloud.datastore.StructuredQuery.Filter` |   |

### getKind()

    public String getKind()

Returns the kind for this query.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |   |

### getLimit()

    public Integer getLimit()

Returns the limit for this query.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/Integer.html` |   |

### getOffset()

    public int getOffset()

Returns the offset for this query.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

### getOrderBy()

    public List<StructuredQuery.OrderBy> getOrderBy()

Returns the order by clause for this query.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/util/List.html<https://docs.cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.cloud.datastore.StructuredQuery.OrderBy>` |   |

### getProjection()

    public List<String> getProjection()

Returns the projection for this query.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/util/List.html<https://docs.oracle.com/javase/8/docs/api/java/lang/String.html>` |   |

### getStartCursor()

    public Cursor getStartCursor()

Returns the start cursor for this query.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.cloud.datastore.Cursor` |   |

### getType()

    public Query.ResultType<V> getType()

> [!WARNING]
> **Internal Only**: This feature is not stable for application use.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.cloud.datastore.Query.ResultType<V>` |   |

### hashCode()

    public int hashCode()

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

**Overrides** [Object.hashCode()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--)

### nextQuery(RunQueryResponse responsePb)

    public StructuredQuery<V> nextQuery(RunQueryResponse responsePb)

> [!WARNING]
> **Internal Only**: This feature is not stable for application use.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `responsePb` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.datastore.v1.RunQueryResponse` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.cloud.datastore.StructuredQuery<V>` |   |

### populatePb(RunQueryRequest.Builder requestPb)

    public void populatePb(RunQueryRequest.Builder requestPb)

> [!WARNING]
> **Internal Only**: This feature is not stable for application use.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `requestPb` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.datastore.v1.RunQueryRequest.Builder` |

### toBuilder()

    public abstract StructuredQuery.Builder<V> toBuilder()

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.cloud.datastore.StructuredQuery.Builder<V>` |   |

### toString()

    public String toString()

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |   |

**Overrides** [Object.toString()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--)