public SnapshotGroup getLastUnprocessedGroup(Integer projectId, long delayInMs, long roofTime ) throws NoResultException {
Query query = manager.createNamedQuery( SnapshotGroup.SQL_SELECT_LAST_UNPROCESSED );
query.setParameter("idProject", projectId);
List snapshot = query.getResultList();
if ( snapshot.size() == 0 ) throw new NoResultException();
roofTime = roofTime + delayInMs;
for (Object aSnapshot : snapshot) {
SnapshotGroup grp = (SnapshotGroup) aSnapshot;
if ( grp.getCreatedAt().getTime() < roofTime ) {
return grp;
}
}
throw new NoResultException();
}