예제 #1
0
 public void Rollback(SinglePhaseEnlistment singlePhaseEnlistment)
 {
     // try to rollback the transaction with either the
     // ADO.NET transaction or the callbacks that managed the
     // two phase commit transaction.
     if (_npgsqlTx != null)
     {
         _npgsqlTx.Rollback();
         _npgsqlTx.Dispose();
         _npgsqlTx = null;
         singlePhaseEnlistment.Aborted();
     }
     else if (_callbacks != null)
     {
         if (_rm != null)
         {
             _rm.RollbackWork(_callbacks.GetName());
             singlePhaseEnlistment.Aborted();
         }
         else
         {
             _callbacks.RollbackTransaction();
             singlePhaseEnlistment.Aborted();
         }
         _callbacks = null;
     }
     _inTransaction = false;
 }
예제 #2
0
 public void SinglePhaseCommit(SinglePhaseEnlistment singlePhaseEnlistment)
 {
     if (_npgsqlTx != null)
     {
         _npgsqlTx.Commit();
         _npgsqlTx.Dispose();
         _npgsqlTx = null;
         singlePhaseEnlistment.Committed();
     }
     else if (_callbacks != null)
     {
         if (_rm != null)
         {
             _rm.CommitWork(_callbacks.GetName());
             singlePhaseEnlistment.Committed();
         }
         else
         {
             _callbacks.CommitTransaction();
             singlePhaseEnlistment.Committed();
         }
         _callbacks = null;
     }
     _inTransaction = false;
 }
예제 #3
0
 /// <summary>
 /// Used when a connection is closed
 /// </summary>
 public void Prepare()
 {
     if (_inTransaction)
     {
         // may not be null if Promote or Enlist is called first
         if (_callbacks == null)
         {
             _callbacks = new NpgsqlTransactionCallbacks(_connection);
         }
         _callbacks.PrepareTransaction();
         if (_npgsqlTx != null)
         {
             // cancel the NpgsqlTransaction since this will
             // be handled by a two phase commit.
             _npgsqlTx.Cancel();
             _npgsqlTx.Dispose();
             _npgsqlTx = null;
         }
     }
 }
예제 #4
0
 public byte[] Promote()
 {
     _rm = CreateResourceManager();
     // may not be null if Prepare or Enlist is called first
     if (_callbacks == null)
     {
         _callbacks = new NpgsqlTransactionCallbacks(_connection);
     }
     byte[] token = _rm.Promote(_callbacks);
     // mostly likely case for this is the transaction has been prepared.
     if (_npgsqlTx != null)
     {
         // cancel the NpgsqlTransaction since this will
         // be handled by a two phase commit.
         _npgsqlTx.Cancel();
         _npgsqlTx.Dispose();
         _npgsqlTx = null;
     }
     return(token);
 }
		/// <summary>
		/// Used when a connection is closed
		/// </summary>
		public void Prepare()
		{
			if (_inTransaction)
			{
				// may not be null if Promote or Enlist is called first
				if (_callbacks == null)
				{
					_callbacks = new NpgsqlTransactionCallbacks(_connection);
				}
				_callbacks.PrepareTransaction();
				if (_npgsqlTx != null)
				{
					// cancel the NpgsqlTransaction since this will
					// be handled by a two phase commit.
					_npgsqlTx.Cancel();
					_npgsqlTx.Dispose();
					_npgsqlTx = null;
				}
			}
		}
예제 #6
0
 public void Enlist(Transaction tx)
 {
     if (tx != null)
     {
         _isolationLevel = tx.IsolationLevel;
         if (!tx.EnlistPromotableSinglePhase(this))
         {
             // must already have a durable resource
             // start transaction
             _npgsqlTx      = _connection.BeginTransaction(ConvertIsolationLevel(_isolationLevel));
             _inTransaction = true;
             _rm            = CreateResourceManager();
             _callbacks     = new NpgsqlTransactionCallbacks(_connection);
             _rm.Enlist(_callbacks, TransactionInterop.GetTransmitterPropagationToken(tx));
             // enlisted in distributed transaction
             // disconnect and cleanup local transaction
             _npgsqlTx.Cancel();
             _npgsqlTx.Dispose();
             _npgsqlTx = null;
         }
     }
 }
		public void Enlist(Transaction tx)
		{
			if (tx != null)
			{
				_isolationLevel = tx.IsolationLevel;
				if (!tx.EnlistPromotableSinglePhase(this))
				{
					// must already have a durable resource
					// start transaction
					_npgsqlTx = _connection.BeginTransaction(ConvertIsolationLevel(_isolationLevel));
					_inTransaction = true;
					_rm = CreateResourceManager();
					_callbacks = new NpgsqlTransactionCallbacks(_connection);
					_rm.Enlist(_callbacks, TransactionInterop.GetTransmitterPropagationToken(tx));
					// enlisted in distributed transaction
					// disconnect and cleanup local transaction
					_npgsqlTx.Cancel();
					_npgsqlTx.Dispose();
					_npgsqlTx = null;
				}
			}
		}
		public void Rollback(SinglePhaseEnlistment singlePhaseEnlistment)
		{
			// try to rollback the transaction with either the
			// ADO.NET transaction or the callbacks that managed the
			// two phase commit transaction.
			if (_npgsqlTx != null)
			{
				_npgsqlTx.Rollback();
				_npgsqlTx.Dispose();
				_npgsqlTx = null;
				singlePhaseEnlistment.Aborted();
			}
			else if (_callbacks != null)
			{
				if (_rm != null)
				{
					_rm.RollbackWork(_callbacks.GetName());
					singlePhaseEnlistment.Aborted();
				}
				else
				{
					_callbacks.RollbackTransaction();
					singlePhaseEnlistment.Aborted();
				}
				_callbacks = null;
			}
			_inTransaction = false;
		}
		public byte[] Promote()
		{
			_rm = CreateResourceManager();
			// may not be null if Prepare or Enlist is called first
			if (_callbacks == null)
			{
				_callbacks = new NpgsqlTransactionCallbacks(_connection);
			}
			byte[] token = _rm.Promote(_callbacks);
			// mostly likely case for this is the transaction has been prepared.
			if (_npgsqlTx != null)
			{
				// cancel the NpgsqlTransaction since this will
				// be handled by a two phase commit.
				_npgsqlTx.Cancel();
				_npgsqlTx.Dispose();
				_npgsqlTx = null;
			}
			return token;
		}
		public void SinglePhaseCommit(SinglePhaseEnlistment singlePhaseEnlistment)
		{
			if (_npgsqlTx != null)
			{
				_npgsqlTx.Commit();
				_npgsqlTx.Dispose();
				_npgsqlTx = null;
				singlePhaseEnlistment.Committed();
			}
			else if (_callbacks != null)
			{
				if (_rm != null)
				{
					_rm.CommitWork(_callbacks.GetName());
					singlePhaseEnlistment.Committed();
				}
				else
				{
					_callbacks.CommitTransaction();
					singlePhaseEnlistment.Committed();
				}
				_callbacks = null;
			}
			_inTransaction = false;
		}