in empire-db/src/main/java/org/apache/empire/db/DBUtils.java [1131:1195]
public <T> List<T> queryBeanList(DBCommandExpr cmd, DBBeanListFactory<T> factory, Object parent, int first, int pageSize)
{
List<T> list = null;
DBReader r = new DBReader(context);
try
{ // prepare
factory.prepareQuery(cmd, context);
// check pageSize
if (pageSize==0)
{ log.warn("PageSize must not be 0. Setting to -1 for all records!");
pageSize = -1;
}
// set range
DBMSHandler dbms = context.getDbms();
if (pageSize>0 && dbms.isSupported(DBMSFeature.QUERY_LIMIT_ROWS))
{ // let the database limit the rows
if (first>0 && dbms.isSupported(DBMSFeature.QUERY_SKIP_ROWS))
{ // let the database skip the rows
cmd.skipRows(first);
// no need to skip rows ourself
first = 0;
}
cmd.limitRows(first+pageSize);
}
// Runquery
r.open(cmd);
if (first>0)
{ // skip rows
r.skipRows(first);
}
// Create a list of data entries
int maxCount = (pageSize>=0) ? pageSize : MAX_QUERY_ROWS;
list = factory.newList((pageSize>=0) ? pageSize : DEFAULT_LIST_CAPACITY);
// add data
int rownum = 0;
while (r.moveNext() && maxCount != 0)
{ // Create bean an init
T item = factory.newItem(rownum, r);
if (item==null)
continue;
// add entry
list.add(item);
// post processing
if (item instanceof DataBean<?>)
((DataBean<?>)item).initialize(((DBObject)r).getDatabase(), context, rownum, parent);
// next
rownum++;
// Decrease count
if (maxCount > 0)
maxCount--;
}
// check
if (rownum==MAX_QUERY_ROWS)
queryRowLimitExeeded();
// done
return list;
}
finally
{
r.close();
// complete
if (list!=null)
factory.completeQuery(list);
}
}