Esempio n. 1
0
        private void FlushCollections(IEventSource session)
        {
            log.Debug("Processing unreferenced collections");

            ICollection list = IdentityMap.Entries(session.PersistenceContext.CollectionEntries);

            foreach (DictionaryEntry me in list)
            {
                CollectionEntry ce = (CollectionEntry)me.Value;
                if (!ce.IsReached && !ce.IsIgnore)
                {
                    Collections.ProcessUnreachableCollection((IPersistentCollection)me.Key, session);
                }
            }

            // Schedule updates to collections:

            log.Debug("Scheduling collection removes/(re)creates/updates");

            list = IdentityMap.Entries(session.PersistenceContext.CollectionEntries);
            ActionQueue actionQueue = session.ActionQueue;

            foreach (DictionaryEntry me in list)
            {
                IPersistentCollection coll = (IPersistentCollection)me.Key;
                CollectionEntry       ce   = (CollectionEntry)me.Value;

                if (ce.IsDorecreate)
                {
                    session.Interceptor.OnCollectionRecreate(coll, ce.CurrentKey);
                    actionQueue.AddAction(new CollectionRecreateAction(coll, ce.CurrentPersister, ce.CurrentKey, session));
                }
                if (ce.IsDoremove)
                {
                    session.Interceptor.OnCollectionRemove(coll, ce.LoadedKey);
                    actionQueue.AddAction(
                        new CollectionRemoveAction(coll, ce.LoadedPersister, ce.LoadedKey, ce.IsSnapshotEmpty(coll), session));
                }
                if (ce.IsDoupdate)
                {
                    session.Interceptor.OnCollectionUpdate(coll, ce.LoadedKey);
                    actionQueue.AddAction(
                        new CollectionUpdateAction(coll, ce.LoadedPersister, ce.LoadedKey, ce.IsSnapshotEmpty(coll), session));
                }
            }
            actionQueue.SortCollectionActions();
        }
Esempio n. 2
0
        protected virtual async Task FlushCollectionsAsync(IEventSource session, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            log.Debug("Processing unreferenced collections");

            ICollection list = IdentityMap.Entries(session.PersistenceContext.CollectionEntries);

            foreach (DictionaryEntry me in list)
            {
                CollectionEntry ce = (CollectionEntry)me.Value;
                if (!ce.IsReached && !ce.IsIgnore)
                {
                    await(Collections.ProcessUnreachableCollectionAsync((IPersistentCollection)me.Key, session, cancellationToken)).ConfigureAwait(false);
                }
            }

            // Schedule updates to collections:

            log.Debug("Scheduling collection removes/(re)creates/updates");

            list = IdentityMap.Entries(session.PersistenceContext.CollectionEntries);
            ActionQueue actionQueue = session.ActionQueue;

            foreach (DictionaryEntry me in list)
            {
                IPersistentCollection coll = (IPersistentCollection)me.Key;
                CollectionEntry       ce   = (CollectionEntry)me.Value;

                if (ce.IsDorecreate)
                {
                    session.Interceptor.OnCollectionRecreate(coll, ce.CurrentKey);
                    actionQueue.AddAction(new CollectionRecreateAction(coll, ce.CurrentPersister, ce.CurrentKey, session));
                }
                if (ce.IsDoremove)
                {
                    session.Interceptor.OnCollectionRemove(coll, ce.LoadedKey);
                    actionQueue.AddAction(
                        new CollectionRemoveAction(coll, ce.LoadedPersister, ce.LoadedKey, ce.IsSnapshotEmpty(coll), session));
                }
                if (ce.IsDoupdate)
                {
                    session.Interceptor.OnCollectionUpdate(coll, ce.LoadedKey);
                    actionQueue.AddAction(
                        new CollectionUpdateAction(coll, ce.LoadedPersister, ce.LoadedKey, ce.IsSnapshotEmpty(coll), session));
                }
            }
            actionQueue.SortCollectionActions();
        }