public override void Execute() { object id = Key; ISessionImplementor session = Session; ICollectionPersister persister = Persister; IPersistentCollection collection = Collection; bool affectedByFilters = persister.IsAffectedByEnabledFilters(session); bool statsEnabled = session.Factory.Statistics.IsStatisticsEnabled; Stopwatch stopwatch = null; if (statsEnabled) { stopwatch = Stopwatch.StartNew(); } PreUpdate(); if (!collection.WasInitialized) { if (!collection.HasQueuedOperations) { throw new AssertionFailure("no queued adds"); } //do nothing - we only need to notify the cache... } else if (!affectedByFilters && collection.Empty) { if (!emptySnapshot) { persister.Remove(id, session); } } else if (collection.NeedsRecreate(persister)) { if (affectedByFilters) { throw new HibernateException("cannot recreate collection while filter is enabled: " + MessageHelper.CollectionInfoString(persister, collection, id, session)); } if (!emptySnapshot) { persister.Remove(id, session); } persister.Recreate(collection, id, session); } else { persister.DeleteRows(collection, id, session); persister.UpdateRows(collection, id, session); persister.InsertRows(collection, id, session); } Session.PersistenceContext.GetCollectionEntry(collection).AfterAction(collection); Evict(); PostUpdate(); if (statsEnabled) { stopwatch.Stop(); Session.Factory.StatisticsImplementor.UpdateCollection(Persister.Role, stopwatch.Elapsed); } }
public override async Task ExecuteAsync(CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); object id = await(GetKeyAsync(cancellationToken)).ConfigureAwait(false); ISessionImplementor session = Session; ICollectionPersister persister = Persister; IPersistentCollection collection = Collection; bool affectedByFilters = persister.IsAffectedByEnabledFilters(session); bool statsEnabled = session.Factory.Statistics.IsStatisticsEnabled; Stopwatch stopwatch = null; if (statsEnabled) { stopwatch = Stopwatch.StartNew(); } await(PreUpdateAsync(cancellationToken)).ConfigureAwait(false); if (!collection.WasInitialized) { if (!collection.HasQueuedOperations) { throw new AssertionFailure("no queued adds"); } //do nothing - we only need to notify the cache... } else if (!affectedByFilters && collection.Empty) { if (!emptySnapshot) { await(persister.RemoveAsync(id, session, cancellationToken)).ConfigureAwait(false); } } else if (collection.NeedsRecreate(persister)) { if (affectedByFilters) { throw new HibernateException("cannot recreate collection while filter is enabled: " + MessageHelper.CollectionInfoString(persister, collection, id, session)); } if (!emptySnapshot) { await(persister.RemoveAsync(id, session, cancellationToken)).ConfigureAwait(false); } await(persister.RecreateAsync(collection, id, session, cancellationToken)).ConfigureAwait(false); } else { await(persister.DeleteRowsAsync(collection, id, session, cancellationToken)).ConfigureAwait(false); await(persister.UpdateRowsAsync(collection, id, session, cancellationToken)).ConfigureAwait(false); await(persister.InsertRowsAsync(collection, id, session, cancellationToken)).ConfigureAwait(false); } var entry = Session.PersistenceContext.GetCollectionEntry(collection); entry.AfterAction(collection); await(EvictAsync(cancellationToken)).ConfigureAwait(false); await(PostUpdateAsync(cancellationToken)).ConfigureAwait(false); if (statsEnabled) { stopwatch.Stop(); Session.Factory.StatisticsImplementor.UpdateCollection(Persister.Role, stopwatch.Elapsed); } }