query.setFlushMode(FlushModeType.COMMIT);
List<SnapshotGroup> groups = query.getResultList();
createNewEntityManager();
for (Iterator<SnapshotGroup> i = groups.iterator(); i.hasNext();) {
SnapshotGroup group = i.next();
for (Iterator<Snapshot> is = group.getSnapshots().iterator(); is.hasNext();) {
Snapshot snapshot = is.next();
LOG.info("purging group=" + group.getId() + ", snapshot=" + snapshot.getId());
snapshot = getEntityManager().find(Snapshot.class, snapshot.getId());
getEntityManager().getTransaction().begin();
purgeFileMeasures(snapshot);
purgeRuleFailures(snapshot);
purgeFiles(snapshot);
purgeTendencies(snapshot);
getEntityManager().merge(snapshot);
getEntityManager().getTransaction().commit();
is.remove();
createNewEntityManager();
}
getEntityManager().getTransaction().begin();
// since SnapshotGroup are now detached must reload them to put them under the entitymanager control
group = getEntityManager().find(SnapshotGroup.class, group.getId());
group.setPurged(true);
getEntityManager().merge(group);
getEntityManager().getTransaction().commit();
i.remove();
createNewEntityManager();
}