V
- the type of the values returned by this query.public abstract class Query<V> extends Object implements Serializable
GqlQuery
and StructuredQuery
.
Note that queries require proper indexing. See Cloud Datastore Index Configuration for help configuring indexes.
Modifier and Type | Class and Description |
---|---|
static class |
Query.ResultType<V>
This class represents the expected type of the result.
|
Modifier and Type | Method and Description |
---|---|
String |
getNamespace() |
static EntityQuery.Builder |
newEntityQueryBuilder()
Returns a new
StructuredQuery builder for full (complete entities) queries. |
static <V> GqlQuery.Builder<V> |
newGqlQueryBuilder(Query.ResultType<V> resultType,
String gql)
Returns a new
GqlQuery builder. |
static GqlQuery.Builder<?> |
newGqlQueryBuilder(String gql)
Returns a new
GqlQuery builder. |
static KeyQuery.Builder |
newKeyQueryBuilder()
Returns a new
StructuredQuery builder for key only queries. |
static ProjectionEntityQuery.Builder |
newProjectionEntityQueryBuilder()
Returns a new
StructuredQuery builder for projection queries. |
public String getNamespace()
public static GqlQuery.Builder<?> newGqlQueryBuilder(String gql)
GqlQuery
builder.
Example of creating and running a GQL query.
String kind = "my_kind";
String gqlQuery = "select * from " + kind;
Query<?> query = Query.newGqlQueryBuilder(gqlQuery).build();
QueryResults<?> results = datastore.run(query);
// Use results
public static <V> GqlQuery.Builder<V> newGqlQueryBuilder(Query.ResultType<V> resultType, String gql)
GqlQuery
builder.
Example of creating and running a typed GQL query.
String kind = "my_kind";
String gqlQuery = "select * from " + kind;
Query<Entity> query = Query.newGqlQueryBuilder(Query.ResultType.ENTITY, gqlQuery).build();
QueryResults<Entity> results = datastore.run(query);
// Use results
public static EntityQuery.Builder newEntityQueryBuilder()
StructuredQuery
builder for full (complete entities) queries.
Example of creating and running an entity query.
String kind = "my_kind";
Query<Entity> query = Query.newEntityQueryBuilder().setKind(kind).build();
QueryResults<Entity> results = datastore.run(query);
// Use results
public static KeyQuery.Builder newKeyQueryBuilder()
StructuredQuery
builder for key only queries.
Example of creating and running a key query.
String kind = "my_kind";
Query<Key> query = Query.newKeyQueryBuilder().setKind(kind).build();
QueryResults<Key> results = datastore.run(query);
// Use results
public static ProjectionEntityQuery.Builder newProjectionEntityQueryBuilder()
StructuredQuery
builder for projection queries.
Example of creating and running a projection entity query.
String kind = "my_kind";
String property = "my_property";
Query<ProjectionEntity> query = Query.newProjectionEntityQueryBuilder()
.setKind(kind)
.addProjection(property)
.build();
QueryResults<ProjectionEntity> results = datastore.run(query);
// Use results
Copyright © 2019 Google LLC. All rights reserved.