Package com.google.api.services.datastore.DatastoreV1

Examples of com.google.api.services.datastore.DatastoreV1.QueryResultBatch


  List<Key> insertAutoId(Entity... entities) throws DatastoreException {
    Mutation.Builder mutation = Mutation.newBuilder();
    for (Entity entity : entities) {
      mutation.addInsertAutoId(entity);
    }
    CommitRequest req = CommitRequest.newBuilder()
        .setMutation(mutation)
        .setMode(CommitRequest.Mode.NON_TRANSACTIONAL)
        .build();
    return datastore.commit(req).getMutationResult().getInsertAutoIdKeyList();
  }
View Full Code Here


    List<Filter> keyFilters = new ArrayList<Filter>();
    if (query.hasFilter()) {
      keyFilters.add(query.getFilter());
    }
    if (lastKey != null) {
      Filter lowerBound = DatastoreHelper.makeFilter(DatastoreHelper.KEY_PROPERTY_NAME,
          PropertyFilter.Operator.GREATER_THAN_OR_EQUAL,
          DatastoreHelper.makeValue(lastKey)).build();
      keyFilters.add(lowerBound);
    }
    if (nextKey != null) {
      Filter upperBound = DatastoreHelper.makeFilter(DatastoreHelper.KEY_PROPERTY_NAME,
          PropertyFilter.Operator.LESS_THAN,
          DatastoreHelper.makeValue(nextKey)).build();
      keyFilters.add(upperBound);
    }
    return Query.newBuilder(query).setFilter(makeFilter(keyFilters)).build();
View Full Code Here

    validateQuery(query);
    validateSplitSize(numSplits);

    List<Query> splits = new ArrayList<Query>(numSplits);
    List<Key> scatterKeys = getScatterKeys(numSplits, query, datastore);
    Key lastKey = null;
    for (Key nextKey : getSplitKey(scatterKeys, numSplits)) {
      splits.add(createSplit(lastKey, nextKey, query));
      lastKey = nextKey;
    }
    splits.add(createSplit(lastKey, null, query));
View Full Code Here

      throws DatastoreException {
    Query.Builder scatterPointQuery = createScatterQuery(query, numSplits);

    List<Key> keySplits = new ArrayList<Key>();

    QueryResultBatch batch;
    do {
      RunQueryRequest scatterRequest = RunQueryRequest.newBuilder()
          .setQuery(scatterPointQuery).build();
      batch = datastore.runQuery(scatterRequest).getBatch();
      for (EntityResult result : batch.getEntityResultList()) {
        keySplits.add(result.getEntity().getKey());
      }
      scatterPointQuery.setStartCursor(batch.getEndCursor());
      scatterPointQuery.setLimit(scatterPointQuery.getLimit() - batch.getEntityResultCount());
    } while (batch.getMoreResults() == MoreResultsType.NOT_FINISHED);
    Collections.sort(keySplits, DatastoreHelper.getKeyComparator());
    return keySplits;
  }
View Full Code Here

    List<Key> keySplits = new ArrayList<Key>();

    QueryResultBatch batch;
    do {
      RunQueryRequest scatterRequest = RunQueryRequest.newBuilder()
          .setQuery(scatterPointQuery).build();
      batch = datastore.runQuery(scatterRequest).getBatch();
      for (EntityResult result : batch.getEntityResultList()) {
        keySplits.add(result.getEntity().getKey());
      }
View Full Code Here

   * @throws DatastoreException on error
   */
  List<Entity> runQuery(Query query) throws DatastoreException {
    RunQueryRequest.Builder request = RunQueryRequest.newBuilder();
    request.setQuery(query);
    RunQueryResponse response = datastore.runQuery(request.build());

    if (response.getBatch().getMoreResults() == QueryResultBatch.MoreResultsType.NOT_FINISHED) {
      System.err.println("WARNING: partial results\n");
    }
    List<EntityResult> results = response.getBatch().getEntityResultList();
    List<Entity> entities = new ArrayList<Entity>(results.size());
    for (EntityResult result : results) {
      entities.add(result.getEntity());
    }
    return entities;
View Full Code Here

  @Override
  Future<RunQueryResponse> makeNextCall(RunQueryRequest prototype, WrappedQueryResult latestResult,Integer fetchCount,Integer offset) {
    RunQueryRequest.Builder runQueryRequest = prototype.toBuilder();
    DatastoreV4.Query.Builder query = runQueryRequest.getQueryBuilder();
    QueryResultBatch latestBatch = ((WrappedQueryResultV4) latestResult).getBatch();
    if (!latestBatch.hasEndCursor()) {
      throw new IllegalArgumentException();
    }
    query.setStartCursor(latestBatch.getEndCursor());
    if (query.hasLimit()) {
      remainingLimit -= latestBatch.getEntityResultCount();
      query.setLimit(Math.max(remainingLimit, 0));
    }
    if (offset != null) {
      query.setOffset(offset);
    } else {
View Full Code Here

TOP

Related Classes of com.google.api.services.datastore.DatastoreV1.QueryResultBatch

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.