throw new IllegalStateException("Size of group changed from " + groupSize + " to " + count
+ " - please retry the operation.");
}
// Configurations are very expensive to load, so load 'em in chunks to ease the strain on the DB.
PageControl pageControl = new PageControl(0, 20);
Query query = PersistenceUtility.createQueryWithOrderBy(entityManager,
Configuration.QUERY_GET_RESOURCE_CONFIG_MAP_BY_GROUP_ID, new OrderingField("r.id", PageOrdering.ASC));
query.setParameter("resourceGroupId", compatibleGroup.getId());
Map<Integer, Configuration> results = new HashMap<Integer, Configuration>((int) count);
int rowsProcessed = 0;
while (true) {
PersistenceUtility.setDataPage(query, pageControl); // retrieve one page at a time
List<Object[]> pagedResults = query.getResultList();
if (pagedResults.size() <= 0) {
break;
}
for (Object[] result : pagedResults) {
results.put((Integer) result[0], (Configuration) result[1]);
}
rowsProcessed += pagedResults.size();
if (rowsProcessed >= count) {
break;
}
pageControl.setPageNumber(pageControl.getPageNumber() + 1); // advance the page
}
return results;
}