V
- the type of the result values this query will producepublic final class GqlQuery<V> extends Query<V> implements RecordQuery<V>
When the type of the results is known the preferred usage would be:
Query<Entity> query =
Query.newGqlQueryBuilder(Query.ResultType.ENTITY, "select * from kind").build();
QueryResults<Entity> results = datastore.run(query);
while (results.hasNext()) {
Entity entity = results.next();
...
}
When the type of the results is unknown you can use this approach:
Query<?> query = Query.newGqlQueryBuilder("select __key__ from kind").build();
QueryResults<?> results = datastore.run(query);
if (Key.class.isAssignableFrom(results.getResultClass())) {
QueryResults<Key> keys = (QueryResults<Key>) results;
while (keys.hasNext()) {
Key key = keys.next();
...
}
}
Modifier and Type | Class and Description |
---|---|
static class |
GqlQuery.Builder<V>
A GQL query builder.
|
Query.ResultType<V>
Modifier and Type | Method and Description |
---|---|
boolean |
allowLiteral()
Returns whether the query string can contain literals.
|
boolean |
equals(Object obj) |
Map<String,Object> |
getNamedBindings()
Returns an immutable map of named bindings.
|
Map<String,com.google.cloud.datastore.GqlQuery.Binding> |
getNamedBindingsMap() |
List<Object> |
getNumberArgs()
Returns an immutable list of positional bindings (using original order).
|
List<com.google.cloud.datastore.GqlQuery.Binding> |
getPositionalBindingsMap() |
String |
getQueryString()
Returns the query string for this query.
|
Query.ResultType<V> |
getType() |
int |
hashCode() |
RecordQuery<V> |
nextQuery(RunQueryResponse responsePb) |
void |
populatePb(RunQueryRequest.Builder requestPb) |
String |
toString() |
getNamespace, newAggregationQueryBuilder, newEntityQueryBuilder, newGqlQueryBuilder, newGqlQueryBuilder, newKeyQueryBuilder, newProjectionEntityQueryBuilder
public String getQueryString()
public boolean allowLiteral()
false
, the query string
must not contain any literals and instead must bind all values.public Map<String,Object> getNamedBindings()
@InternalApi public Map<String,com.google.cloud.datastore.GqlQuery.Binding> getNamedBindingsMap()
@InternalApi public List<com.google.cloud.datastore.GqlQuery.Binding> getPositionalBindingsMap()
public List<Object> getNumberArgs()
public Query.ResultType<V> getType()
getType
in interface RecordQuery<V>
@InternalApi public void populatePb(RunQueryRequest.Builder requestPb)
populatePb
in interface RecordQuery<V>
@InternalApi public RecordQuery<V> nextQuery(RunQueryResponse responsePb)
nextQuery
in interface RecordQuery<V>
Copyright © 2023 Google LLC. All rights reserved.