当前位置: 首页>>代码示例>>Java>>正文


Java ResultType类代码示例

本文整理汇总了Java中com.google.cloud.datastore.Query.ResultType的典型用法代码示例。如果您正苦于以下问题:Java ResultType类的具体用法?Java ResultType怎么用?Java ResultType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ResultType类属于com.google.cloud.datastore.Query包,在下文中一共展示了ResultType类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getKinds

import com.google.cloud.datastore.Query.ResultType; //导入依赖的package包/类
@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);
  }
}
 
开发者ID:sai-pullabhotla,项目名称:catatumbo,代码行数:23,代码来源:DefaultDatastoreMetadata.java

示例2: executeKeyQueryRequest

import com.google.cloud.datastore.Query.ResultType; //导入依赖的package包/类
/**
 * Executes the given {@link KeyQueryRequest} and returns the response.
 * 
 * @param request
 *          the key query request
 * @return the query response
 */
public QueryResponse<DatastoreKey> executeKeyQueryRequest(KeyQueryRequest request) {
  try {
    GqlQuery.Builder<Key> queryBuilder = Query.newGqlQueryBuilder(ResultType.KEY,
        request.getQuery());
    queryBuilder.setNamespace(entityManager.getEffectiveNamespace());
    queryBuilder.setAllowLiteral(request.isAllowLiterals());
    QueryUtils.applyNamedBindings(queryBuilder, request.getNamedBindings());
    QueryUtils.applyPositionalBindings(queryBuilder, request.getPositionalBindings());
    GqlQuery<Key> gqlQuery = queryBuilder.build();
    QueryResults<Key> results = nativeReader.run(gqlQuery);
    List<DatastoreKey> entities = new ArrayList<>();
    DefaultQueryResponse<DatastoreKey> response = new DefaultQueryResponse<>();
    response.setStartCursor(new DefaultDatastoreCursor(results.getCursorAfter().toUrlSafe()));
    while (results.hasNext()) {
      Key result = results.next();
      DatastoreKey datastoreKey = new DefaultDatastoreKey(result);
      entities.add(datastoreKey);
    }
    response.setResults(entities);
    response.setEndCursor(new DefaultDatastoreCursor(results.getCursorAfter().toUrlSafe()));
    return response;
  } catch (DatastoreException exp) {
    throw new EntityManagerException(exp);
  }
}
 
开发者ID:sai-pullabhotla,项目名称:catatumbo,代码行数:33,代码来源:DefaultDatastoreReader.java

示例3: getNamespaces

import com.google.cloud.datastore.Query.ResultType; //导入依赖的package包/类
@Override
public QueryResponse<String> getNamespaces(DatastoreCursor fromCursor, int limit) {
  try {
    String query = "SELECT __key__ FROM " + ENTITY_NAMESPACES + " ORDER BY __key__";
    if (limit > 0) {
      query += " LIMIT @Limit";
    }
    query += " OFFSET @Offset";
    GqlQuery.Builder<Key> gqlQueryBuilder = Query.newGqlQueryBuilder(ResultType.KEY, query);
    if (limit > 0) {
      gqlQueryBuilder.setBinding("Limit", limit);
    }
    gqlQueryBuilder.setBinding("Offset", Cursor.fromUrlSafe(fromCursor.getEncoded()));
    GqlQuery<Key> gqlQuery = gqlQueryBuilder.build();
    Datastore datastore = entityManager.getDatastore();
    QueryResults<Key> results = datastore.run(gqlQuery);
    DefaultQueryResponse<String> response = new DefaultQueryResponse<>();
    List<String> namespaces = new ArrayList<>(Math.max(limit, 50));
    response.setStartCursor(new DefaultDatastoreCursor(results.getCursorAfter().toUrlSafe()));
    while (results.hasNext()) {
      Key key = results.next();
      String name = key.getName();
      namespaces.add(name == null ? "" : name);
    }
    response.setResults(namespaces);
    response.setEndCursor(new DefaultDatastoreCursor(results.getCursorAfter().toUrlSafe()));
    return response;
  } catch (DatastoreException exp) {
    throw new EntityManagerException(exp);
  }
}
 
开发者ID:sai-pullabhotla,项目名称:catatumbo,代码行数:32,代码来源:DefaultDatastoreMetadata.java

示例4: executeEntityQueryRequest

import com.google.cloud.datastore.Query.ResultType; //导入依赖的package包/类
/**
 * Executes the given {@link EntityQueryRequest} and returns the response.
 * 
 * @param expectedResultType
 *          the expected type of results.
 * @param request
 *          the entity query request
 * @return the query response
 */
