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());
}
};
}
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;
}
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;
}
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();
}
}
}
}
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;
}
Aggregations