}
ExecutorAllCompletionService eacs = new ExecutorAllCompletionService(threadPool);
EntityManager emStream = emf.createEntityManager();
try {
EntityTransaction txStream = emStream.getTransaction();
ScrollableResults metadataKeys = null;
txStream.begin();
try {
long currentTime = timeService.wallClockTime();
Session session = emStream.unwrap(Session.class);
Criteria criteria = session.createCriteria(MetadataEntity.class).setReadOnly(true)
.add(Restrictions.le(MetadataEntity.EXPIRATION, currentTime)).setProjection(Projections.id());
if (setFetchSizeMinInteger) {
criteria.setFetchSize(Integer.MIN_VALUE);
}
metadataKeys = criteria.scroll(ScrollMode.FORWARD_ONLY);
ArrayList<MetadataEntityKey> batch = new ArrayList<MetadataEntityKey>((int) configuration.batchSize());
while (metadataKeys.next()) {
MetadataEntityKey mKey = (MetadataEntityKey) metadataKeys.get(0);
batch.add(mKey);
if (batch.size() == configuration.batchSize()) {
purgeBatch(batch, listener, eacs, currentTime);
batch.clear();
}
}
purgeBatch(batch, listener, eacs, currentTime);
txStream.commit();
} finally {
if (metadataKeys != null) metadataKeys.close();
if (txStream != null && txStream.isActive()) {
txStream.rollback();
}
}
} finally {