public <E> QueryResponse<E> executeEntityQueryRequest(Class<E> expectedResultType,
    EntityQueryRequest request) {
  try {
    GqlQuery.Builder<Entity> queryBuilder = Query.newGqlQueryBuilder(ResultType.ENTITY,
        request.getQuery());
    queryBuilder.setNamespace(entityManager.getEffectiveNamespace());
    queryBuilder.setAllowLiteral(request.isAllowLiterals());
    QueryUtils.applyNamedBindings(queryBuilder, request.getNamedBindings());
    QueryUtils.applyPositionalBindings(queryBuilder, request.getPositionalBindings());
    GqlQuery<Entity> gqlQuery = queryBuilder.build();
    QueryResults<Entity> results = nativeReader.run(gqlQuery);
    List<E> entities = new ArrayList<>();
    DefaultQueryResponse<E> response = new DefaultQueryResponse<>();
    response.setStartCursor(new DefaultDatastoreCursor(results.getCursorAfter().toUrlSafe()));
    while (results.hasNext()) {
      Entity result = results.next();
      E entity = Unmarshaller.unmarshal(result, expectedResultType);
      entities.add(entity);
    }
    response.setResults(entities);
    response.setEndCursor(new DefaultDatastoreCursor(results.getCursorAfter().toUrlSafe()));
    entityManager.executeEntityListeners(CallbackType.POST_LOAD, entities);
    return response;
  } catch (DatastoreException exp) {
    throw new EntityManagerException(exp);
  }
}
 
开发者ID:sai-pullabhotla,项目名称:catatumbo,代码行数:37,代码来源:DefaultDatastoreReader.java

示例5: executeProjectionQueryRequest

import com.google.cloud.datastore.Query.ResultType; //导入依赖的package包/类
/**
 * Executes the given {@link ProjectionQueryRequest} and returns the response.
 * 
 * @param expectedResultType
 *          the expected type of results.
 * @param request
 *          the projection query request
 * @return the query response
 */
public <E> QueryResponse<E> executeProjectionQueryRequest(Class<E> expectedResultType,
    ProjectionQueryRequest request) {
  try {
    GqlQuery.Builder<ProjectionEntity> queryBuilder = Query
        .newGqlQueryBuilder(ResultType.PROJECTION_ENTITY, request.getQuery());
    queryBuilder.setNamespace(entityManager.getEffectiveNamespace());
    queryBuilder.setAllowLiteral(request.isAllowLiterals());
    QueryUtils.applyNamedBindings(queryBuilder, request.getNamedBindings());
    QueryUtils.applyPositionalBindings(queryBuilder, request.getPositionalBindings());
    GqlQuery<ProjectionEntity> gqlQuery = queryBuilder.build();
    QueryResults<ProjectionEntity> results = nativeReader.run(gqlQuery);
    List<E> entities = new ArrayList<>();
    DefaultQueryResponse<E> response = new DefaultQueryResponse<>();
    response.setStartCursor(new DefaultDatastoreCursor(results.getCursorAfter().toUrlSafe()));
    while (results.hasNext()) {
      ProjectionEntity result = results.next();
      E entity = Unmarshaller.unmarshal(result, expectedResultType);
      entities.add(entity);
    }
    response.setResults(entities);
    response.setEndCursor(new DefaultDatastoreCursor(results.getCursorAfter().toUrlSafe()));
    // TODO should we invoke PostLoad callback for projected entities?
    return response;
  } catch (DatastoreException exp) {
    throw new EntityManagerException(exp);
  }
}
 
开发者ID:sai-pullabhotla,项目名称:catatumbo,代码行数:37,代码来源:DefaultDatastoreReader.java

示例6: testGqlRunQuery

import com.google.cloud.datastore.Query.ResultType; //导入依赖的package包/类
@Test
public void testGqlRunQuery() {
  setUpQueryTests();
  // [START gql_run_query]
  Query<Entity> query = Query.newGqlQueryBuilder(
      ResultType.ENTITY, "select * from Task order by created asc").build();
  // [END gql_run_query]
  assertValidQuery(query);
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:10,代码来源:ConceptsTest.java

示例7: testGqlNamedBindingQuery

import com.google.cloud.datastore.Query.ResultType; //导入依赖的package包/类
@Test
public void testGqlNamedBindingQuery() {
  setUpQueryTests();
  // [START gql_named_binding_query]
  Query<Entity> query =
      Query.newGqlQueryBuilder(
          ResultType.ENTITY,
          "select * from Task where completed = @completed and priority = @priority")
      .setBinding("completed", false)
      .setBinding("priority", 4)
      .build();
  // [END gql_named_binding_query]
  assertValidQuery(query);
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:15,代码来源:ConceptsTest.java

示例8: testGqlPositionalBindingQuery

import com.google.cloud.datastore.Query.ResultType; //导入依赖的package包/类
@Test
public void testGqlPositionalBindingQuery() {
  setUpQueryTests();
  // [START gql_positional_binding_query]
  Query<Entity> query = Query.newGqlQueryBuilder(
        ResultType.ENTITY, "select * from Task where completed = @1 and priority = @2")
      .addBinding(false)
      .addBinding(4)
      .build();
  // [END gql_positional_binding_query]
  assertValidQuery(query);
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:13,代码来源:ConceptsTest.java

示例9: testGqlLiteralQuery

import com.google.cloud.datastore.Query.ResultType; //导入依赖的package包/类
@Test
public void testGqlLiteralQuery() {
  setUpQueryTests();
  // [START gql_literal_query]
  Query<Entity> query = Query.newGqlQueryBuilder(
          ResultType.ENTITY, "select * from Task where completed = false and priority = 4")
      .setAllowLiteral(true)
      .build();
  // [END gql_literal_query]
  assertValidQuery(query);
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:12,代码来源:ConceptsTest.java


注:本文中的com.google.cloud.datastore.Query.ResultType类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。