in empire-db/src/main/java/org/apache/empire/db/DBUtils.java [823:883]
public <T extends DataListEntry> List<T> queryDataList(DBCommandExpr cmd, DataListFactory<T> factory, 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 : 10);
// add data
int rownum = 0;
while (r.moveNext() && maxCount != 0)
{ // Create bean an init
T entry = factory.newEntry(rownum, r);
if (entry==null)
continue;
// add entry
list.add(entry);
rownum++;
// Decrease count
if (maxCount > 0)
maxCount--;
}
// check
if (rownum==MAX_QUERY_ROWS)
queryRowLimitExeeded();
// done
return list;
}
finally
{ // close reader
r.close();
// complete
if (list!=null)
factory.completeQuery(list);
}
}