Package siena.core.options

Examples of siena.core.options.QueryOptionState


    }
  }

  public static <T> void previousPage(QueryData<T> query) {
    QueryOptionPage pag = (QueryOptionPage)query.option(QueryOptionPage.ID);
    QueryOptionState state = (QueryOptionState)query.option(QueryOptionState.ID);
    QueryOptionSdbContext sdbCtx = (QueryOptionSdbContext)query.option(QueryOptionSdbContext.ID);
    if(sdbCtx==null){
      sdbCtx = new QueryOptionSdbContext();
      query.options().put(sdbCtx.type, sdbCtx);
    }
View Full Code Here


    if(gaeCtx==null){
      gaeCtx = new QueryOptionGaeContext();
      query.customize(gaeCtx);
    }
   
    QueryOptionState state = (QueryOptionState)query.option(QueryOptionState.ID);
    QueryOptionFetchType fetchType = (QueryOptionFetchType)query.option(QueryOptionFetchType.ID);
    FetchOptions fetchOptions = FetchOptions.Builder.withDefaults();

    QueryOptionPage pag = (QueryOptionPage)query.option(QueryOptionPage.ID);
    if(!pag.isPaginating()){
      // no pagination but pageOption active
      if(pag.isActive()){
        // if local limit is set, it overrides the pageOption.pageSize
        if(limit!=Integer.MAX_VALUE){
          gaeCtx.realPageSize = limit;
          fetchOptions.limit(gaeCtx.realPageSize);
          // pageOption is passivated to be sure it is not reused
          pag.passivate();
        }
        // using pageOption.pageSize
        else {
          gaeCtx.realPageSize = pag.pageSize;
          fetchOptions.limit(gaeCtx.realPageSize);
          // passivates the pageOption in stateless mode not to keep anything between 2 requests
          if(state.isStateless()){
            pag.passivate();
          }           
        }
      }
      else {
        if(limit != Integer.MAX_VALUE){
          gaeCtx.realPageSize = limit;
          fetchOptions.limit(gaeCtx.realPageSize);
        }
      }
    }else {
      // paginating so use the pagesize and don't passivate pageOption
      // 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();
View Full Code Here

 
 
  private <T> SienaFuture<Iterable<T>> doFetchIterable(QueryAsync<T> query, int limit, int offset)
  {
    QueryOptionGaeContext gaeCtx = (QueryOptionGaeContext)query.option(QueryOptionGaeContext.ID);
    QueryOptionState state = (QueryOptionState)query.option(QueryOptionState.ID);
    QueryOptionFetchType fetchType = (QueryOptionFetchType)query.option(QueryOptionFetchType.ID);
       
    if(gaeCtx==null){
      gaeCtx = new QueryOptionGaeContext();
      query.customize(gaeCtx);
    }

    FetchOptions fetchOptions = FetchOptions.Builder.withDefaults();

    QueryOptionPage pag = (QueryOptionPage)query.option(QueryOptionPage.ID);
    if(!pag.isPaginating()){
      // no pagination but pageOption active
      if(pag.isActive()){
        // if local limit is set, it overrides the pageOption.pageSize
        if(limit!=Integer.MAX_VALUE){
          gaeCtx.realPageSize = limit;
          fetchOptions.limit(gaeCtx.realPageSize);
          // pageOption is passivated to be sure it is not reused
          pag.passivate();
        }
        // using pageOption.pageSize
        else {
          gaeCtx.realPageSize = pag.pageSize;
          fetchOptions.limit(gaeCtx.realPageSize);
          // passivates the pageOption in stateless mode not to keep anything between 2 requests
          if(state.isStateless()){
            pag.passivate();
          }           
        }
      }
      else {
        if(limit != Integer.MAX_VALUE){
          gaeCtx.realPageSize = limit;
          fetchOptions.limit(gaeCtx.realPageSize);
        }
      }
    }else {
      // paginating so use the pagesize and don't passivate pageOption
      // 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();
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
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 {
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();
    }
   
    String token = null;
    // sets the current cursor (in stateful mode, cursor is always kept for further use)
    if(pag.isPaginating()){
      token = res.getNextToken();
      if(token!=null){
        sdbCtx.addToken(token, sdbCtx.realOffset + sdbCtx.realPageSize + off.offset);
      }
      // if paginating and 0 results then no more data else resets noMoreDataAfter
      if(res.getItems().size()==0){
        sdbCtx.noMoreDataAfter = true;
      } else {
        sdbCtx.noMoreDataAfter = false;
      }
    }else{
      if(state.isStateless()){
        // in stateless, doesn't follow real offset & stays where it is
        sdbCtx.realOffset = off.offset;
       
        token = res.getNextToken();
        if(token!=null){
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()){       
View Full Code Here

  }

  @Override
  public <T> void paginate(Query<T> query) {
    QueryOptionSdbContext sdbCtx = (QueryOptionSdbContext)query.option(QueryOptionSdbContext.ID);
    QueryOptionState state = (QueryOptionState)query.option(QueryOptionState.ID);

    if(sdbCtx==null){
      sdbCtx = new QueryOptionSdbContext();
      query.customize(sdbCtx);
    }
   
    // in stateless, resetting pagination resets everything in the context
    if(state.isStateless()){
      sdbCtx.resetAll();     
    }
   
    QueryOptionOffset off = (QueryOptionOffset)query.option(QueryOptionOffset.ID);
    off.passivate();
View Full Code Here

    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 optionStateful() {
    QueryOptionState opt = (QueryOptionState)(options.get(QueryOptionState.ID)).activate();
    opt.lifeCycle = QueryOptionState.LifeCycle.STATEFUL;
  }
View Full Code Here

TOP

Related Classes of siena.core.options.QueryOptionState

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.