query.setMaxResults(maxEvents);
}
for (final ScrollableResults results = query.scroll(ScrollMode.FORWARD_ONLY); results.next(); ) {
final PersistentPortalEvent persistentPortalEvent = (PersistentPortalEvent)results.get(0);
final PortalEvent portalEvent = this.toPortalEvent(persistentPortalEvent.getEventData(), persistentPortalEvent.getEventType());
handler.apply(portalEvent);
persistentPortalEvent.setAggregated(true);
session.evict(persistentPortalEvent);
}
}