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
Implements
SerializableType Parameter
Name | Description |
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
Name | Description |
resultType | ResultType<V> |
gql | String |
Type | Description |
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
Type | Description |
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
Name | Description |
gql | String |
Type | Description |
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
Type | Description |
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
Type | Description |
ProjectionEntityQuery.Builder |
Methods
getNamespace()
public String getNamespace()
Type | Description |
String |