Package com.google.appengine.api.datastore

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


  public Cursor getCursor() {
    if (nextOffset == 0) {
      return nextCursor;
    } else {
      // There may not be a baseCursor if we haven't iterated yet
      FetchOptions opts = FetchOptions.Builder.withDefaults();
      if (nextCursor != null)
        opts = opts.startCursor(nextCursor);

      return pq.asQueryResultIterator(opts.offset(nextOffset).limit(0)).getCursor();
    }
  }
View Full Code Here


  /**
   * @return a set of fetch options for the current limit, offset, and cursors,
   *  based on the default fetch options.  There will always be options even if default.
   */
  private FetchOptions fetchOptions() {
    FetchOptions opts = FetchOptions.Builder.withDefaults();

    if (this.startAt != null)
      opts = opts.startCursor(this.startAt);

    if (this.endAt != null)
      opts = opts.endCursor(this.endAt);

    if (this.limit != 0)
      opts = opts.limit(this.limit);

    if (this.offset != 0)
      opts = opts.offset(this.offset);

    if (this.chunk == null)
      opts = opts.chunkSize(DEFAULT_CHUNK_SIZE);
    else
      opts = opts.chunkSize(this.chunk);

    return opts;
  }
View Full Code Here

  public static GbEntityList<GbEntity> getData(Cursor cursor, String kind, Integer range) {

    // Get Data
    DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
    PreparedQuery query = datastore.prepare(new Query(kind));
    FetchOptions fetchOptions = null;
    if (cursor == null) {
      fetchOptions = FetchOptions.Builder.withLimit(range);
    } else {
      fetchOptions = FetchOptions.Builder.withStartCursor(cursor).limit(range);
    }
View Full Code Here

    final String kind = (String) control.getProperty(GbControl.KIND_NAME);
    final Long rowNum = (Long) control.getProperty(GbControl.COUNT);
    logger.info("Drop:kind=" + kind + ":rowNum=" + rowNum);
    Queue queue = QueueFactory.getDefaultQueue();

    FetchOptions withLimit = FetchOptions.Builder.withLimit(RANGE);
    List<Entity> keyList = datastore.prepare(new Query(kind).setKeysOnly()).asList(withLimit);

    if ((keyList == null) || (keyList.size() == 0)) {
      queue.add(TaskOptions.Builder.url("/tasks/dropEnd.gobo").param(
        "controlKey",
View Full Code Here

      applySort(q, queryInfo.orderBy);
    PreparedQuery pq = datastore.prepare(q);

    Integer inlineCount = queryInfo.inlineCount == InlineCount.ALLPAGES ? pq.countEntities(FetchOptions.Builder.withDefaults()) : null;

    FetchOptions options = null;
    if (queryInfo.top != null)
      options = FetchOptions.Builder.withLimit(queryInfo.top);
    if (queryInfo.skip != null)
      options = options == null ? FetchOptions.Builder.withOffset(queryInfo.skip) : options.offset(queryInfo.skip);

    Iterable<Entity> iter = options == null ? pq.asIterable() : pq.asIterable(options);

    final QueryInfo qi = queryInfo;
    List<OEntity> entities = Enumerable.create(iter).select(new Func1<Entity, OEntity>() {
View Full Code Here

  }

  public List<UploadedImage> getRecent() {
    Query query = new Query("UploadedImage");
    query.addSort(UploadedImage.CREATED_AT, SortDirection.DESCENDING);
    FetchOptions options = FetchOptions.Builder.withLimit(25);

    ArrayList<UploadedImage> results = new ArrayList<UploadedImage>();
    for (Entity result : datastore.prepare(query).asIterable(options)) {
      UploadedImage image = fromEntity(result);
      results.add(image);
View Full Code Here

    if (n < 1) {
      throw new IllegalArgumentException("n must be positive");
    }
    logger.info("Deleting  " + n + " " + kind + "s with rootJobKey=" + rootJobKey);
    List<Key> keyList = new LinkedList<Key>();
    FetchOptions fetchOptions = FetchOptions.Builder.withLimit(n).chunkSize(Math.min(n, 500));
    for (Entity entity : queryAll(kind, rootJobKey, true, fetchOptions)) {
      keyList.add(entity.getKey());
    }
    dataStore.delete(keyList);
    return keyList.size();
View Full Code Here

      {
        DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
        com.google.appengine.api.datastore.Query q = new com.google.appengine.api.datastore.Query(classe.getSimpleName());
        PreparedQuery pq = ds.prepare(q);
         
        final FetchOptions fetch_options = FetchOptions.Builder.withPrefetchSize(100).chunkSize(100);
         ret = ds.prepare(q).asQueryResultList(fetch_options);
       
        //Query q = em.createQuery("SELECT c FROM " + classe.getSimpleName() + " c");
       
        //ret =  q.getResultList();
       
      }
      else
      {
        DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
        com.google.appengine.api.datastore.Query q = new com.google.appengine.api.datastore.Query(classe.getSimpleName());
        PreparedQuery pq = ds.prepare(q);
         
        final FetchOptions fetch_options = FetchOptions.Builder.withPrefetchSize(100).chunkSize(100);
         ret = ds.prepare(q).asQueryResultList(fetch_options);
        
        //Query q = em.createQuery("SELECT c FROM " + classe.getSimpleName() + " c");
       
      //  ret =  q.getResultList();
View Full Code Here

    }
   
    @Test
    public void testResetDate() throws Exception {
       
        FetchOptions fo = FetchOptions.Builder.withDefaults();
       
        cacheService.putResetDate("SomeKind");
        Date resetDate = cacheService.getResetDate("SomeKind");
        assertNotNull(resetDate);
        Thread.sleep(2000);
View Full Code Here

    for (Entity e : ds.prepare(q).asIterable()) {
        results.add(Entities.getNamespaceFromNamespaceKey(e.getKey()));
    }
    String bak = NamespaceManager.get();
    try {
        FetchOptions opt = FetchOptions.Builder.withOffset(0);
        for(String ns: results) {
            NamespaceManager.set(ns);
            q = new Query(RESET_DATE_KIND).setKeysOnly();
            List<Entity> entities = ds.prepare(q).asList(opt);
            List<Key> keys = new ArrayList<Key>(entities.size());
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.