本文整理了Java中com.google.cloud.datastore.Query.newEntityQueryBuilder
方法的一些代码示例,展示了Query.newEntityQueryBuilder
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.newEntityQueryBuilder
方法的具体详情如下:
包路径:com.google.cloud.datastore.Query
类名称:Query
方法名:newEntityQueryBuilder
[英]Returns a new StructuredQuery builder for full (complete entities) queries.
Example of creating and running an entity query.
String kind = "my_kind";
[中]返回用于完整(完整实体)查询的新StructuredQuery builder。
创建和运行实体查询的示例。
String kind = "my_kind";
代码示例来源:origin: googleapis/google-cloud-java
/** Example of creating and running an entity query. */
// [TARGET newEntityQueryBuilder()]
// [VARIABLE "my_kind"]
public QueryResults<Entity> newEntityQuery(String kind) {
// [START newEntityQuery]
Query<Entity> query = Query.newEntityQueryBuilder().setKind(kind).build();
QueryResults<Entity> results = datastore.run(query);
// Use results
// [END newEntityQuery]
return results;
}
代码示例来源:origin: googleapis/google-cloud-java
/** Example of running a query to find all entities of one kind. */
// [TARGET run(Query, ReadOption...)]
// [VARIABLE "my_kind"]
public List<Entity> runQuery(String kind) {
// TODO change so that it's not necessary to hold the entities in a list for integration testing
// [START runQuery]
StructuredQuery<Entity> query = Query.newEntityQueryBuilder().setKind(kind).build();
QueryResults<Entity> results = datastore.run(query);
List<Entity> entities = Lists.newArrayList();
while (results.hasNext()) {
Entity result = results.next();
// do something with result
entities.add(result);
}
// [END runQuery]
return entities;
}
代码示例来源:origin: googleapis/google-cloud-java
/** Example of running a query to find all entities with a matching property value. */
// [TARGET run(Query, ReadOption...)]
// [VARIABLE "my_kind"]
// [VARIABLE "my_property"]
// [VARIABLE "my_value"]
public List<Entity> runQueryOnProperty(String kind, String property, String value) {
// TODO change so that it's not necessary to hold the entities in a list for integration testing
// [START runQueryOnProperty]
StructuredQuery<Entity> query =
Query.newEntityQueryBuilder()
.setKind(kind)
.setFilter(PropertyFilter.eq(property, value))
.build();
QueryResults<Entity> results = datastore.run(query);
List<Entity> entities = Lists.newArrayList();
while (results.hasNext()) {
Entity result = results.next();
// do something with result
entities.add(result);
}
// [END runQueryOnProperty]
return entities;
}
}
代码示例来源:origin: googleapis/google-cloud-java
Map<Timestamp, String> sortedComments = new TreeMap<>();
StructuredQuery<Entity> query =
Query.newEntityQueryBuilder()
.setNamespace(NAMESPACE)
.setKind(COMMENT_KIND)
代码示例来源:origin: googleapis/google-cloud-java
/** Example of running a query to find all entities with an ancestor. */
// [TARGET run(Query)]
// [VARIABLE "my_parent_key_name"]
public List<Entity> run(String parentKeyName) {
Datastore datastore = transaction.getDatastore();
// [START run]
KeyFactory keyFactory = datastore.newKeyFactory().setKind("ParentKind");
Key parentKey = keyFactory.newKey(parentKeyName);
// Build a query
Query<Entity> query =
Query.newEntityQueryBuilder()
.setKind("MyKind")
.setFilter(PropertyFilter.hasAncestor(parentKey))
.build();
QueryResults<Entity> results = transaction.run(query);
List<Entity> entities = Lists.newArrayList();
while (results.hasNext()) {
Entity result = results.next();
// do something with result
entities.add(result);
}
transaction.commit();
// [END run]
return entities;
}
代码示例来源:origin: googleapis/google-cloud-java
int totalCount = 0;
Iterator<ByteString> cursorIter = endCursors.iterator();
StructuredQuery<Entity> query = Query.newEntityQueryBuilder().setLimit(limit).build();
while (true) {
QueryResults<Entity> results = datastore.run(query);
代码示例来源:origin: googleapis/google-cloud-java
Query.newGqlQueryBuilder("select * from " + KIND1).setNamespace(NAMESPACE).build();
Query<Entity> scQuery1 =
Query.newEntityQueryBuilder()
.setNamespace(NAMESPACE)
.setKind(KIND1)
Query.newEntityQueryBuilder()
.setNamespace(NAMESPACE)
.setKind(KIND1)
代码示例来源:origin: googleapis/google-cloud-java
.build();
Query<Entity> scQuery1 =
Query.newEntityQueryBuilder()
.setNamespace(NAMESPACE)
.setKind(KIND1)
.build();
Query<? extends Entity> scQuery2 =
Query.newEntityQueryBuilder()
.setNamespace(NAMESPACE)
.setKind(KIND2)
.build();
scQuery1 =
Query.newEntityQueryBuilder()
.setNamespace(NAMESPACE)
.setFilter(PropertyFilter.hasAncestor(ROOT_KEY))
代码示例来源:origin: googleapis/google-cloud-java
DatastoreRpc datastoreRpc = datastore.getOptions().getDatastoreRpcV1();
List<RunQueryResponse> responses = new ArrayList<>();
Query<Entity> query = Query.newEntityQueryBuilder().build();
RunQueryRequest.Builder requestPb = RunQueryRequest.newBuilder();
query.populatePb(requestPb);
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void testRunStructuredQuery() throws InterruptedException {
Query<Entity> query =
Query.newEntityQueryBuilder().setKind(KIND1).setOrderBy(OrderBy.asc("__key__")).build();
Query.newEntityQueryBuilder()
.setKind(KIND1)
.setFilter(PropertyFilter.hasAncestor(ROOT_KEY))
代码示例来源:origin: googleapis/google-cloud-java
Query.newEntityQueryBuilder()
.setKind("Person")
.setFilter(PropertyFilter.eq("favorite_food", "pizza"))
代码示例来源:origin: GoogleCloudPlatform/java-docs-samples
/**
* Returns a list of all task entities in ascending order of creation time.
*
* @throws DatastoreException if the query fails
*/
Iterator<Entity> listTasks() {
Query<Entity> query =
Query.newEntityQueryBuilder().setKind("Task").setOrderBy(OrderBy.asc("created")).build();
return datastore.run(query);
}
// [END datastore_retrieve_entities]
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void testTransactionWithQuery() {
Query<Entity> query =
Query.newEntityQueryBuilder()
.setKind(KIND2)
.setFilter(PropertyFilter.hasAncestor(KEY2))
.build();
Transaction transaction = datastore.newTransaction();
QueryResults<Entity> results = transaction.run(query);
assertEquals(ENTITY2, results.next());
assertFalse(results.hasNext());
transaction.add(ENTITY3);
transaction.commit();
assertEquals(ENTITY3, datastore.get(KEY3));
transaction = datastore.newTransaction();
results = transaction.run(query);
assertEquals(ENTITY2, results.next());
transaction.delete(ENTITY3.getKey());
// update entity2 during the transaction
datastore.put(Entity.newBuilder(ENTITY2).clear().build());
try {
transaction.commit();
fail("Expecting a failure");
} catch (DatastoreException expected) {
assertEquals("ABORTED", expected.getReason());
}
}
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void testTransactionWithQuery() throws InterruptedException {
Query<Entity> query =
Query.newEntityQueryBuilder()
.setKind(KIND2)
.setFilter(PropertyFilter.hasAncestor(KEY2))
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void testRunStructuredQuery() {
Query<Entity> query =
Query.newEntityQueryBuilder().setKind(KIND1).setOrderBy(OrderBy.asc("__key__")).build();
QueryResults<Entity> results1 = datastore.run(query);
assertTrue(results1.hasNext());
代码示例来源:origin: spotify/styx
List<Resource> getResources() throws IOException {
final EntityQuery query = Query.newEntityQueryBuilder().setKind(KIND_COUNTER_LIMIT).build();
final List<Resource> resources = Lists.newArrayList();
datastore.query(query, entity ->
resources.add(entityToResource(entity)));
return resources;
}
代码示例来源:origin: spotify/styx
public Map<WorkflowInstance, RunState> activeStatesByTriggerId(
String triggerId) throws IOException {
final EntityQuery query =
Query.newEntityQueryBuilder().setKind(KIND_ACTIVE_WORKFLOW_INSTANCE)
.setFilter(PropertyFilter.eq(PROPERTY_STATE_TRIGGER_ID, triggerId))
.build();
return queryActiveStates(query);
}
代码示例来源:origin: spotify/styx
Map<WorkflowInstance, RunState> readActiveStates(String componentId) throws IOException {
final EntityQuery query =
Query.newEntityQueryBuilder().setKind(KIND_ACTIVE_WORKFLOW_INSTANCE)
.setFilter(PropertyFilter.eq(PROPERTY_COMPONENT, componentId))
.build();
return queryActiveStates(query);
}
代码示例来源:origin: org.springframework.cloud/spring-cloud-gcp-data-datastore
@Override
public <T> Collection<T> findAll(Class<T> entityClass, DatastoreQueryOptions queryOptions) {
DatastorePersistentEntity<?> persistentEntity = this.datastoreMappingContext.getPersistentEntity(entityClass);
EntityQuery.Builder builder = Query.newEntityQueryBuilder()
.setKind(persistentEntity.kindName());
applyQueryOptions(builder, queryOptions, persistentEntity);
return convertEntitiesForRead(getDatastoreReadWriter().run(builder.build()), entityClass);
}
代码示例来源:origin: spring-cloud/spring-cloud-gcp
@Override
public <T> Collection<T> findAll(Class<T> entityClass, DatastoreQueryOptions queryOptions) {
DatastorePersistentEntity<?> persistentEntity = this.datastoreMappingContext.getPersistentEntity(entityClass);
EntityQuery.Builder builder = Query.newEntityQueryBuilder()
.setKind(persistentEntity.kindName());
applyQueryOptions(builder, queryOptions, persistentEntity);
return convertEntitiesForRead(getDatastoreReadWriter().run(builder.build()), entityClass);
}
内容来源于网络,如有侵权,请联系作者删除!