Package com.google.appengine.api.datastore

Examples of com.google.appengine.api.datastore.FetchOptions


              : SortDirection.DESCENDING);
        }
        long l0 = System.currentTimeMillis();

        PreparedQuery prepare = null;
        FetchOptions options = null;
        if (limit != -1) {
          options = FetchOptions.Builder.withLimit(limit)
              .prefetchSize(limit);
        }
        if (keysonly) {
          query.setKeysOnly();
        }

        prepare = DatastoreServiceFactory.getDatastoreService()
            .prepare(query);
        // System.out.println("EXTRACT Ents!!!!! count = "
        // + prepare.countEntities() + " isforStoring ="
        // + isForStoring);
        Iterator<Entity> results = (options == null ? prepare
            .asIterable() : prepare.asIterable(options)).iterator();

        int countEntities = prepare.countEntities();

        if (prepare.countEntities() < limit && orderBy != null
            && orderBy.length() > 0
            && !orderBy.equals(Entity.KEY_RESERVED_PROPERTY)) {
          Query qq = new Query(kind);
          if (query.getAncestor() != null) {
            qq.setAncestor(query.getAncestor());
          }
          List<FilterPredicate> fp = query.getFilterPredicates();
          for (FilterPredicate fpred : fp) {
            qq.addFilter(fpred.getPropertyName(),
                fpred.getOperator(), fpred.getValue());
          }

          Iterator<Entity> iter1 = results;

          FetchOptions newNo = null;
          if (limit > 0) {
            newNo = FetchOptions.Builder.withLimit(limit);
          }

          prepare = DatastoreServiceFactory.getDatastoreService()
View Full Code Here


      DatastoreService dss = DatastoreServiceFactory
          .getDatastoreService();

      Query q = new Query(kind);
      q.setKeysOnly();
      FetchOptions fo = insertParametersToQueue(q);
      PreparedQuery pq = dss.prepare(q);
      limit = fo.getLimit();

      if (pq.countEntities() > 0) {
        try {
          List<Entity> arr = pq.asList(fo);
          total = arr.size();
View Full Code Here

  public AbstractHandler(int id) {
    this.type = id;
  }

  protected FetchOptions insertParametersToQueue(Query q) {
    FetchOptions fo = null;
    // int limit = -1;

    q.addSort(Entity.KEY_RESERVED_PROPERTY);
    if (keyString != null) {
      Key kk = KeyFactory.stringToKey(keyString);
View Full Code Here

  @Override

  public void beginSlice() {
    Preconditions.checkState(iterator == null, "%s: Already initialized: %s", this, iterator);
    FetchOptions options = withChunkSize(BATCH_SIZE);
    if (cursor != null) {
      options.startCursor(cursor);
    }
    iterator = getDatastoreService().prepare(query).asQueryResultIterator(options);
  }
View Full Code Here

  @Override
  public ProcessData process(ProcessContext context, ProcessData input) {
    // step 1 : read data
    DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
    FetchOptions fetchOptions = FetchOptions.Builder.withLimit(this.batchSize);
    if (!isNullOrEmpty(this.startCursor)) {
            fetchOptions.startCursor(Cursor.fromWebSafeString(this.startCursor));
        }
   
    // step 2 : convert data into evaluation result
    QueryResultList<Entity> entities = datastore.prepare(new Query(kind)).asQueryResultList(fetchOptions);
    this.startCursor = entities.getCursor().toWebSafeString()// update context
View Full Code Here

    DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
   
    Query q = isNullOrEmpty(filter) ?
      new Query(kind) : new GqlQuery("select * from " + kind + " " + filter).query();
   
    FetchOptions options = FetchOptions.Builder.withLimit(length).offset(start);
   
    try {
      Iterable<Entity> entities = datastore.prepare(q).asIterable(options);
     
      List<EntityInfo> result = new LinkedList<EntityInfo>();
View Full Code Here

          qd.primaryDatastoreQuery.getSortPredicates().isEmpty()) {
        // only execute a batch get if there aren't any other
        // filters or sorts
        return fulfillBatchGetQuery(ds, qd, mconn);
      } else if (qd.joinQuery != null) {
        FetchOptions opts = buildFetchOptions(fromInclNo, toExclNo);
        JoinHelper joinHelper = new JoinHelper();
        return wrapEntityQueryResult(
            joinHelper.executeJoinQuery(qd, this, ds, opts),
            qd.resultTransformer, ds, mconn, null);
      } else {
        latestDatastoreQuery = qd.primaryDatastoreQuery;
        Transaction txn = null;
        Map extensions = query.getExtensions();
        // give users a chance to opt-out of having their query execute in a txn
        if (extensions == null ||
            !extensions.containsKey(DatastoreManager.EXCLUDE_QUERY_FROM_TXN) ||
            !(Boolean)extensions.get(DatastoreManager.EXCLUDE_QUERY_FROM_TXN)) {
          // If this is an ancestor query, execute it in the current transaction
          txn = qd.primaryDatastoreQuery.getAncestor() != null ? ds.getCurrentTransaction(null) : null;
        }
        PreparedQuery preparedQuery = ds.prepare(txn, qd.primaryDatastoreQuery);
        FetchOptions opts = buildFetchOptions(fromInclNo, toExclNo);
        if (qd.resultType == ResultType.COUNT) {
          return fulfillCountQuery(preparedQuery, opts);
        } else {
          if (qd.resultType == ResultType.KEYS_ONLY || isBulkDelete()) {
            qd.primaryDatastoreQuery.setKeysOnly();
View Full Code Here

   * Build a FetchOptions instance using the provided params.
   * @return A FetchOptions instance built using the provided params,
   * or {@code null} if neither param is set.
   */
  FetchOptions buildFetchOptions(long fromInclNo, long toExclNo) {
    FetchOptions opts = null;
    Integer offset = null;
    if (fromInclNo != 0 && rangeValueIsSet(fromInclNo)) {
      // datastore api expects an int because we cap you at 1000 anyway.
      offset = (int) Math.min(Integer.MAX_VALUE, fromInclNo);
      opts = withOffset(offset);
    }
    if (rangeValueIsSet(toExclNo)) {
      // datastore api expects an int because we cap you at 1000 anyway.
      int intExclNo = (int) Math.min(Integer.MAX_VALUE, toExclNo);
      if (opts == null) {
        // When fromInclNo isn't specified, intExclNo (the index of the last
        // result to return) and limit are the same.
        opts = withLimit(intExclNo);
      } else {
        // When we have values for both fromInclNo and toExclNo
        // we can't take toExclNo as the limit for the query because
        // toExclNo is the index of the last result, not the max
        // results to return.  In this scenario the limit is the
        // index of the last result minus the offset.  For example, if
        // fromInclNo is 10 and toExclNo is 25, the limit for the query
        // is 15 because we want 15 results starting after the first 10.

        // We know that offset won't be null because opts is not null.
        opts.limit(intExclNo - offset);
      }
    }
    Cursor cursor = getCursor();
    // If we have a cursor, add it to the fetch options
    if (cursor != null) {
      if (opts == null) {
        opts = withCursor(cursor);
      } else {
        opts.cursor(cursor);
      }
    }
    return opts;
  }
View Full Code Here

          qd.primaryDatastoreQuery.getSortPredicates().isEmpty()) {
        // only execute a batch get if there aren't any other
        // filters or sorts
        return fulfillBatchGetQuery(ds, qd, mconn);
      } else if (qd.joinQuery != null) {
        FetchOptions opts = buildFetchOptions(fromInclNo, toExclNo);
        JoinHelper joinHelper = new JoinHelper();
        return wrapEntityQueryResult(
            joinHelper.executeJoinQuery(qd, this, ds, opts),
            qd.resultTransformer, ds, mconn, null);
      } else {
        latestDatastoreQuery = qd.primaryDatastoreQuery;
        Transaction txn = null;
        // give users a chance to opt-out of having their query execute in a txn
        if (extensions == null ||
            !extensions.containsKey(DatastoreManager.EXCLUDE_QUERY_FROM_TXN) ||
            !(Boolean)extensions.get(DatastoreManager.EXCLUDE_QUERY_FROM_TXN)) {
          // If this is an ancestor query, execute it in the current transaction
          txn = qd.primaryDatastoreQuery.getAncestor() != null ? ds.getCurrentTransaction(null) : null;
        }
        PreparedQuery preparedQuery = ds.prepare(txn, qd.primaryDatastoreQuery);
        FetchOptions opts = buildFetchOptions(fromInclNo, toExclNo);
        if (qd.resultType == ResultType.COUNT) {
          return fulfillCountQuery(preparedQuery, opts);
        } else {
          if (qd.resultType == ResultType.KEYS_ONLY || isBulkDelete()) {
            qd.primaryDatastoreQuery.setKeysOnly();
View Full Code Here

   * Build a FetchOptions instance using the provided params.
   * @return A FetchOptions instance built using the provided params,
   * or {@code null} if neither param is set.
   */
  FetchOptions buildFetchOptions(long fromInclNo, long toExclNo) {
    FetchOptions opts = null;
    Integer offset = null;
    if (fromInclNo != 0 && rangeValueIsSet(fromInclNo)) {
      // datastore api expects an int because we cap you at 1000 anyway.
      offset = (int) Math.min(Integer.MAX_VALUE, fromInclNo);
      opts = withOffset(offset);
    }
    if (rangeValueIsSet(toExclNo)) {
      // datastore api expects an int because we cap you at 1000 anyway.
      int intExclNo = (int) Math.min(Integer.MAX_VALUE, toExclNo);
      if (opts == null) {
        // When fromInclNo isn't specified, intExclNo (the index of the last
        // result to return) and limit are the same.
        opts = withLimit(intExclNo);
      } else {
        // When we have values for both fromInclNo and toExclNo
        // we can't take toExclNo as the limit for the query because
        // toExclNo is the index of the last result, not the max
        // results to return.  In this scenario the limit is the
        // index of the last result minus the offset.  For example, if
        // fromInclNo is 10 and toExclNo is 25, the limit for the query
        // is 15 because we want 15 results starting after the first 10.

        // We know that offset won't be null because opts is not null.
        opts.limit(intExclNo - offset);
      }
    }
    Cursor cursor = getCursor();
    // If we have a cursor, add it to the fetch options
    if (cursor != null) {
      if (opts == null) {
        opts = withCursor(cursor);
      } else {
        opts.cursor(cursor);
      }
    }
    return opts;
  }
View Full Code Here

TOP

Related Classes of com.google.appengine.api.datastore.FetchOptions

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.