use of org.hibernate.event.spi.FlushEntityEvent in project hibernate-orm by hibernate.
the class AbstractFlushingEventListener method flushEntities.
/**
* 1. detect any dirty entities
* 2. schedule any entity updates
* 3. search out any reachable collections
*/
private int flushEntities(final FlushEvent event, final PersistenceContext persistenceContext) throws HibernateException {
LOG.trace("Flushing entities and processing referenced collections");
final EventSource source = event.getSession();
final Iterable<FlushEntityEventListener> flushListeners = source.getFactory().getServiceRegistry().getService(EventListenerRegistry.class).getEventListenerGroup(EventType.FLUSH_ENTITY).listeners();
// Among other things, updateReachables() will recursively load all
// collections that are moving roles. This might cause entities to
// be loaded.
// So this needs to be safe from concurrent modification problems.
final Map.Entry<Object, EntityEntry>[] entityEntries = persistenceContext.reentrantSafeEntityEntries();
final int count = entityEntries.length;
for (Map.Entry<Object, EntityEntry> me : entityEntries) {
// Update the status of the object and if necessary, schedule an update
EntityEntry entry = me.getValue();
Status status = entry.getStatus();
if (status != Status.LOADING && status != Status.GONE) {
final FlushEntityEvent entityEvent = new FlushEntityEvent(source, me.getKey(), entry);
for (FlushEntityEventListener listener : flushListeners) {
listener.onFlushEntity(entityEvent);
}
}
}
source.getActionQueue().sortActions();
return count;
}
Aggregations