Search in sources :

Example 11 with QueryOptionState

use of siena.core.options.QueryOptionState in project siena by mandubian.

the class BaseQueryData method defaultOptions.

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());
        }
    };
}
Also used : QueryOptionOffset(siena.core.options.QueryOptionOffset) QueryOptionPage(siena.core.options.QueryOptionPage) HashMap(java.util.HashMap) QueryOptionState(siena.core.options.QueryOptionState) QueryOptionFetchType(siena.core.options.QueryOptionFetchType)

Example 12 with QueryOptionState

use of siena.core.options.QueryOptionState in project siena by mandubian.

the class BaseQueryData method optionStateful.

protected void optionStateful() {
    QueryOptionState opt = (QueryOptionState) (options.get(QueryOptionState.ID)).activate();
    opt.lifeCycle = QueryOptionState.LifeCycle.STATEFUL;
}
Also used : QueryOptionState(siena.core.options.QueryOptionState)

Example 13 with QueryOptionState

use of siena.core.options.QueryOptionState in project siena by mandubian.

the class SdbPersistenceManager method postMapping.

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;
}
Also used : QueryOptionOffset(siena.core.options.QueryOptionOffset) QueryOptionPage(siena.core.options.QueryOptionPage) QueryOptionState(siena.core.options.QueryOptionState)

Example 14 with QueryOptionState

use of siena.core.options.QueryOptionState in project siena by mandubian.

the class SdbPersistenceManager method postFetch.

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) {
                sdbCtx.addToken(token, /*sdbCtx.realOffset +*/
                sdbCtx.realPageSize);
            }
        } else {
            // follows the real offset in stateful mode
            sdbCtx.realOffset += sdbCtx.realPageSize;
            token = res.getNextToken();
            if (token != null) {
                sdbCtx.addAndMoveToken(token, sdbCtx.realOffset);
            } else {
                // forces to go to next token to invalidate current one
                // if there are no token after, currentToken will be null
                sdbCtx.nextToken();
            }
        }
    }
}
Also used : QueryOptionOffset(siena.core.options.QueryOptionOffset) QueryOptionPage(siena.core.options.QueryOptionPage) QueryOptionState(siena.core.options.QueryOptionState)

Example 15 with QueryOptionState

use of siena.core.options.QueryOptionState in project siena by mandubian.

the class SdbPersistenceManager method paginate.

@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();
    off.offset = 0;
}
Also used : QueryOptionOffset(siena.core.options.QueryOptionOffset) QueryOptionState(siena.core.options.QueryOptionState)

Aggregations

QueryOptionState (siena.core.options.QueryOptionState)20 QueryOptionOffset (siena.core.options.QueryOptionOffset)16 QueryOptionPage (siena.core.options.QueryOptionPage)15 SienaException (siena.SienaException)6 ArrayList (java.util.ArrayList)5 QueryOptionFetchType (siena.core.options.QueryOptionFetchType)5 Cursor (com.google.appengine.api.datastore.Cursor)4 FetchOptions (com.google.appengine.api.datastore.FetchOptions)4 PreparedQuery (com.google.appengine.api.datastore.PreparedQuery)4 QueryResultList (com.google.appengine.api.datastore.QueryResultList)4 QueryResultIterable (com.google.appengine.api.datastore.QueryResultIterable)3 PreparedStatement (java.sql.PreparedStatement)3 ResultSet (java.sql.ResultSet)3 SQLException (java.sql.SQLException)3 SienaFutureMock (siena.core.async.SienaFutureMock)2 HashMap (java.util.HashMap)1 List (java.util.List)1