Search in sources :

Example 1 with CollectionRecreateAction

use of org.hibernate.action.internal.CollectionRecreateAction in project hibernate-orm by hibernate.

the class AbstractFlushingEventListener method flushCollections.

/**
	 * process any unreferenced collections and then inspect all known collections,
	 * scheduling creates/removes/updates
	 */
@SuppressWarnings("unchecked")
private int flushCollections(final EventSource session, final PersistenceContext persistenceContext) throws HibernateException {
    LOG.trace("Processing unreferenced collections");
    final Map.Entry<PersistentCollection, CollectionEntry>[] entries = IdentityMap.concurrentEntries((Map<PersistentCollection, CollectionEntry>) persistenceContext.getCollectionEntries());
    final int count = entries.length;
    for (Map.Entry<PersistentCollection, CollectionEntry> me : entries) {
        CollectionEntry ce = me.getValue();
        if (!ce.isReached() && !ce.isIgnore()) {
            Collections.processUnreachableCollection(me.getKey(), session);
        }
    }
    // Schedule updates to collections:
    LOG.trace("Scheduling collection removes/(re)creates/updates");
    ActionQueue actionQueue = session.getActionQueue();
    for (Map.Entry<PersistentCollection, CollectionEntry> me : IdentityMap.concurrentEntries((Map<PersistentCollection, CollectionEntry>) persistenceContext.getCollectionEntries())) {
        PersistentCollection coll = me.getKey();
        CollectionEntry ce = me.getValue();
        if (ce.isDorecreate()) {
            session.getInterceptor().onCollectionRecreate(coll, ce.getCurrentKey());
            actionQueue.addAction(new CollectionRecreateAction(coll, ce.getCurrentPersister(), ce.getCurrentKey(), session));
        }
        if (ce.isDoremove()) {
            session.getInterceptor().onCollectionRemove(coll, ce.getLoadedKey());
            actionQueue.addAction(new CollectionRemoveAction(coll, ce.getLoadedPersister(), ce.getLoadedKey(), ce.isSnapshotEmpty(coll), session));
        }
        if (ce.isDoupdate()) {
            session.getInterceptor().onCollectionUpdate(coll, ce.getLoadedKey());
            actionQueue.addAction(new CollectionUpdateAction(coll, ce.getLoadedPersister(), ce.getLoadedKey(), ce.isSnapshotEmpty(coll), session));
        }
        // todo : I'm not sure the !wasInitialized part should really be part of this check
        if (!coll.wasInitialized() && coll.hasQueuedOperations()) {
            actionQueue.addAction(new QueuedOperationCollectionAction(coll, ce.getLoadedPersister(), ce.getLoadedKey(), session));
        }
    }
    actionQueue.sortCollectionActions();
    return count;
}
Also used : PersistentCollection(org.hibernate.collection.spi.PersistentCollection) ActionQueue(org.hibernate.engine.spi.ActionQueue) CollectionEntry(org.hibernate.engine.spi.CollectionEntry) EntityEntry(org.hibernate.engine.spi.EntityEntry) CollectionEntry(org.hibernate.engine.spi.CollectionEntry) QueuedOperationCollectionAction(org.hibernate.action.internal.QueuedOperationCollectionAction) CollectionRecreateAction(org.hibernate.action.internal.CollectionRecreateAction) CollectionRemoveAction(org.hibernate.action.internal.CollectionRemoveAction) CollectionUpdateAction(org.hibernate.action.internal.CollectionUpdateAction) Map(java.util.Map) IdentityMap(org.hibernate.internal.util.collections.IdentityMap) CascadePoint(org.hibernate.engine.internal.CascadePoint)

Aggregations

Map (java.util.Map)1 CollectionRecreateAction (org.hibernate.action.internal.CollectionRecreateAction)1 CollectionRemoveAction (org.hibernate.action.internal.CollectionRemoveAction)1 CollectionUpdateAction (org.hibernate.action.internal.CollectionUpdateAction)1 QueuedOperationCollectionAction (org.hibernate.action.internal.QueuedOperationCollectionAction)1 PersistentCollection (org.hibernate.collection.spi.PersistentCollection)1 CascadePoint (org.hibernate.engine.internal.CascadePoint)1 ActionQueue (org.hibernate.engine.spi.ActionQueue)1 CollectionEntry (org.hibernate.engine.spi.CollectionEntry)1 EntityEntry (org.hibernate.engine.spi.EntityEntry)1 IdentityMap (org.hibernate.internal.util.collections.IdentityMap)1