Example #1
0
        /// <summary></summary>
        public override void Execute()
        {
            if (!_collection.WasInitialized)
            {
                if (!_collection.HasQueuedAdds)
                {
                    throw new AssertionFailure("bug processing queued adds");
                }

                // do nothing - collection was not initialized
                // we only need to notify the cache...
            }
            else if (_collection.Empty)
            {
                // the collection had all elements removed - check to see if it
                // was empty when it was loaded or if the contents were actually
                // deleted
                if (!_emptySnapshot)
                {
                    Persister.Remove(Id, Session);
                }
            }
            else if (_collection.NeedsRecreate(Persister))
            {
                // certain collections (Bag) have to be recreated in the db each
                // time - if the snapshot was not empty then there are some existing
                // rows that need to be removed.
                if (!_emptySnapshot)
                {
                    Persister.Remove(Id, Session);
                }

                Persister.Recreate(_collection, Id, Session);
            }
            else
            {
                // this is a normal collection that needs to have its state
                // synched with the database.
                Persister.DeleteRows(_collection, Id, Session);
                Persister.UpdateRows(_collection, Id, Session);
                Persister.InsertRows(_collection, Id, Session);
            }
            Evict();
        }