"In case of asQueryResultList(), you cannot specify sortInMemory().");
}
addFilterIfPolyModel();
List<M> modelList = null;
boolean hasNext = false;
Cursor cursor = null;
if (fetchOptions.getLimit() == null) {
QueryResultList<Entity> entityList = asQueryResultEntityList();
modelList = new ArrayList<M>(entityList.size());
for (Entity e : entityList) {
ModelMeta<M> mm = DatastoreUtil.getModelMeta(modelMeta, e);
M model = mm.entityToModel(e);
mm.postGet(model);
modelList.add(model);
}
cursor = entityList.getCursor();
} else {
int limit = fetchOptions.getLimit();
fetchOptions.limit(limit + 1);
modelList = new ArrayList<M>();
QueryResultIterator<Entity> ite = asQueryResultEntityIterator();
while (true) {
hasNext = ite.hasNext();
if (!hasNext || modelList.size() == limit) {
cursor = ite.getCursor();
break;
}
Entity e = ite.next();
ModelMeta<M> mm = DatastoreUtil.getModelMeta(modelMeta, e);
M model = mm.entityToModel(e);
mm.postGet(model);
modelList.add(model);
}
}
String cursorWebSafeString =
cursor == null ? null : cursor.toWebSafeString();
return new S3QueryResultList<M>(
modelList,
cursorWebSafeString,
getEncodedFilters(),
getEncodedSorts(),