本文整理了Java中com.google.cloud.datastore.Query.newGqlQueryBuilder
方法的一些代码示例,展示了Query.newGqlQueryBuilder
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.newGqlQueryBuilder
方法的具体详情如下:
包路径:com.google.cloud.datastore.Query
类名称:Query
方法名:newGqlQueryBuilder
[英]Returns a new GqlQuery builder.
Example of creating and running a typed GQL query.
String kind = "my_kind";
[中]返回一个新的GqlQuery生成器。
创建和运行类型化GQL查询的示例。
String kind = "my_kind";
代码示例来源:origin: googleapis/google-cloud-java
/**
* Returns a new {@link GqlQuery} builder.
*
* <p>Example of creating and running a GQL query.
*
* <pre>{@code
* String kind = "my_kind";
* String gqlQuery = "select * from " + kind;
* Query<?> query = Query.newGqlQueryBuilder(gqlQuery).build();
* QueryResults<?> results = datastore.run(query);
* // Use results
* }</pre>
*
* @see <a href="https://cloud.google.com/datastore/docs/apis/gql/gql_reference">GQL Reference</a>
*/
public static GqlQuery.Builder<?> newGqlQueryBuilder(String gql) {
return newGqlQueryBuilder(ResultType.UNKNOWN, gql);
}
代码示例来源:origin: googleapis/google-cloud-java
/** Example of creating and running a GQL query. */
// [TARGET newGqlQueryBuilder(String)]
// [VARIABLE "my_kind"]
public QueryResults<?> newQuery(String kind) {
// [START newQuery]
String gqlQuery = "select * from " + kind;
Query<?> query = Query.newGqlQueryBuilder(gqlQuery).build();
QueryResults<?> results = datastore.run(query);
// Use results
// [END newQuery]
return results;
}
代码示例来源:origin: googleapis/google-cloud-java
/** Example of creating and running a typed GQL query. */
// [TARGET newGqlQueryBuilder(ResultType, String)]
// [VARIABLE "my_kind"]
public QueryResults<Entity> newTypedQuery(String kind) {
// [START newTypedQuery]
String gqlQuery = "select * from " + kind;
Query<Entity> query = Query.newGqlQueryBuilder(Query.ResultType.ENTITY, gqlQuery).build();
QueryResults<Entity> results = datastore.run(query);
// Use results
// [END newTypedQuery]
return results;
}
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void testGqlQueryPagination() 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 mockDatastore = rpcMockOptions.getService();
QueryResults<Key> results =
mockDatastore.run(
Query.newGqlQueryBuilder(ResultType.KEY, "select __key__ from *").build());
int count = 0;
while (results.hasNext()) {
count += 1;
results.next();
}
assertEquals(count, 5);
EasyMock.verify(rpcFactoryMock, rpcMock);
}
代码示例来源:origin: googleapis/google-cloud-java
Query<Entity> query1 =
(Query<Entity>)
Query.newGqlQueryBuilder("select * from " + KIND1).setNamespace(NAMESPACE).build();
Query<Entity> scQuery1 =
Query.newEntityQueryBuilder()
Query.newGqlQueryBuilder("select * from " + KIND1).setNamespace(NAMESPACE).build();
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void testEventualConsistencyQuery() {
ReadOptions readOption =
ReadOptions.newBuilder().setReadConsistencyValue(ReadConsistency.EVENTUAL_VALUE).build();
com.google.datastore.v1.GqlQuery query =
com.google.datastore.v1.GqlQuery.newBuilder().setQueryString("FROM * SELECT *").build();
RunQueryRequest.Builder expectedRequest =
RunQueryRequest.newBuilder()
.setReadOptions(readOption)
.setGqlQuery(query)
.setPartitionId(PartitionId.newBuilder().setProjectId(PROJECT_ID).build());
EasyMock.expect(rpcMock.runQuery(expectedRequest.build()))
.andReturn(RunQueryResponse.newBuilder().build());
EasyMock.replay(rpcFactoryMock, rpcMock);
Datastore datastore = rpcMockOptions.getService();
datastore.run(
Query.newGqlQueryBuilder("FROM * SELECT *").build(), ReadOption.eventualConsistency());
EasyMock.verify(rpcFactoryMock, rpcMock);
}
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void testRunGqlQueryWithCasting() {
@SuppressWarnings("unchecked")
Query<Entity> query1 =
(Query<Entity>) Query.newGqlQueryBuilder("select * from " + KIND1).build();
QueryResults<Entity> results1 = datastore.run(query1);
assertTrue(results1.hasNext());
assertEquals(ENTITY1, results1.next());
assertFalse(results1.hasNext());
Query<?> query2 = Query.newGqlQueryBuilder("select * from " + KIND1).build();
QueryResults<?> results2 = datastore.run(query2);
assertSame(Entity.class, results2.getResultClass());
@SuppressWarnings("unchecked")
QueryResults<Entity> results3 = (QueryResults<Entity>) results2;
assertTrue(results3.hasNext());
assertEquals(ENTITY1, results3.next());
assertFalse(results3.hasNext());
}
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void testRunGqlQueryNoCasting() throws InterruptedException {
Query<Entity> query1 =
Query.newGqlQueryBuilder(ResultType.ENTITY, "select * from " + KIND1)
.setNamespace(NAMESPACE)
.build();
Query.newGqlQueryBuilder(ResultType.ENTITY, "select * from " + KIND2 + " order by __key__")
.setNamespace(NAMESPACE)
.build();
Query.newGqlQueryBuilder(ResultType.ENTITY, "select * from bla")
.setNamespace(NAMESPACE)
.build();
Query.newGqlQueryBuilder(ResultType.KEY, "select __key__ from " + KIND1)
.setNamespace(NAMESPACE)
.build();
Query.newGqlQueryBuilder(ResultType.PROJECTION_ENTITY, "select __key__ from " + KIND1)
.setNamespace(NAMESPACE)
.build();
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void testRunGqlQueryNoCasting() {
Query<Entity> query1 =
Query.newGqlQueryBuilder(ResultType.ENTITY, "select * from " + KIND1).build();
QueryResults<Entity> results1 = datastore.run(query1);
assertTrue(results1.hasNext());
Query.newGqlQueryBuilder(ResultType.ENTITY, "select * from " + KIND2 + " order by __key__")
.build();
QueryResults<? extends Entity> results2 = datastore.run(query2);
assertFalse(results2.hasNext());
query1 = Query.newGqlQueryBuilder(ResultType.ENTITY, "select * from bla").build();
results1 = datastore.run(query1);
assertFalse(results1.hasNext());
Query.newGqlQueryBuilder(ResultType.KEY, "select __key__ from " + KIND1).build();
QueryResults<Key> keyOnlyResults = datastore.run(keyOnlyQuery);
assertTrue(keyOnlyResults.hasNext());
Query.newGqlQueryBuilder(ResultType.PROJECTION_ENTITY, "select __key__ from " + KIND1)
.build();
QueryResults<ProjectionEntity> keyProjectionResult = datastore.run(keyProjectionQuery);
Query.newGqlQueryBuilder(ResultType.PROJECTION_ENTITY, "select str, date from " + KIND1)
.build();
代码示例来源:origin: GoogleCloudPlatform/java-docs-samples
/**
* Return a list of all users.
*/
public List<User> getAllUsers() {
Query<Entity> query =
Query.newGqlQueryBuilder(Query.ResultType.ENTITY, "SELECT * FROM " + kind).build();
QueryResults<Entity> results = datastore.run(query);
List<User> users = new ArrayList<>();
while (results.hasNext()) {
Entity result = results.next();
users.add(
new User(result.getString("id"), result.getString("name"), result.getString("email")));
}
return users;
}
代码示例来源:origin: com.google.cloud/google-cloud-datastore
/**
* Returns a new {@link GqlQuery} builder.
*
* <p>Example of creating and running a GQL query.
*
* <pre>{@code
* String kind = "my_kind";
* String gqlQuery = "select * from " + kind;
* Query<?> query = Query.newGqlQueryBuilder(gqlQuery).build();
* QueryResults<?> results = datastore.run(query);
* // Use results
* }</pre>
*
* @see <a href="https://cloud.google.com/datastore/docs/apis/gql/gql_reference">GQL Reference</a>
*/
public static GqlQuery.Builder<?> newGqlQueryBuilder(String gql) {
return newGqlQueryBuilder(ResultType.UNKNOWN, gql);
}
代码示例来源:origin: sai-pullabhotla/catatumbo
@Override
public List<String> getKinds(boolean excludeSystemKinds) {
try {
String query = "SELECT __key__ FROM " + ENTITY_KINDS + " ORDER BY __key__";
GqlQuery.Builder<Key> gqlQueryBuilder = Query.newGqlQueryBuilder(ResultType.KEY, query);
gqlQueryBuilder.setNamespace(entityManager.getEffectiveNamespace());
GqlQuery<Key> gqlQuery = gqlQueryBuilder.build();
QueryResults<Key> results = entityManager.getDatastore().run(gqlQuery);
List<String> kinds = new ArrayList<>(50);
while (results.hasNext()) {
Key key = results.next();
String kind = key.getName();
if (excludeSystemKinds && kind.startsWith("__")) {
continue;
}
kinds.add(key.getName());
}
return kinds;
} catch (DatastoreException exp) {
throw new EntityManagerException(exp);
}
}
代码示例来源:origin: sai-pullabhotla/catatumbo
@Override
public long deleteAll(String kind) {
if (Utility.isNullOrEmpty(kind)) {
throw new IllegalArgumentException("kind cannot be null or blank");
}
String query = "SELECT __key__ FROM " + kind;
try {
GqlQuery<Key> gqlQuery = Query.newGqlQueryBuilder(Query.ResultType.KEY, query)
.setNamespace(getEffectiveNamespace()).build();
QueryResults<Key> keys = datastore.run(gqlQuery);
Key[] nativeKeys = new Key[DEFAULT_DELETE_ALL_BATCH_SIZE];
long deleteCount = 0;
int i = 0;
while (keys.hasNext()) {
nativeKeys[i++] = keys.next();
if (i % DEFAULT_DELETE_ALL_BATCH_SIZE == 0) {
datastore.delete(nativeKeys);
deleteCount += DEFAULT_DELETE_ALL_BATCH_SIZE;
i = 0;
}
}
if (i > 0) {
datastore.delete(Arrays.copyOfRange(nativeKeys, 0, i));
deleteCount += i;
}
return deleteCount;
} catch (DatastoreException exp) {
throw new EntityManagerException(exp);
}
}
代码示例来源:origin: io.konig/konig-data-app-common
private void configAuthenticationDetails(String username) throws ServletException {
MemcacheService cache = MemcacheServiceFactory.getMemcacheService();
DatastoreOptions options = DatastoreOptions.newBuilder().build();
Query<?> query = Query.newGqlQueryBuilder("Select passwordSha1 from UserAuthentication "
+ "where username = @username")
.setBinding("username", username)
.build();
Datastore datastore = options.getService();
QueryResults<?> results = datastore.run(query);
while (results.hasNext()) {
Entity currentEntity = (Entity) results.next();
cache.put(username, currentEntity.getString("passwordSha1"));
}
if(username != null) {
String cachePassword = (String)MemcacheServiceFactory.getMemcacheService().get(username);
if(cachePassword == null) {
throw new ServletException("Invalid User");
}
}
}
代码示例来源:origin: sai-pullabhotla/catatumbo
GqlQuery.Builder<Key> gqlQueryBuilder = Query.newGqlQueryBuilder(ResultType.KEY, query);
if (limit > 0) {
gqlQueryBuilder.setBinding("Limit", limit);
代码示例来源:origin: sai-pullabhotla/catatumbo
GqlQuery.Builder<Key> queryBuilder = Query.newGqlQueryBuilder(ResultType.KEY,
request.getQuery());
queryBuilder.setNamespace(entityManager.getEffectiveNamespace());
代码示例来源:origin: sai-pullabhotla/catatumbo
try {
GqlQuery.Builder<ProjectionEntity> queryBuilder = Query
.newGqlQueryBuilder(ResultType.PROJECTION_ENTITY, request.getQuery());
queryBuilder.setNamespace(entityManager.getEffectiveNamespace());
queryBuilder.setAllowLiteral(request.isAllowLiterals());
代码示例来源:origin: sai-pullabhotla/catatumbo
EntityQueryRequest request) {
try {
GqlQuery.Builder<Entity> queryBuilder = Query.newGqlQueryBuilder(ResultType.ENTITY,
request.getQuery());
queryBuilder.setNamespace(entityManager.getEffectiveNamespace());
内容来源于网络,如有侵权,请联系作者删除!