Package siena.core.options

Examples of siena.core.options.QueryOptionOffset


          sdbCtx.realOffset -= pag.pageSize;
         
          // if currentokenoffset is less than previous page realoffset
          // uses offset
          if(sdbCtx.currentTokenOffset() <= sdbCtx.realOffset){
            QueryOptionOffset offset = (QueryOptionOffset)query.option(QueryOptionOffset.ID);
            offset.activate();
            offset.offset = sdbCtx.realOffset - sdbCtx.currentTokenOffset();
          }
          // if currentokenoffset is greater than previous page realoffset
          // go to previous page again
          else {
            previousPage(query);
          }
        }else {
          if(sdbCtx.previousToken() == null) {
            sdbCtx.realOffset -= pag.pageSize;
           
            // if the realOffset is not null, it means we are not at the index 0 of the table
            // so now uses realOffset
            if(sdbCtx.realOffset >= 0){
              QueryOptionOffset offset = (QueryOptionOffset)query.option(QueryOptionOffset.ID);
              offset.activate();
              offset.offset = sdbCtx.realOffset;
            }else {
              // resets realOffset to 0 because it was negative
              sdbCtx.realOffset = 0;
              sdbCtx.noMoreDataBefore = true;
            }
          }else {
            // follows the real offset
            sdbCtx.realOffset -= pag.pageSize;
           
            // if currentokenoffset is less than previous page realoffset
            // uses offset
            if(sdbCtx.currentTokenOffset() <= sdbCtx.realOffset){
              QueryOptionOffset offset = (QueryOptionOffset)query.option(QueryOptionOffset.ID);
              offset.activate();
              offset.offset = sdbCtx.realOffset - sdbCtx.currentTokenOffset();
            }
            // if currentokenoffset is greater than previous page realoffset
            // go to previous page again
            else {
              previousPage(query);
            }
          }
        }
       
      }else {
        QueryOptionOffset offset = (QueryOptionOffset)query.option(QueryOptionOffset.ID);
        // means there has been a nextPage performed first and the offset has been used
        // to simulate the nextPage as there was no token yet
        if(sdbCtx.realOffset != 0){
          // follows the real offset
          sdbCtx.realOffset -= pag.pageSize;         

          offset.activate();         
          offset.offset = sdbCtx.realOffset;
        }else {
          sdbCtx.noMoreDataBefore = true;
        }
        /*if(offset.offset != 0){
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 SienaFutureMock<List<T>>(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
          Iterable<Entity> entities = prepareKeysOnly(query).asIterable(fetchOptions);
          return new GaeSienaFutureListMapper<T>(this, entities, query, GaeSienaFutureListMapper.MapType.KEYS_ONLY);
        }
      case NORMAL:
      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 GaeSienaFutureListMapper<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 by using offset 
      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 SienaFutureMock<Iterable<T>>(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 GaeSienaFutureIterableMapper<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

    if(list.isEmpty()) { return null; }
    return list.get(0);
  }

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

 
  protected <T> void postMapping(Query<T> query){
    QueryOptionPage pag = (QueryOptionPage)query.option(QueryOptionPage.ID);
    QueryOptionSdbContext sdbCtx = (QueryOptionSdbContext)query.option(QueryOptionSdbContext.ID);
    QueryOptionState state = (QueryOptionState)query.option(QueryOptionState.ID);
    QueryOptionOffset off = (QueryOptionOffset)query.option(QueryOptionOffset.ID);

    // desactivates paging & offset in stateless mode
    if(state.isStateless() && !pag.isPaginating()){
      pag.passivate();
      pag.pageSize = 0;
      sdbCtx.resetAll();
    }
    // offset if not kept as it is never reused as is even in stateful
    // mode. the stateful mode only keeps the realOffset/pagination alive
    off.passivate();
    off.offset = 0;
  }
View Full Code Here

 
  protected <T> void continueFetchNextToken(Query<T> query, List<T> results, int depth){
    QueryOptionPage pag = (QueryOptionPage)query.option(QueryOptionPage.ID);
    QueryOptionSdbContext sdbCtx = (QueryOptionSdbContext)query.option(QueryOptionSdbContext.ID);
    QueryOptionState state = (QueryOptionState)query.option(QueryOptionState.ID);
    QueryOptionOffset off = (QueryOptionOffset)query.option(QueryOptionOffset.ID);
   
    // desactivates offset not to use if fetching more items from next token
    if(state.isStateless()){
      off.passivate();
    }
   
    if(!pag.isActive()){
      if(state.isStateless()){
        // retrieves next token
        if(sdbCtx.nextToken()!=null){
          doFetchList(query, Integer.MAX_VALUE, 0, results, depth+1);
        }
      }else {
        if(sdbCtx.currentToken()!=null){
          // desactivates offset because we don't to go on using offset while going to next tokens
          boolean b = off.isActive();
          off.passivate();
          doFetchList(query, Integer.MAX_VALUE, 0, results, depth+1);
          // reactivate it if it was activated
          if(b) off.activate();
        }
      }
    }
  }
View Full Code Here

 
  protected <T> void postFetch(Query<T> query, SelectResult res) {
    QueryOptionPage pag = (QueryOptionPage)query.option(QueryOptionPage.ID);
    QueryOptionSdbContext sdbCtx = (QueryOptionSdbContext)query.option(QueryOptionSdbContext.ID);
    QueryOptionState state = (QueryOptionState)query.option(QueryOptionState.ID);
    QueryOptionOffset off = (QueryOptionOffset)query.option(QueryOptionOffset.ID);
   
    if(sdbCtx.realPageSize == 0){
      sdbCtx.realPageSize = res.getItems().size();
    }
   
View Full Code Here

 
  protected <T> void preFetch(Query<T> query, int limit, int offset, boolean recursing){
    QueryOptionSdbContext sdbCtx = (QueryOptionSdbContext)query.option(QueryOptionSdbContext.ID);
    QueryOptionState state = (QueryOptionState)query.option(QueryOptionState.ID);
    QueryOptionPage pag = (QueryOptionPage)query.option(QueryOptionPage.ID);
    QueryOptionOffset off = (QueryOptionOffset)query.option(QueryOptionOffset.ID);

    if(sdbCtx==null){
      sdbCtx = new QueryOptionSdbContext();
      query.customize(sdbCtx);
    }
   
    if(!pag.isPaginating()){
      if(state.isStateless()){
        // if not empty, it means we are recursing on tokens
        sdbCtx.reset(recursing);       
      }
      // no pagination but pageOption active
      if(pag.isActive()){       
        // if local limit is set, it overrides the pageOption.pageSize
        if(limit!=Integer.MAX_VALUE){
          sdbCtx.realPageSize = limit;       
          // DONT DO THAT BECAUSE IT PREVENTS GOING TO NEXT TOKENS USING PAGE SIZE
          // pageOption is passivated to be sure it is not reused
          //pag.passivate();
        }
        // using pageOption.pageSize
        else {
          sdbCtx.realPageSize = pag.pageSize;
          // DONT DO THAT BECAUSE IT PREVENTS GOING TO NEXT TOKENS USING PAGE SIZE
          // passivates the pageOption in stateless mode not to keep anything between 2 requests
          //if(state.isStateless()){
          //  pag.passivate();
          //}           
        }
      }
      else {
        if(limit != Integer.MAX_VALUE){
          sdbCtx.realPageSize = limit;
          // activates paging (but not pagination)
          pag.activate();
        }else {
          sdbCtx.realPageSize = 0;
        }
      }
    }else {
      // paginating so use the pagesize and don't passivate pageOption
      // local limit is not taken into account
      sdbCtx.realPageSize = pag.pageSize;
    }
   
    // if local offset has been set, uses it
    if(offset!=0){
      off.activate();
      off.offset = offset;
    }
  }
View Full Code Here

     
    preFetch(query, limit, offset, !resList.isEmpty());
   
    QueryOptionSdbContext sdbCtx = (QueryOptionSdbContext)query.option(QueryOptionSdbContext.ID);
    QueryOptionFetchType fetchType = (QueryOptionFetchType)query.option(QueryOptionFetchType.ID);
    QueryOptionOffset off = (QueryOptionOffset)query.option(QueryOptionOffset.ID);
   
    // if previousPage has detected there is no more data, simply returns an empty list
    if(sdbCtx.noMoreDataBefore || sdbCtx.noMoreDataAfter){
      return;
    }
           
    // manages cursor limitations for IN and != operators with offsets
    if(!sdbCtx.isActive()){
      StringBuffer domainBuf = new StringBuffer();
      SelectRequest req = SdbMappingUtils.buildQuery(query, prefix, domainBuf);
      req.setConsistentRead(isReadConsistent());
      checkDomain(domainBuf.toString());
      SelectResult res = sdb.select(req);
     
      // activates the SdbCtx now that it is really initialised
      sdbCtx.activate();
                 
      postFetch(query, res);
     
      // cursor not yet created
      switch(fetchType.fetchType){
      case KEYS_ONLY:
        if(off.isActive()){
          SdbMappingUtils.mapSelectResultToListKeysOnly(res, resList, query.getQueriedClass(), off.offset);
        }else {
          SdbMappingUtils.mapSelectResultToListKeysOnly(res, resList, query.getQueriedClass());
        }       
        break;
      case NORMAL:
      default:
        if(off.isActive()){
          SdbMappingUtils.mapSelectResultToList(res, resList, query.getQueriedClass(), off.offset);
        }else {
          SdbMappingUtils.mapSelectResultToList(res, resList, query.getQueriedClass());
        }
        // join management
        if(!query.getJoins().isEmpty()
            || !ClassInfo.getClassInfo(query.getQueriedClass()).joinFields.isEmpty())
          mapJoins(query, resList);
      }
     
      continueFetchNextToken(query, resList, depth);
      postMapping(query);
    }
    else {
      // we prepare the query each time
      StringBuffer domainBuf = new StringBuffer();
      SelectRequest req = SdbMappingUtils.buildQuery(query, prefix, domainBuf);
      req.setConsistentRead(isReadConsistent());
      checkDomain(domainBuf.toString());
      // we can't use real asynchronous function with cursors
      // so the page is extracted at once and wrapped into a SienaFuture     
      String token = sdbCtx.currentToken();
      if(token!=null){
        req.setNextToken(token);
      }
      SelectResult res = sdb.select(req);
       
      postFetch(query, res);
     
      switch(fetchType.fetchType){
      case KEYS_ONLY:
        if(off.isActive()){
          SdbMappingUtils.mapSelectResultToListKeysOnly(res, resList, query.getQueriedClass(), off.offset);
        }else {
          SdbMappingUtils.mapSelectResultToListKeysOnly(res, resList, query.getQueriedClass());
        }
        break;
      case NORMAL:
      default:
        if(off.isActive()){
          SdbMappingUtils.mapSelectResultToList(res, resList, query.getQueriedClass(), off.offset);
        } else {
          SdbMappingUtils.mapSelectResultToList(res, resList, query.getQueriedClass());
        }
        // join management
View Full Code Here

    // in stateless, resetting pagination resets everything in the context
    if(state.isStateless()){
      sdbCtx.resetAll();     
    }
   
    QueryOptionOffset off = (QueryOptionOffset)query.option(QueryOptionOffset.ID);
    off.passivate();
    off.offset = 0;
  }
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.