Package com.google.appengine.api.datastore

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


  private Future<QueryResultIterator<Entity>> futureSingleQueryEntities(Query query)
  {
      Transaction txn = this.datastore.getTransaction();
      Future<QueryResultIterator<Entity>> futureEntities;
      AsyncPreparedQuery prepared = new AsyncPreparedQuery(query, txn);
      FetchOptions fetchOptions = getRootCommand().getFetchOptions();
      if (fetchOptions == null)
      {
        futureEntities = prepared.asFutureQueryResultIterator();
      }
      else
View Full Code Here


    List<Iterator<Entity>> iterators = new ArrayList<Iterator<Entity>>(queries.size());
    for (Query query : queries)
    {
      PreparedQuery prepared = this.datastore.servicePrepare(query);
      Iterator<Entity> entities;
      FetchOptions fetchOptions = getRootCommand().getFetchOptions();
      if (fetchOptions == null)
      {
        entities = prepared.asIterator();
      }
      else
View Full Code Here

    Transaction txn = datastore.getTransaction();
    for (Query query : queries)
    {
      AsyncPreparedQuery prepared = new AsyncPreparedQuery(query, txn);
      Future<QueryResultIterator<Entity>> futureEntities;
      FetchOptions fetchOptions = getRootCommand().getFetchOptions();
      if (fetchOptions == null)
      {
        futureEntities = prepared.asFutureQueryResultIterator();
      }
      else
View Full Code Here

    return new BookIterable(datastoreService.prepare(new QueryConverter().convertQuery(jpqlQuery))
        .asIterable());
  }

  public Iterable<Book> asIterable(String jpqlQuery, int limit, int offset) {
    FetchOptions fo = withLimit(limit).offset(offset);
    return new BookIterable(datastoreService.prepare(new QueryConverter().convertQuery(jpqlQuery))
        .asIterable(fo));
  }
View Full Code Here

    if (qd.type == QueryType.BATCH_GET) {
      // BatchGet query
      return executeBatchGetQuery(ds, qd);
    } else if (qd.type == QueryType.JOIN) {
      // Join query
      FetchOptions opts = buildFetchOptions(query.getRangeFromIncl(), query.getRangeToExcl());
      if (NucleusLogger.DATASTORE_NATIVE.isDebugEnabled()) {
        NucleusLogger.DATASTORE_NATIVE.debug("Executing join query in datastore for " + query.toString());
      }
      if (getExecutionContext().getStatistics() != null) {
        getExecutionContext().getStatistics().incrementNumReads();
      }

      Iterable<Entity> entityIterable = new JoinHelper().executeJoinQuery(qd, this, ds, opts);

      return wrapEntityQueryResult(entityIterable, qd.resultTransformer, ds, null);
    } else {
      // Normal query
      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.QUERYEXT_EXCLUDE_FROM_TXN) ||
          !(Boolean)extensions.get(DatastoreManager.QUERYEXT_EXCLUDE_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(query.getRangeFromIncl(), query.getRangeToExcl());

      if (NucleusLogger.DATASTORE_NATIVE.isDebugEnabled()) {
        NucleusLogger.DATASTORE_NATIVE.debug("Executing query in datastore for " + query.toString());
      }
      if (getExecutionContext().getStatistics() != null) {
        getExecutionContext().getStatistics().incrementNumReads();
      }

      Iterable<Entity> entityIterable;
      Cursor endCursor = null;
      if (opts != null) {
        if (opts.getLimit() != null) {
          QueryResultList<Entity> entities = preparedQuery.asQueryResultList(opts);
          endCursor = entities.getCursor();
          entityIterable = entities;
        } else {
          entityIterable = preparedQuery.asQueryResultIterable(opts);
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 && fromInclNo != Long.MAX_VALUE) {
      // datastore api expects an int because we cap you at 1000 anyway.
      offset = (int) Math.min(Integer.MAX_VALUE, fromInclNo);
      opts = withOffset(offset);
    }

    if (toExclNo != Long.MAX_VALUE) {
      // 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);
      }
    }

    // users can provide the cursor as a Cursor or its String representation.
    // If we have a cursor, add it to the fetch options
    Cursor cursor = null;
    Object obj = query.getExtension(CursorHelper.QUERY_CURSOR_PROPERTY_NAME);
    if (obj != null) {
      if (obj instanceof Cursor) {
        cursor = (Cursor) obj;
      }
      else {
        cursor = Cursor.fromWebSafeString((String) obj);
      }
    }
    if (cursor != null) {
      if (opts == null) {
        opts = withStartCursor(cursor);
      } else {
        opts.startCursor(cursor);
      }
    }

    // Use the fetch size of the fetch plan to determine chunk size.
    FetchPlan fetchPlan = query.getFetchPlan();
    Integer fetchSize = fetchPlan.getFetchSize();
    if (fetchSize != FetchPlan.FETCH_SIZE_OPTIMAL) {
      if (fetchSize == FetchPlan.FETCH_SIZE_GREEDY) {
        fetchSize = Integer.MAX_VALUE;
      }
    } else {
      fetchSize = null;
    }
    if (fetchSize != null) {
      if (opts == null) {
        opts = withChunkSize(fetchSize);
      } else {
        opts.chunkSize(fetchSize);
      }
    }

    return opts;
  }
View Full Code Here

    }
  }

  private OverlayQueryResultIteratorImpl runQuery(FetchOptions fetchOptions) {
    checkNotNull(fetchOptions);
    FetchOptions overlayFetchOptions = cloneFetchOptionsPrefetchAndChunkSize(fetchOptions);
    FetchOptions parentFetchOptions = cloneFetchOptionsPrefetchAndChunkSize(fetchOptions);
    QueryResultIterator<Entity> overlayIterator =
        preparedOverlayQuery.asQueryResultIterator(overlayFetchOptions);
    QueryResultIterator<Entity> parentIterator =
        preparedParentQuery.asQueryResultIterator(parentFetchOptions);
    return new OverlayQueryResultIteratorImpl(overlayIterator, parentIterator, fetchOptions);
View Full Code Here

    return new OverlayQueryResultIteratorImpl(overlayIterator, parentIterator, fetchOptions);
  }

  private FetchOptions cloneFetchOptionsPrefetchAndChunkSize(FetchOptions fetchOptions) {
    checkNotNull(fetchOptions);
    FetchOptions clonedOptions = withDefaults();
    Integer prefetchSize = fetchOptions.getPrefetchSize();
    if (prefetchSize != null) {
      clonedOptions.prefetchSize(prefetchSize);
    }
    Integer chunkSize = fetchOptions.getChunkSize();
    if (chunkSize != null) {
      clonedOptions.chunkSize(chunkSize);
    }
    return clonedOptions;
  }
View Full Code Here

    return clonedOptions;
  }

  private FetchOptions cloneFetchOptions(FetchOptions fetchOptions) {
    checkNotNull(fetchOptions);
    FetchOptions clonedOptions = cloneFetchOptionsPrefetchAndChunkSize(fetchOptions);
    Cursor startCursor = fetchOptions.getStartCursor();
    if (startCursor != null) {
      clonedOptions.startCursor(startCursor);
    }
    Cursor endCursor = fetchOptions.getEndCursor();
    if (endCursor != null) {
      clonedOptions.endCursor(endCursor);
    }
    Integer limit = fetchOptions.getLimit();
    if (limit != null) {
      clonedOptions.limit(limit);
    }
    Integer offset = fetchOptions.getOffset();
    if (offset != null) {
      clonedOptions.offset(offset);
    }
    return clonedOptions;
  }
View Full Code Here

    interpreteParameters();

    DatastoreService dss = DatastoreServiceFactory.getDatastoreService();
    Query q = new Query(kind);
    FetchOptions fo = insertParametersToQueue(q);
    PreparedQuery pq = dss.prepare(q);

    boolean finish = false;

    if (pq.countEntities() > 0) {
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.