Package com.google.appengine.api.datastore

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


            // activates the GaeCtx now that it is initialised
            gaeCtx.activate();
            // sets the current cursor (in stateful mode, cursor is always kept for further use)
            if(pag.isPaginating()){
              Cursor cursor = entities.getCursor();
              if(cursor!=null){
                gaeCtx.addCursor(cursor.toWebSafeString());
              }
            }else{
              Cursor cursor = entities.getCursor();
              if(cursor!=null){
                gaeCtx.addAndMoveCursor(entities.getCursor().toWebSafeString());
              }
              // keeps track of the offset anyway if not paginating
              gaeCtx.realOffset+=entities.size();
            }                     
           
            return new GaeSienaFutureListMapper<T>(
                this, entities, query, GaeSienaFutureListMapper.MapType.KEYS_ONLY);
          }
        case NORMAL:
        default:
          {
            PreparedQuery pq = prepare(query);
            if(!gaeCtx.useCursor){
              // then uses offset (in case of IN or != operators)
              //if(offset.isActive()){
              //  fetchOptions.offset(offset.offset);
              //}
              fetchOptions.offset(gaeCtx.realOffset);             
            }
            // we can't use real asynchronous function with cursors
            // so the page is extracted at once and wrapped into a SienaFuture
            QueryResultList<Entity> entities = pq.asQueryResultList(fetchOptions);
           
            // activates the GaeCtx now that it is initialised
            gaeCtx.activate();
            // sets the current cursor (in stateful mode, cursor is always kept for further use)
            //if(gaeCtx.useCursor){
            if(pag.isPaginating()){
              Cursor cursor = entities.getCursor();
              if(cursor!=null){
                gaeCtx.addCursor(cursor.toWebSafeString());
              }
            }else{
              Cursor cursor = entities.getCursor();
              if(cursor!=null){
                gaeCtx.addAndMoveCursor(entities.getCursor().toWebSafeString());
              }
              // keeps track of the offset anyway if not paginating
              gaeCtx.realOffset+=entities.size();
            }
            //}
           
            return new GaeSienaFutureListMapper<T>(this, entities, query);
          }
        }
       
      }else {
        switch(fetchType.fetchType){
        case KEYS_ONLY:
          {
            // we prepare the query each time
            PreparedQuery pq = prepareKeysOnly(query);
            QueryResultList<Entity> entities;
            if(!gaeCtx.useCursor){
              // then uses offset (in case of IN or != operators)
              //if(offset.isActive()){
              //  fetchOptions.offset(offset.offset);
              //}
              fetchOptions.offset(gaeCtx.realOffset);
              // we can't use real asynchronous function with cursors
              // so the page is extracted at once and wrapped into a SienaFuture
              entities = pq.asQueryResultList(fetchOptions);
            }else {
              // we can't use real asynchronous function with cursors
              // so the page is extracted at once and wrapped into a SienaFuture
              String cursor = gaeCtx.currentCursor();
              if(cursor!=null){
                entities = pq.asQueryResultList(
                  fetchOptions.startCursor(Cursor.fromWebSafeString(cursor)));
              }
              else {
                entities = pq.asQueryResultList(fetchOptions);
              }
            }
           
            // sets the current cursor (in stateful mode, cursor is always kept for further use)
            //if(gaeCtx.useCursor){
            if(pag.isPaginating()){
              Cursor cursor = entities.getCursor();
              if(cursor!=null){
                gaeCtx.addCursor(cursor.toWebSafeString());
              }
            }else{
              Cursor cursor = entities.getCursor();
              if(cursor!=null){
                gaeCtx.addAndMoveCursor(entities.getCursor().toWebSafeString());
              }
              // keeps track of the offset anyway if not paginating
              gaeCtx.realOffset+=entities.size();
            }
            //}
           
            return new GaeSienaFutureListMapper<T>(
                this, entities, query, GaeSienaFutureListMapper.MapType.KEYS_ONLY);
          }
        case NORMAL:
        default:
          {
            PreparedQuery pq = prepare(query);
            QueryResultList<Entity> entities;
            if(!gaeCtx.useCursor){
              // then uses offset (in case of IN or != operators)
              //if(offset.isActive()){
              //  fetchOptions.offset(offset.offset);
              //}
              fetchOptions.offset(gaeCtx.realOffset);
              // we can't use real asynchronous function with cursors
              // so the page is extracted at once and wrapped into a SienaFuture
              entities = pq.asQueryResultList(fetchOptions);
            }else {
              // we can't use real asynchronous function with cursors
              // so the page is extracted at once and wrapped into a SienaFuture
              String cursor = gaeCtx.currentCursor();
              if(cursor!=null){
                entities = pq.asQueryResultList(
                  fetchOptions.startCursor(Cursor.fromWebSafeString(gaeCtx.currentCursor())));
              }else {
                entities = pq.asQueryResultList(fetchOptions);
              }
            }
           
            // sets the current cursor (in stateful mode, cursor is always kept for further use)
            //if(gaeCtx.useCursor){
            if(pag.isPaginating()){
              Cursor cursor = entities.getCursor();
              if(cursor!=null){
                gaeCtx.addCursor(cursor.toWebSafeString());
              }
            }else{
              Cursor cursor = entities.getCursor();
              if(cursor!=null){
                gaeCtx.addAndMoveCursor(entities.getCursor().toWebSafeString());
              }
              // keeps track of the offset anyway
              gaeCtx.realOffset+=entities.size();
View Full Code Here


              // activates the GaeCtx now that it is initialised
              gaeCtx.activate();
              // sets the current cursor (in stateful mode, cursor is always kept for further use)
              //if(gaeCtx.useCursor){
              Cursor cursor = entities.getCursor();
              if(cursor!=null){
                gaeCtx.addCursor(cursor.toWebSafeString());
              }
              //}
             
              return new GaeSienaFutureIterableMapper<T>(this, entities, query);
            }else {
View Full Code Here

    public T next() {
      Entity entity = gaeIterator.next();
      QueryOptionGaeContext gaeCtx = (QueryOptionGaeContext)query.option(QueryOptionGaeContext.ID);
      // overrides current cursor with the current iterator cursor
      // sets the current cursor (in stateful mode, cursor is always kept for further use)
      Cursor cursor = gaeIterator.getCursor();
      if(cursor!=null) {
        gaeCtx.setCurrentCursor(cursor.toWebSafeString());
      }
     
      // keeps track of the offset anyway if not paginating
      //QueryOptionOffset offset = (QueryOptionOffset)query.option(QueryOptionOffset.ID);
      gaeCtx.realOffset++;
View Full Code Here

    public T next() {
      Entity entity = gaeIterator.next();
      QueryOptionGaeContext gaeCtx = (QueryOptionGaeContext)query.option(QueryOptionGaeContext.ID);
      // overrides current cursor with the current iterator cursor
      // sets the current cursor (in stateful mode, cursor is always kept for further use)
      Cursor cursor = gaeIterator.getCursor();
      if(cursor!=null) {
        gaeCtx.setCurrentCursor(cursor.toWebSafeString());
      }
     
      // keeps track of the offset anyway if not paginating
      //QueryOptionOffset offset = (QueryOptionOffset)query.option(QueryOptionOffset.ID);
      gaeCtx.realOffset++;
View Full Code Here

            // activates the GaeCtx now that it is initialised
            gaeCtx.activate();
            // sets the current cursor (in stateful mode, cursor is always kept for further use)
            if(pag.isPaginating()){
              Cursor cursor = entities.getCursor();
              if(cursor!=null){
                gaeCtx.addCursor(cursor.toWebSafeString());
              }
             
              // if paginating and 0 results then no more data else resets noMoreDataAfter
              if(entities.size()==0){
                gaeCtx.noMoreDataAfter = true;
              } else {
                gaeCtx.noMoreDataAfter = false;
              }
            }else{
              Cursor cursor = entities.getCursor();
              if(cursor!=null){
                gaeCtx.addAndMoveCursor(entities.getCursor().toWebSafeString());
              }
              // keeps track of the offset anyway if not paginating
              gaeCtx.realOffset+=entities.size();
            }                     
           
            return mapKeysOnly(query, entities);
          }
        case NORMAL:
        default:
          {
            PreparedQuery pq = prepare(query);
            if(!gaeCtx.useCursor){
              // then uses offset (in case of IN or != operators)
              //if(offset.isActive()){
              //  fetchOptions.offset(gaeCtx.realOffset);
              //}
              fetchOptions.offset(gaeCtx.realOffset);
            }
            // we can't use real asynchronous function with cursors
            // so the page is extracted at once and wrapped into a SienaFuture
            QueryResultList<Entity> entities = pq.asQueryResultList(fetchOptions);
           
            // activates the GaeCtx now that it is initialised
            gaeCtx.activate();
            // sets the current cursor (in stateful mode, cursor is always kept for further use)
            if(pag.isPaginating()){
              Cursor cursor = entities.getCursor();
              if(cursor!=null){
                gaeCtx.addCursor(cursor.toWebSafeString());
              }
              // if paginating and 0 results then no more data else resets noMoreDataAfter
              if(entities.size()==0){
                gaeCtx.noMoreDataAfter = true;
              } else {
                gaeCtx.noMoreDataAfter = false;
              }
            }else{
              Cursor cursor = entities.getCursor();
              if(cursor!=null){
                gaeCtx.addAndMoveCursor(entities.getCursor().toWebSafeString());
              }
              // keeps track of the offset anyway if not paginating
              gaeCtx.realOffset+=entities.size();
            }
           
            return map(query, entities);
          }
        }
       
      }else {
        switch(fetchType.fetchType){
        case KEYS_ONLY:
          {
            // we prepare the query each time
            PreparedQuery pq = prepareKeysOnly(query);
            QueryResultList<Entity> entities;
            if(!gaeCtx.useCursor){
              // then uses offset (in case of IN or != operators)
              //if(offset.isActive()){
              //  fetchOptions.offset(gaeCtx.realOffset);
              //}
              fetchOptions.offset(gaeCtx.realOffset);
              // we can't use real asynchronous function with cursors
              // so the page is extracted at once and wrapped into a SienaFuture
              entities = pq.asQueryResultList(fetchOptions);
            }else {
              // we can't use real asynchronous function with cursors
              // so the page is extracted at once and wrapped into a SienaFuture
              String cursor = gaeCtx.currentCursor();
              if(cursor!=null){
                entities = pq.asQueryResultList(
                  fetchOptions.startCursor(Cursor.fromWebSafeString(cursor)));
              }
              else {
                entities = pq.asQueryResultList(fetchOptions);
              }
            }
           
            // sets the current cursor (in stateful mode, cursor is always kept for further use)
            if(pag.isPaginating()){
              Cursor cursor = entities.getCursor();
              if(cursor!=null){
                gaeCtx.addCursor(cursor.toWebSafeString());
              }
              // if paginating and 0 results then no more data else resets noMoreDataAfter
              if(entities.size()==0){
                gaeCtx.noMoreDataAfter = true;
              } else {
                gaeCtx.noMoreDataAfter = false;
              }
            }else{
              Cursor cursor = entities.getCursor();
              if(cursor!=null){
                gaeCtx.addAndMoveCursor(entities.getCursor().toWebSafeString());
              }
              // keeps track of the offset anyway if not paginating
              gaeCtx.realOffset+=entities.size();
            }
            //}
           
            return mapKeysOnly(query, entities);
          }
        case NORMAL:
        default:
          {
            PreparedQuery pq = prepare(query);
            QueryResultList<Entity> entities;
            if(!gaeCtx.useCursor){
              // then uses offset (in case of IN or != operators)
              //if(offset.isActive()){
              //  fetchOptions.offset(gaeCtx.realOffset);
              //}
             
              fetchOptions.offset(gaeCtx.realOffset);
              // we can't use real asynchronous function with cursors
              // so the page is extracted at once and wrapped into a SienaFuture
              entities = pq.asQueryResultList(fetchOptions);
            }else {
              // we can't use real asynchronous function with cursors
              // so the page is extracted at once and wrapped into a SienaFuture
              String cursor = gaeCtx.currentCursor();
              if(cursor!=null){
                entities = pq.asQueryResultList(
                  fetchOptions.startCursor(Cursor.fromWebSafeString(gaeCtx.currentCursor())));
              }else {
                entities = pq.asQueryResultList(fetchOptions);
              }
            }
           
            // sets the current cursor (in stateful mode, cursor is always kept for further use)
            if(pag.isPaginating()){
              Cursor cursor = entities.getCursor();
              if(cursor!=null){
                gaeCtx.addCursor(cursor.toWebSafeString());
              }
              // if paginating and 0 results then no more data else resets noMoreDataAfter
              if(entities.size()==0){
                gaeCtx.noMoreDataAfter = true;
              } else {
                gaeCtx.noMoreDataAfter = false;
              }
            }else{
              Cursor cursor = entities.getCursor();
              if(cursor!=null){
                gaeCtx.addAndMoveCursor(entities.getCursor().toWebSafeString());
              }
              // keeps track of the offset anyway
              gaeCtx.realOffset+=entities.size();
View Full Code Here

              // activates the GaeCtx now that it is initialised
              gaeCtx.activate();
              // sets the current cursor (in stateful mode, cursor is always kept for further use)
              //if(gaeCtx.useCursor){
              Cursor cursor = entities.getCursor();
              if(cursor!=null){
                gaeCtx.addCursor(cursor.toWebSafeString());
              }
              //}
              return new GaeSienaIterable<T>(this, entities, query);
            }else {
              // if not paginating, we simply use the queryresultiterable and moves the current cursor
View Full Code Here

    public <T> Query<T> query(Class<T> clazz, Pagination pagination) {
        Query<T> query = this.query(clazz);

        if (pagination != null) {
            if (pagination.getCurrent() != null) {
                Cursor cursor = Cursor.fromWebSafeString(pagination.getCurrent());
                query.startCursor(cursor);
            }
        }

        return query;
View Full Code Here

        new Operation<Pair<? extends Iterable<JobRecord>, String>>("queryRootPipelines") {
          @Override
          public Pair<? extends Iterable<JobRecord>, String> call() {
            QueryResultIterator<Entity> entities =
                preparedQuery.asQueryResultIterable(fetchOptions).iterator();
            Cursor dsCursor = null;
            List<JobRecord> roots = new LinkedList<>();
            while (entities.hasNext()) {
              if (limit > 0 && roots.size() >= limit) {
                dsCursor = entities.getCursor();
                break;
              }
              JobRecord jobRecord = new JobRecord(entities.next());
              roots.add(jobRecord);
            }
            return Pair.of(roots, dsCursor == null ? null : dsCursor.toWebSafeString());
          }
        });
  }
View Full Code Here

                "In case of asQueryResultList(), you cannot specify sortInMemory().");
        }
        addFilterIfPolyModel();
        List<M> modelList = null;
        boolean hasNext = false;
        Cursor cursor = null;
        int limit = fetchOptions.getLimit();
        if (limit == Integer.MAX_VALUE) {
            QueryResultList<Entity> entityList = asQueryResultEntityList();
            modelList = new ArrayList<M>(entityList.size());
            for (Entity e : entityList) {
                ModelMeta<M> mm = DatastoreUtil.getModelMeta(modelMeta, e);
                modelList.add(mm.entityToModel(e));
            }
            cursor = entityList.getCursor();
        } else {
            fetchOptions.limit(limit + 1);
            modelList = new ArrayList<M>();
            QueryResultIterator<Entity> ite = asQueryResultEntityIterator();
            while (true) {
                hasNext = ite.hasNext();
                if (!hasNext || modelList.size() == limit) {
                    cursor = ite.getCursor();
                    break;
                }
                Entity e = ite.next();
                ModelMeta<M> mm = DatastoreUtil.getModelMeta(modelMeta, e);
                modelList.add(mm.entityToModel(e));
            }
        }
        return new S3QueryResultList<M>(
            modelList,
            cursor.toWebSafeString(),
            getEncodedFilters(),
            getEncodedSorts(),
            hasNext);
    }
View Full Code Here

          throws ServletException, IOException {
    response.setContentType("text/plain;charset=UTF-8");
    PrintWriter out = response.getWriter();
    boolean done = false;
    int tickler = 0;
    Cursor cursor = null;
    try {
      while (!done) {
        tickler = 0;
        Query<Sensor> query = ofy().load().type(Sensor.class).limit(1000);
        if (cursor != null) {
View Full Code Here

TOP

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

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.