Exemplo n.º 1
0
        /// <summary>
        /// Attempts to flush and commit all changes made within this update context to the persistent store.
        /// </summary>
        /// <remarks>
        /// If this operation succeeds, the state of the persistent store will be syncrhonized with the state
        /// of all domain objects that are attached to this context, and the context can continue to be used
        /// for read operations only. If the operation fails, an exception will be thrown.
        /// </remarks>
        public void Commit()
        {
            try
            {
                // flush session prior to commit, this ensures that all entities are validated and changes
                // recorded by the interceptor
                FlushAndValidate();

                EventsHelper.Fire(PreCommit, this, EventArgs.Empty);

                // publish pre-commit to listeners
                var changeSetId        = Guid.NewGuid().ToString("N");
                var changeSetPublisher = new EntityChangeSetPublisher();
                changeSetPublisher.PreCommit(new EntityChangeSetPreCommitArgs(changeSetId, new EntityChangeSet(_interceptor.FullChangeSet), this));

                // flush session again, in case pre-commit listeners made modifications to entities in this context
                FlushAndValidate();

                // do audit
                AuditTransaction();

                // do final commit
                CommitTransaction();

                // publish post-commit to listeners
                changeSetPublisher.PostCommit(new EntityChangeSetPostCommitArgs(changeSetId, new EntityChangeSet(_interceptor.FullChangeSet)));
            }
            catch (Exception e)
            {
                HandleHibernateException(e, SR.ExceptionCommitFailure);
            }
        }
Exemplo n.º 2
0
		/// <summary>
		/// Attempts to flush and commit all changes made within this update context to the persistent store.
		/// </summary>
		/// <remarks>
		/// If this operation succeeds, the state of the persistent store will be syncrhonized with the state
		/// of all domain objects that are attached to this context, and the context can continue to be used
		/// for read operations only. If the operation fails, an exception will be thrown.
		/// </remarks>
		public void Commit()
		{
			try
			{
				// flush session prior to commit, this ensures that all entities are validated and changes
				// recorded by the interceptor
				FlushAndValidate();

				// publish pre-commit to listeners
				var changeSetPublisher = new EntityChangeSetPublisher();
				changeSetPublisher.PreCommit(new EntityChangeSetPreCommitArgs(new EntityChangeSet(_interceptor.FullChangeSet), this));

				// flush session again, in case pre-commit listeners made modifications to entities in this context
				FlushAndValidate();

				// do audit
				AuditTransaction();

				// do final commit
				CommitTransaction();

				// publish post-commit to listeners
				changeSetPublisher.PostCommit(new EntityChangeSetPostCommitArgs(new EntityChangeSet(_interceptor.FullChangeSet)));
			}
			catch (Exception e)
			{
				HandleHibernateException(e, SR.ExceptionCommitFailure);
			}
		}