本文整理了Java中com.google.cloud.datastore.Query.newKeyQueryBuilder
方法的一些代码示例,展示了Query.newKeyQueryBuilder
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.newKeyQueryBuilder
方法的具体详情如下:
包路径:com.google.cloud.datastore.Query
类名称:Query
方法名:newKeyQueryBuilder
[英]Returns a new StructuredQuery builder for key only queries.
Example of creating and running a key query.
String kind = "my_kind";
[中]为仅键查询返回新的StructuredQuery生成器。
创建和运行密钥查询的示例。
String kind = "my_kind";
代码示例来源:origin: googleapis/google-cloud-java
/** Example of creating and running a key query. */
// [TARGET newKeyQueryBuilder()]
// [VARIABLE "my_kind"]
public QueryResults<Key> newKeyQuery(String kind) {
// [START newKeyQuery]
Query<Key> query = Query.newKeyQueryBuilder().setKind(kind).build();
QueryResults<Key> results = datastore.run(query);
// Use results
// [END newKeyQuery]
return results;
}
代码示例来源:origin: googleapis/google-cloud-java
/** Deletes all entities in the namespace associated with this {@link RemoteDatastoreHelper}. */
public void deleteNamespace() {
StructuredQuery<Key> query = Query.newKeyQueryBuilder().setNamespace(namespace).build();
QueryResults<Key> keys = datastore.run(query);
while (keys.hasNext()) {
datastore.delete(keys.next());
}
}
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void testStructuredQueryPagination() throws DatastoreException {
List<RunQueryResponse> responses = buildResponsesForQueryPagination();
for (int i = 0; i < responses.size(); i++) {
EasyMock.expect(rpcMock.runQuery(EasyMock.anyObject(RunQueryRequest.class)))
.andReturn(responses.get(i));
}
EasyMock.replay(rpcFactoryMock, rpcMock);
Datastore datastore = rpcMockOptions.getService();
QueryResults<Key> results = datastore.run(Query.newKeyQueryBuilder().build());
int count = 0;
while (results.hasNext()) {
count += 1;
results.next();
}
assertEquals(count, 5);
EasyMock.verify(rpcFactoryMock, rpcMock);
}
代码示例来源:origin: googleapis/google-cloud-java
@Override
public void run(Transaction tx, Key userKey, Void arg) {
Entity user = tx.get(userKey);
if (user == null) {
System.out.println("Nothing to delete, user does not exist.");
return;
}
Query<Key> query =
Query.newKeyQueryBuilder()
.setNamespace(NAMESPACE)
.setKind(COMMENT_KIND)
.setFilter(PropertyFilter.hasAncestor(userKey))
.build();
QueryResults<Key> comments = tx.run(query);
int count = 0;
while (comments.hasNext()) {
tx.delete(comments.next());
count++;
}
tx.delete(userKey);
System.out.printf("Deleting user '%s' and %d comment[s].%n", userKey.getName(), count);
}
代码示例来源:origin: google/data-transfer-project
/**
* Finds the ID of the first {@link PortabilityJob} in state {@code jobState} in Datastore, or
* null if none found.
*
* <p>TODO(rtannenbaum): Order by creation time so we can process jobs in a FIFO manner. Trying
* to OrderBy.asc("created") currently fails because we don't yet have an index set up.
*/
@Override
public UUID findFirst(JobAuthorization.State jobState) {
Query<Key> query =
Query.newKeyQueryBuilder()
.setKind(KIND)
.setFilter(PropertyFilter.eq(PortabilityJob.AUTHORIZATION_STATE, jobState.name()))
// .setOrderBy(OrderBy.asc("created"))
.setLimit(1)
.build();
QueryResults<Key> results = datastore.run(query);
if (!results.hasNext()) {
return null;
}
Key key = results.next();
return UUID.fromString(key.getName());
}
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void testSkippedResults() {
Query<Key> query = Query.newKeyQueryBuilder().setOffset(Integer.MAX_VALUE).build();
int numberOfEntities = DATASTORE.run(query).getSkippedResults();
assertEquals(2, numberOfEntities);
}
}
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void testRunKeyQueryWithOffset() {
Query<Key> query = Query.newKeyQueryBuilder().setOffset(Integer.MAX_VALUE).build();
int numberOfEntities = datastore.run(query).getSkippedResults();
assertEquals(2, numberOfEntities);
}
代码示例来源:origin: googleapis/google-cloud-java
@Before
public void setUp() {
rpcFactoryMock = EasyMock.createStrictMock(DatastoreRpcFactory.class);
rpcMock = EasyMock.createStrictMock(DatastoreRpc.class);
rpcMockOptions =
options
.toBuilder()
.setRetrySettings(ServiceOptions.getDefaultRetrySettings())
.setServiceRpcFactory(rpcFactoryMock)
.build();
EasyMock.expect(rpcFactoryMock.create(rpcMockOptions)).andReturn(rpcMock);
StructuredQuery<Key> query = Query.newKeyQueryBuilder().build();
QueryResults<Key> result = datastore.run(query);
datastore.delete(Iterators.toArray(result, Key.class));
datastore.add(ENTITY1, ENTITY2);
}
代码示例来源:origin: googleapis/google-cloud-java
datastore.add(ENTITY3, entity4, entity5);
List<RunQueryResponse> responses = new ArrayList<>();
Query<Key> query = Query.newKeyQueryBuilder().build();
RunQueryRequest.Builder requestPb = RunQueryRequest.newBuilder();
query.populatePb(requestPb);
代码示例来源:origin: googleapis/google-cloud-java
.build();
Query<Key> scKeyOnlyQuery =
Query.newKeyQueryBuilder()
.setNamespace(NAMESPACE)
.setFilter(PropertyFilter.hasAncestor(ROOT_KEY))
代码示例来源:origin: googleapis/google-cloud-java
assertFalse(results1.hasNext());
Query<Key> keyOnlyQuery = Query.newKeyQueryBuilder().setKind(KIND1).build();
Query<Key> scKeyOnlyQuery =
Query.newKeyQueryBuilder()
.setKind(KIND1)
.setFilter(PropertyFilter.hasAncestor(ROOT_KEY))
代码示例来源:origin: googleapis/google-cloud-java
assertFalse(results1.hasNext());
Query<Key> keyOnlyQuery = Query.newKeyQueryBuilder().setKind(KIND1).build();
QueryResults<Key> results2 = datastore.run(keyOnlyQuery);
assertTrue(results2.hasNext());
代码示例来源:origin: spring-cloud/spring-cloud-gcp
private Key[] findAllKeys(Class entityClass) {
Iterable<Key> keysFound = queryKeys(Query.newKeyQueryBuilder().setKind(
this.datastoreMappingContext
.getPersistentEntity(entityClass).kindName())
.build());
return StreamSupport.stream(keysFound.spliterator(),
false).toArray(Key[]::new);
}
代码示例来源:origin: org.springframework.cloud/spring-cloud-gcp-data-datastore
private Key[] findAllKeys(Class entityClass) {
Iterable<Key> keysFound = queryKeys(Query.newKeyQueryBuilder().setKind(
this.datastoreMappingContext
.getPersistentEntity(entityClass).kindName())
.build());
return StreamSupport.stream(keysFound.spliterator(),
false).toArray(Key[]::new);
}
代码示例来源:origin: com.google.cloud/google-cloud-datastore
/** Deletes all entities in the namespace associated with this {@link RemoteDatastoreHelper}. */
public void deleteNamespace() {
StructuredQuery<Key> query = Query.newKeyQueryBuilder().setNamespace(namespace).build();
QueryResults<Key> keys = datastore.run(query);
while (keys.hasNext()) {
datastore.delete(keys.next());
}
}
代码示例来源:origin: org.eclipse.jetty.gcloud/jetty-gcloud-session-manager
Query<Key> q = Query.newKeyQueryBuilder()
.setKind(_model.getKind())
.setFilter(PropertyFilter.eq(_model.getId(), s))
代码示例来源:origin: spring-cloud/spring-cloud-gcp
this.datastoreMappingContext.getPersistentEntity(example.getProbeType());
StructuredQuery.Builder builder = keyQuery ? Query.newKeyQueryBuilder() : Query.newEntityQueryBuilder();
builder.setKind(persistentEntity.kindName());
内容来源于网络,如有侵权,请联系作者删除!