* fully resolved. For the rest of the list, only ObjectIds are read.
*
* @since 1.0.6
*/
protected void fillIn(Query query) {
QueryMetadata info = query.getMetaData(dataContext.getEntityResolver());
synchronized (elements) {
boolean fetchesDataRows = internalQuery.isFetchingDataRows();
// start fresh
elements.clear();
rowWidth = 0;
try {
int lastResolved = 0;
long t1 = System.currentTimeMillis();
ResultIterator it = dataContext.performIteratedQuery(query);
try {
rowWidth = it.getDataRowWidth();
// resolve first page if we can
if (resolvesFirstPage()) {
// read first page completely, the rest as ObjectIds
for (int i = 0; i < pageSize && it.hasNextRow(); i++) {
elements.add(it.nextDataRow());
lastResolved++;
}
// defer DataRows -> Objects conversion till we are completely done.
}
// continue reading ids
DbEntity entity = rootEntity.getDbEntity();
while (it.hasNextRow()) {
elements.add(it.nextObjectId(entity));
}
QueryLogger.logSelectCount(elements.size(), System
.currentTimeMillis()
- t1);
}
finally {
it.close();
}
// fill in the first page AFTER the iterator was closed, otherwise we may
// cause an (unobvious) deadlock due to connection pool exhaustion
if (!fetchesDataRows && lastResolved > 0) {
List objects = dataContext.objectsFromDataRows(
rootEntity,
elements.subList(0, lastResolved),
info.isRefreshingObjects(),
info.isResolvingInherited());
for(int i = 0; i < lastResolved; i++) {
elements.set(i, objects.get(i));
}
}