Class Query<V> (2.11.4)

public abstract class Query<V> implements Serializable

A Google Cloud Datastore query. For usage examples see GqlQuery and StructuredQuery.

Note that queries require proper indexing. See Cloud Datastore Index Configuration for help configuring indexes. See Also: Datastore Queries

Inheritance

java.lang.Object > Query<V>

Implements

Serializable

Type Parameter

NameDescription
V

Static Methods

<V>newGqlQueryBuilder(Query.ResultType<V> resultType, String gql)

public static GqlQuery.Builder<V> <V>newGqlQueryBuilder(Query.ResultType<V> resultType, String gql)

Returns a new 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
 

See Also: GQL Reference

Parameters
NameDescription
resultTypeResultType<V>
gqlString
Returns
TypeDescription
Builder<V>

newEntityQueryBuilder()

public static EntityQuery.Builder newEntityQueryBuilder()

Returns a new 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
 
Returns
TypeDescription
EntityQuery.Builder

newGqlQueryBuilder(String gql)

public static GqlQuery.Builder<?> newGqlQueryBuilder(String gql)

Returns a new 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
 

See Also: GQL Reference

Parameter
NameDescription
gqlString
Returns
TypeDescription
Builder<?>

newKeyQueryBuilder()

public static KeyQuery.Builder newKeyQueryBuilder()

Returns a new 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
 
Returns
TypeDescription
KeyQuery.Builder

newProjectionEntityQueryBuilder()

public static ProjectionEntityQuery.Builder newProjectionEntityQueryBuilder()

Returns a new 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
 
Returns
TypeDescription
ProjectionEntityQuery.Builder

Methods

getNamespace()

public String getNamespace()
Returns
TypeDescription
String