Search in sources :

Example 1 with FlushEntityEventListener

use of org.hibernate.event.spi.FlushEntityEventListener 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;
}
Also used : Status(org.hibernate.engine.spi.Status) EventSource(org.hibernate.event.spi.EventSource) CollectionEntry(org.hibernate.engine.spi.CollectionEntry) EntityEntry(org.hibernate.engine.spi.EntityEntry) EntityEntry(org.hibernate.engine.spi.EntityEntry) FlushEntityEvent(org.hibernate.event.spi.FlushEntityEvent) FlushEntityEventListener(org.hibernate.event.spi.FlushEntityEventListener) Map(java.util.Map) IdentityMap(org.hibernate.internal.util.collections.IdentityMap) IdentityHashMap(java.util.IdentityHashMap) CascadePoint(org.hibernate.engine.internal.CascadePoint)

Aggregations

IdentityHashMap (java.util.IdentityHashMap)1 Map (java.util.Map)1 CascadePoint (org.hibernate.engine.internal.CascadePoint)1 CollectionEntry (org.hibernate.engine.spi.CollectionEntry)1 EntityEntry (org.hibernate.engine.spi.EntityEntry)1 Status (org.hibernate.engine.spi.Status)1 EventSource (org.hibernate.event.spi.EventSource)1 FlushEntityEvent (org.hibernate.event.spi.FlushEntityEvent)1 FlushEntityEventListener (org.hibernate.event.spi.FlushEntityEventListener)1 IdentityMap (org.hibernate.internal.util.collections.IdentityMap)1