Package siena.core.options

Examples of siena.core.options.QueryOptionOffset


      // local limit is not taken into account
      gaeCtx.realPageSize = pag.pageSize;
      fetchOptions.limit(gaeCtx.realPageSize);
    }

    QueryOptionOffset off = (QueryOptionOffset)query.option(QueryOptionOffset.ID);
    // if local offset has been set, uses it
    if(offset!=0){
      off.activate();
      off.offset = offset;
    }
           
    // if previousPage has detected there is no more data, simply returns an empty list
    if(gaeCtx.noMoreDataBefore){
      return new ArrayList<T>();
    }
           
    if(state.isStateless()) {
      if(pag.isPaginating()){
        if(off.isActive()){
          gaeCtx.realOffset+=off.offset;
          fetchOptions.offset(gaeCtx.realOffset);
          off.passivate();
        }else {
          fetchOptions.offset(gaeCtx.realOffset);
        }
      }else {
        // if stateless and not paginating, resets the realoffset to 0
        gaeCtx.realOffset = 0;
        if(off.isActive()){
          gaeCtx.realOffset=off.offset;
          fetchOptions.offset(gaeCtx.realOffset);
          off.passivate();
        }
      }
     
      switch(fetchType.fetchType){
      case KEYS_ONLY:
        {
          // uses iterable as it is the only async request for prepared query for the time being
          List<Entity> entities = prepareKeysOnly(query).asList(fetchOptions);
          // if paginating and 0 results then no more data else resets noMoreDataAfter
          if(pag.isPaginating()){
            if(entities.size() == 0){
              gaeCtx.noMoreDataAfter = true;
            }
            else {
              gaeCtx.noMoreDataAfter = false;
            }
          }
          return mapKeysOnly(query, entities);
        }
      case NORMAL:
      default:
        {
          // uses iterable as it is the only async request for prepared query for the time being
          List<Entity> entities = prepare(query).asList(fetchOptions);
          // if paginating and 0 results then no more data else resets noMoreDataAfter
          if(pag.isPaginating()){
            if(entities.size() == 0){
              gaeCtx.noMoreDataAfter = true;
            }
            else {
              gaeCtx.noMoreDataAfter = false;
            }
          }
          return map(query, entities);
        }
      }

    }else {
      if(off.isActive()){
        // by default, we add the offset but it can be added with the realoffset
        // in case of cursor desactivated
        fetchOptions.offset(off.offset);
        gaeCtx.realOffset+=off.offset;
        off.passivate();
      }
     
      // manages cursor limitations for IN and != operators with offsets
      if(!gaeCtx.isActive()){
        // cursor not yet created
View Full Code Here


      // local limit is not taken into account
      gaeCtx.realPageSize = pag.pageSize;
      fetchOptions.limit(gaeCtx.realPageSize);
    }

    QueryOptionOffset off = (QueryOptionOffset)query.option(QueryOptionOffset.ID);
    // if local offset has been set, uses it
    if(offset!=0){
      off.activate();
      off.offset = offset;
    }
   
    // if previousPage has detected there is no more data, simply returns an empty list
    if(gaeCtx.noMoreDataBefore){
      return new ArrayList<T>();
    }
           
    if(state.isStateless()) {
      if(pag.isPaginating()){     
        if(off.isActive()){
          gaeCtx.realOffset+=off.offset;
          fetchOptions.offset(gaeCtx.realOffset);
          off.passivate();
        }else {
          fetchOptions.offset(gaeCtx.realOffset);
        }
      }else {
               
        // if stateless and not paginating, resets the realoffset to 0
        gaeCtx.realOffset = off.offset;
        if(off.isActive()){
          fetchOptions.offset(gaeCtx.realOffset);
          off.passivate();
        }
      }
     
      switch(fetchType.fetchType){
      case ITER:
      default:
        {
          // uses iterable as it is the only async request for prepared query for the time being
          Iterable<Entity> entities = prepare(query).asIterable(fetchOptions);
          return new GaeSienaIterable<T>(this, entities, query);
        }
      }
     
    }else {     
      if(off.isActive()){
        // by default, we add the offset but it can be added with the realoffset
        // in case of cursor desactivated
        fetchOptions.offset(off.offset);
        gaeCtx.realOffset+=off.offset;
        off.passivate();
      }
      // manages cursor limitations for IN and != operators   
      if(!gaeCtx.isActive()){
        // cursor not yet created
        switch(fetchType.fetchType){
View Full Code Here

  public static Map<Integer, QueryOption> defaultOptions() {
    return new HashMap<Integer, QueryOption>() {
      private static final long serialVersionUID = -7438657296637379900L;
      {
        put(QueryOptionPage.ID, new QueryOptionPage(0));
        put(QueryOptionOffset.ID, new QueryOptionOffset(0));
        put(QueryOptionState.ID, new QueryOptionState());
        //the fetch type is activated by default and set to NORMAL
        put(QueryOptionFetchType.ID, (new QueryOptionFetchType()).activate());
      }}
  }
View Full Code Here

  }
 
  protected void optionPaginate(int pageSize) {
    // sets the pagination
    QueryOptionPage opt = (QueryOptionPage)(options.get(QueryOptionPage.ID));
    QueryOptionOffset offOpt = (QueryOptionOffset)options.get(QueryOptionOffset.ID);
    //QueryOptionState stateOpt = (QueryOptionState)(options.get(QueryOptionState.ID)).activate();
    // can't change pagination after it has been initialized because it breaks all the cursor mechanism
   
    /*if(opt.isActive() && opt.isPaginating()){
      throw new SienaException("Can't change pagination after it has been initialized...");
View Full Code Here

    //}
  }
 
  protected void optionOffset(int offset) {
    QueryOptionPage pagOpt = (QueryOptionPage)(options.get(QueryOptionPage.ID));
    QueryOptionOffset offOpt = (QueryOptionOffset)options.get(QueryOptionOffset.ID);
    //QueryOptionState stateOpt = (QueryOptionState)(options.get(QueryOptionState.ID));
   
    offOpt.activate();
    offOpt.offsetType = QueryOptionOffset.OffsetType.MANUAL;
    offOpt.offset = offset;
   
    // deactivates the pagination in any case
    pagOpt.pageType = QueryOptionPage.PageType.MANUAL;
View Full Code Here

    };
   
  }

  public <T> void release(QueryAsync<T> query) {
    QueryOptionOffset offset = (QueryOptionOffset)query.option(QueryOptionOffset.ID);
    QueryOption reuse = query.option(QueryOptionState.ID);
   
    // resets offset
    if(offset.isActive())
      offset.offset=0;
    // disables reusable and cludge
    if(reuse.isActive()){
      reuse.passivate();
    }
View Full Code Here

      if(!last.ascending)
        q.append(DESC);
    }
   
    QueryOptionSdbContext sdbCtx = (QueryOptionSdbContext)query.option(QueryOptionSdbContext.ID);
    QueryOptionOffset off = (QueryOptionOffset)query.option(QueryOptionOffset.ID);
    if(sdbCtx != null && sdbCtx.realPageSize != 0){
      if(off!=null && off.isActive()){
        // if offset is active, adds it to the page size to be sure to retrieve enough elements
        q.append(LIMIT + (sdbCtx.realPageSize + off.offset));
      }else {
        q.append(LIMIT + sdbCtx.realPageSize);
      }
View Full Code Here

  }
 
  public static <T> void nextPage(QueryData<T> query) {
    QueryOptionPage pag = (QueryOptionPage)query.option(QueryOptionPage.ID);
    QueryOptionSdbContext sdbCtx = (QueryOptionSdbContext)query.option(QueryOptionSdbContext.ID);
    QueryOptionOffset off = (QueryOptionOffset)query.option(QueryOptionOffset.ID);

    if(sdbCtx==null){
      sdbCtx = new QueryOptionSdbContext();
      query.options().put(sdbCtx.type, sdbCtx);
    }
   
    // if no more data after, doesn't try to go after
    if(sdbCtx.noMoreDataAfter){
      return;
    }
   
    // if no more data before, removes flag to be able and stay there
    if(sdbCtx.noMoreDataBefore){
      sdbCtx.noMoreDataBefore = false;
      return;
    }
   
    if(pag.isPaginating()){
      if(sdbCtx.hasToken()){
        if(sdbCtx.nextToken() == null) {
          // in this case, doesn't advance to the next page
          // and stays at the offset of the beginning of the
          // last page
          sdbCtx.noMoreDataAfter = true;
        }else{
          // follows the real offset and doesn't forget to add the off.offset
          if(off.isActive())
            sdbCtx.realOffset += pag.pageSize + off.offset;
          else sdbCtx.realOffset += pag.pageSize;
         
          // if currentokenoffset is less than next page realoffset
          // uses offset
          if(sdbCtx.currentTokenOffset() <= sdbCtx.realOffset){
            off.activate();
            off.offset = sdbCtx.realOffset - sdbCtx.currentTokenOffset();
          }
          // if currentokenoffset is greater than previous page realoffset
          // go to previous page again
          else {
            nextPage(query);
          }         
        }
      }else {
        // no token yet, so uses the offset to go to next page
        QueryOptionOffset offset = (QueryOptionOffset)query.option(QueryOptionOffset.ID);
        offset.activate();
        offset.offset += pag.pageSize;
        // follows the real offset
        sdbCtx.realOffset += pag.pageSize;
      }
    }else {
View Full Code Here

        gaeCtx.realOffset+=pag.pageSize;
        //}
      }     
      else {
        if(!gaeCtx.isActive()){
          QueryOptionOffset offset = (QueryOptionOffset)query.option(QueryOptionOffset.ID);
          if(!gaeCtx.useCursor){
            // then uses offset (in case of IN or != operators)
            //if(offset.isActive()){
            gaeCtx.realOffset+=pag.pageSize;
            //}
          }
          // if the cursor is used, just passivates the offset
          else {
            offset.passivate();
            // keeps track of the offset anyway
            gaeCtx.realOffset+=pag.pageSize;
          }
        }else {
          QueryOptionOffset offset = (QueryOptionOffset)query.option(QueryOptionOffset.ID);
          // if there is a next cursor, we prefer using it because it can mean it was a
          // cursor added by a previousPage call which tries to go backward the first page
          if(!gaeCtx.useCursor && !gaeCtx.hasNextCursor()){
            // then uses offset (in case of IN or != operators)
            //if(offset.isActive()){
            gaeCtx.realOffset+=pag.pageSize;
            //}
          }else{
            // forces cursor to be sure it is used
            gaeCtx.useCursor = true;
            String cursor = gaeCtx.nextCursor();
            // if the cursor is null, it means we are back to the first page so we reactivate the offset
            gaeCtx.realOffset+=pag.pageSize;
            if(cursor==null){
              offset.activate();
            }else {
              offset.passivate();
            }
          }
        }
      }
    }else {
View Full Code Here

              gaeCtx.noMoreDataBefore = true;
            }
          }
         
        }else {
          QueryOptionOffset offset = (QueryOptionOffset)query.option(QueryOptionOffset.ID);
          if(!gaeCtx.useCursor){
            // then uses offset (in case of IN or != operators)
            //if(offset.isActive()){
              if(gaeCtx.realOffset>=pag.pageSize) {
                gaeCtx.realOffset-=pag.pageSize;
              }
              // passivates offset and computes the page before because we are at the first page
              else{
                offset.passivate();
                gaeCtx.noMoreDataBefore = true;               
                previousPage(query);
              }
            //}
          }else{
            String cursor = gaeCtx.previousCursor();
            // if the cursor is null, it means we are back to the first page
            // so we reactivate the offset and deactivate the useCursor
            // and recall the previousPage with the offset mechanism
            if(cursor==null){
              offset.activate();
              gaeCtx.useCursor = false;
              previousPage(query);
            }else {
              offset.passivate();
              gaeCtx.useCursor = true;
              if(gaeCtx.realOffset>=pag.pageSize) {
                gaeCtx.realOffset-=pag.pageSize;
              }
              // passivates offset and computes the page before because we are at the first page
View Full Code Here

TOP

Related Classes of siena.core.options.QueryOptionOffset

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.