if(!gaeCtx.isActive()){
// cursor not yet created
switch(fetchType.fetchType){
case KEYS_ONLY:
{
PreparedQuery pq = prepareKeysOnly(query);
if(!gaeCtx.useCursor){
// then uses offset (in case of IN or != operators)
//if(offset.isActive()){
// fetchOptions.offset(gaeCtx.realOffset);
//}
fetchOptions.offset(gaeCtx.realOffset);
}
// we can't use real asynchronous function with cursors
// so the page is extracted at once and wrapped into a SienaFuture
QueryResultList<Entity> entities = pq.asQueryResultList(fetchOptions);
// activates the GaeCtx now that it is initialised
gaeCtx.activate();
// sets the current cursor (in stateful mode, cursor is always kept for further use)
if(pag.isPaginating()){
Cursor cursor = entities.getCursor();
if(cursor!=null){
gaeCtx.addCursor(cursor.toWebSafeString());
}
// if paginating and 0 results then no more data else resets noMoreDataAfter
if(entities.size()==0){
gaeCtx.noMoreDataAfter = true;
} else {
gaeCtx.noMoreDataAfter = false;
}
}else{
Cursor cursor = entities.getCursor();
if(cursor!=null){
gaeCtx.addAndMoveCursor(entities.getCursor().toWebSafeString());
}
// keeps track of the offset anyway if not paginating
gaeCtx.realOffset+=entities.size();
}
return mapKeysOnly(query, entities);
}
case NORMAL:
default:
{
PreparedQuery pq = prepare(query);
if(!gaeCtx.useCursor){
// then uses offset (in case of IN or != operators)
//if(offset.isActive()){
// fetchOptions.offset(gaeCtx.realOffset);
//}
fetchOptions.offset(gaeCtx.realOffset);
}
// we can't use real asynchronous function with cursors
// so the page is extracted at once and wrapped into a SienaFuture
QueryResultList<Entity> entities = pq.asQueryResultList(fetchOptions);
// activates the GaeCtx now that it is initialised
gaeCtx.activate();
// sets the current cursor (in stateful mode, cursor is always kept for further use)
if(pag.isPaginating()){
Cursor cursor = entities.getCursor();
if(cursor!=null){
gaeCtx.addCursor(cursor.toWebSafeString());
}
// if paginating and 0 results then no more data else resets noMoreDataAfter
if(entities.size()==0){
gaeCtx.noMoreDataAfter = true;
} else {
gaeCtx.noMoreDataAfter = false;
}
}else{
Cursor cursor = entities.getCursor();
if(cursor!=null){
gaeCtx.addAndMoveCursor(entities.getCursor().toWebSafeString());
}
// keeps track of the offset anyway if not paginating
gaeCtx.realOffset+=entities.size();
}
return map(query, entities);
}
}
}else {
switch(fetchType.fetchType){
case KEYS_ONLY:
{
// we prepare the query each time
PreparedQuery pq = prepareKeysOnly(query);
QueryResultList<Entity> entities;
if(!gaeCtx.useCursor){
// then uses offset (in case of IN or != operators)
//if(offset.isActive()){
// fetchOptions.offset(gaeCtx.realOffset);
//}
fetchOptions.offset(gaeCtx.realOffset);
// we can't use real asynchronous function with cursors
// so the page is extracted at once and wrapped into a SienaFuture
entities = pq.asQueryResultList(fetchOptions);
}else {
// we can't use real asynchronous function with cursors
// so the page is extracted at once and wrapped into a SienaFuture
String cursor = gaeCtx.currentCursor();
if(cursor!=null){
entities = pq.asQueryResultList(
fetchOptions.startCursor(Cursor.fromWebSafeString(cursor)));
}
else {
entities = pq.asQueryResultList(fetchOptions);
}
}
// sets the current cursor (in stateful mode, cursor is always kept for further use)
if(pag.isPaginating()){
Cursor cursor = entities.getCursor();
if(cursor!=null){
gaeCtx.addCursor(cursor.toWebSafeString());
}
// if paginating and 0 results then no more data else resets noMoreDataAfter
if(entities.size()==0){
gaeCtx.noMoreDataAfter = true;
} else {
gaeCtx.noMoreDataAfter = false;
}
}else{
Cursor cursor = entities.getCursor();
if(cursor!=null){
gaeCtx.addAndMoveCursor(entities.getCursor().toWebSafeString());
}
// keeps track of the offset anyway if not paginating
gaeCtx.realOffset+=entities.size();
}
//}
return mapKeysOnly(query, entities);
}
case NORMAL:
default:
{
PreparedQuery pq = prepare(query);
QueryResultList<Entity> entities;
if(!gaeCtx.useCursor){
// then uses offset (in case of IN or != operators)
//if(offset.isActive()){
// fetchOptions.offset(gaeCtx.realOffset);
//}
fetchOptions.offset(gaeCtx.realOffset);
// we can't use real asynchronous function with cursors
// so the page is extracted at once and wrapped into a SienaFuture
entities = pq.asQueryResultList(fetchOptions);
}else {
// we can't use real asynchronous function with cursors
// so the page is extracted at once and wrapped into a SienaFuture
String cursor = gaeCtx.currentCursor();
if(cursor!=null){
entities = pq.asQueryResultList(
fetchOptions.startCursor(Cursor.fromWebSafeString(gaeCtx.currentCursor())));
}else {
entities = pq.asQueryResultList(fetchOptions);
}
}
// sets the current cursor (in stateful mode, cursor is always kept for further use)
if(pag.isPaginating()){