You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ibatis.apache.org by gb...@apache.org on 2007/02/28 23:56:04 UTC

svn commit: r513043 - in /ibatis/trunk/cs/mapper: IBatisNet.Common/ IBatisNet.DataAccess/ IBatisNet.DataAccess/DaoSessionHandlers/ IBatisNet.DataMapper.Test/NUnit/SqlMapTests/ IBatisNet.DataMapper/

Author: gbayon
Date: Wed Feb 28 14:56:03 2007
New Revision: 513043

URL: http://svn.apache.org/viewvc?view=rev&rev=513043
Log:
- Fixed IBATISNET-212  Add the ability to track Open Transactions

Modified:
    ibatis/trunk/cs/mapper/IBatisNet.Common/IDalSession.cs
    ibatis/trunk/cs/mapper/IBatisNet.DataAccess/DaoSession.cs
    ibatis/trunk/cs/mapper/IBatisNet.DataAccess/DaoSessionHandlers/SimpleDaoSession.cs
    ibatis/trunk/cs/mapper/IBatisNet.DataAccess/DaoSessionHandlers/SqlMapDaoSession.cs
    ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/TransactionTest.cs
    ibatis/trunk/cs/mapper/IBatisNet.DataMapper/SqlMapSession.cs

Modified: ibatis/trunk/cs/mapper/IBatisNet.Common/IDalSession.cs
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.Common/IDalSession.cs?view=diff&rev=513043&r1=513042&r2=513043
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.Common/IDalSession.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.Common/IDalSession.cs Wed Feb 28 14:56:03 2007
@@ -62,6 +62,15 @@
 			get;
 		}
 
+        /// <summary>
+        /// Indicates if a transaction is open  on
+        /// the session.
+        /// </summary>
+        bool IsTransactionStart
+        {
+            get;
+        }
+
 		/// <summary>
 		/// Complete (commit) a transsaction
 		/// </summary>

Modified: ibatis/trunk/cs/mapper/IBatisNet.DataAccess/DaoSession.cs
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataAccess/DaoSession.cs?view=diff&rev=513043&r1=513042&r2=513043
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataAccess/DaoSession.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataAccess/DaoSession.cs Wed Feb 28 14:56:03 2007
@@ -62,34 +62,51 @@
 		#region IDalSession Members
 
 		#region Properties
-		/// <summary>
-		/// 
-		/// </summary>
+
+        /// <summary>
+        /// The data source use by the session.
+        /// </summary>
+        /// <value></value>
 		public abstract IDataSource DataSource
 		{
 			get;
 		}
-		/// <summary>
-		/// 
-		/// </summary>
+
+
+        /// <summary>
+        /// The Connection use by the session.
+        /// </summary>
+        /// <value></value>
 		public abstract IDbConnection Connection
 		{
 			get;
 		}
-		/// <summary>
-		/// 
-		/// </summary>
-		public abstract IDbTransaction Transaction
+
+
+        /// <summary>
+        /// Indicates if a transaction is open  on
+        /// the session.
+        /// </summary>
+        public abstract bool IsTransactionStart
 		{
 			get;
 		}
 
+        /// <summary>
+        /// The Transaction use by the session.
+        /// </summary>
+        /// <value></value>
+        public abstract IDbTransaction Transaction
+        {
+            get;
+        }
+
 		#endregion
 
 		#region Methods
 
 		/// <summary>
-		/// Complete (commit) a transsaction
+		/// Complete (commit) a transaction
 		/// </summary>
 		public abstract void Complete();
 

Modified: ibatis/trunk/cs/mapper/IBatisNet.DataAccess/DaoSessionHandlers/SimpleDaoSession.cs
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataAccess/DaoSessionHandlers/SimpleDaoSession.cs?view=diff&rev=513043&r1=513042&r2=513043
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataAccess/DaoSessionHandlers/SimpleDaoSession.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataAccess/DaoSessionHandlers/SimpleDaoSession.cs Wed Feb 28 14:56:03 2007
@@ -48,7 +48,7 @@
 		private static readonly ILog _logger = LogManager.GetLogger( MethodBase.GetCurrentMethod().DeclaringType );
 
 		private IDataSource _dataSource = null;
-		private bool _isOpenTransaction = false;
+		private bool _isTransactionOpen = false;
 		private bool _consistent = false;
 
 		/// <summary>
@@ -63,37 +63,54 @@
 		#endregion
 
 		#region Properties
-		/// <summary>
-		/// 
-		/// </summary>
+
+
+        /// <summary>
+        /// The data source use by the session.
+        /// </summary>
+        /// <value></value>
 		public override IDataSource DataSource
 		{
 			get { return _dataSource; }
 		}
-		/// <summary>
-		/// 
-		/// </summary>
+
+
+        /// <summary>
+        /// The Connection use by the session.
+        /// </summary>
+        /// <value></value>
 		public override IDbConnection Connection
 		{
 			get { return _connection; }
 		}
-		/// <summary>
-		/// 
-		/// </summary>
+
+
+        /// <summary>
+        /// The Transaction use by the session.
+        /// </summary>
+        /// <value></value>
 		public override IDbTransaction Transaction
 		{
 			get { return _transaction; }
 		}
 
+
+        /// <summary>
+        /// Indicates if a transaction is open  on
+        /// the session.
+        /// </summary>
+        /// <value></value>
+        public override bool IsTransactionStart
+        {
+            get { return _isTransactionOpen; }
+        }
+
 		/// <summary>
 		/// Changes the vote for transaction to commit (true) or to abort (false).
 		/// </summary>
 		private bool Consistent
 		{
-			set
-			{
-				_consistent = value;
-			}
+			set { _consistent = value; }
 		}
 		#endregion
 
@@ -212,7 +229,7 @@
 			{
 				_logger.Debug("Begin Transaction.");
 			}			
-			_isOpenTransaction = true;
+			_isTransactionOpen = true;
 		}
 
 		/// <summary>
@@ -236,7 +253,7 @@
 				{
 					_logger.Debug("Begin Transaction.");
 				}	
-				_isOpenTransaction = true;
+				_isTransactionOpen = true;
 			}
 		}
 
@@ -265,7 +282,7 @@
 			{
 				_logger.Debug("Begin Transaction.");
 			}
-			_isOpenTransaction = true;			
+			_isTransactionOpen = true;			
 		}
 
 		/// <summary>
@@ -303,7 +320,7 @@
 				{
 					_logger.Debug("Begin Transaction.");
 				}	
-				_isOpenTransaction = true;
+				_isTransactionOpen = true;
 			}			
 		}
 
@@ -315,13 +332,16 @@
 		/// </remarks>
 		public override void CommitTransaction()
 		{
-			_transaction.Commit();
 			if (_logger.IsDebugEnabled)
 			{
 				_logger.Debug("Commit Transaction");
-			}			
+			}		
+	
+			_transaction.Commit();
 			_transaction.Dispose();
 			_transaction= null;
+            _isTransactionOpen = false;
+
 			if (_connection.State != ConnectionState.Closed)
 			{
 				CloseConnection();
@@ -334,13 +354,15 @@
 		/// <param name="closeConnection">Close the connection</param>
 		public override void CommitTransaction(bool closeConnection)
 		{
-			_transaction.Commit();
 			if (_logger.IsDebugEnabled)
 			{
 				_logger.Debug("Commit Transaction");
 			}
+
+			_transaction.Commit();
 			_transaction.Dispose();
 			_transaction= null;
+            _isTransactionOpen = false;
 
 			if (closeConnection)
 			{
@@ -358,13 +380,16 @@
 		/// </remarks>
 		public override void RollBackTransaction()
 		{
-			_transaction.Rollback();
 			if (_logger.IsDebugEnabled)
 			{
 				_logger.Debug("RollBack Transaction");
 			}
+
+			_transaction.Rollback();
 			_transaction.Dispose();
 			_transaction = null;
+            _isTransactionOpen = false;
+
 			if (_connection.State != ConnectionState.Closed)
 			{
 				CloseConnection();
@@ -377,13 +402,15 @@
 		/// <param name="closeConnection">Close the connection</param>
 		public override void RollBackTransaction(bool closeConnection)
 		{
-			_transaction.Rollback();
 			if (_logger.IsDebugEnabled)
 			{
 				_logger.Debug("RollBack Transaction");
 			}
+
+			_transaction.Rollback();
 			_transaction.Dispose();
 			_transaction = null;
+            _isTransactionOpen = false;
 
 			if (closeConnection)
 			{
@@ -480,7 +507,7 @@
 				_logger.Debug("Dispose DaoSession");
 			}
 
-			if (_isOpenTransaction == false)
+			if (_isTransactionOpen == false)
 			{
 				if (_connection.State != ConnectionState.Closed)
 				{
@@ -492,12 +519,14 @@
 				if (_consistent)
 				{
 					daoManager.CommitTransaction();
+				    _isTransactionOpen = false;
 				}
 				else
 				{
 					if (_connection.State != ConnectionState.Closed)
 					{
 						daoManager.RollBackTransaction();
+                        _isTransactionOpen = false;
 					}
 				}
 			}

Modified: ibatis/trunk/cs/mapper/IBatisNet.DataAccess/DaoSessionHandlers/SqlMapDaoSession.cs
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataAccess/DaoSessionHandlers/SqlMapDaoSession.cs?view=diff&rev=513043&r1=513042&r2=513043
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataAccess/DaoSessionHandlers/SqlMapDaoSession.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataAccess/DaoSessionHandlers/SqlMapDaoSession.cs Wed Feb 28 14:56:03 2007
@@ -44,35 +44,57 @@
 		#endregion
 
 		#region Properties
-		/// <summary>
-		/// 
-		/// </summary>
+
+
+        /// <summary>
+        /// Gets the SQL map.
+        /// </summary>
+        /// <value>The SQL map.</value>
 		public ISqlMapper SqlMap
 		{
 			get { return _sqlMap; }
 		}
-		/// <summary>
-		/// 
-		/// </summary>
+
+
+        /// <summary>
+        /// The data source use by the session.
+        /// </summary>
+        /// <value></value>
 		public override IDataSource DataSource
 		{
 			get { return _sqlMap.LocalSession.DataSource; }
 		}
-		/// <summary>
-		/// 
-		/// </summary>
+
+
+        /// <summary>
+        /// The Connection use by the session.
+        /// </summary>
+        /// <value></value>
 		public override IDbConnection Connection
 		{
 			get { return _sqlMap.LocalSession.Connection; }
 		}
-		/// <summary>
-		/// 
-		/// </summary>
+
+
+        /// <summary>
+        /// The Transaction use by the session.
+        /// </summary>
+        /// <value></value>
 		public override IDbTransaction Transaction
 		{
 			get { return _sqlMap.LocalSession.Transaction; }
-		}	
-	
+		}
+
+        /// <summary>
+        /// Indicates if a transaction is open  on
+        /// the session.
+        /// </summary>
+        /// <value></value>
+        public override bool IsTransactionStart
+        {
+            get { return _sqlMap.LocalSession.IsTransactionStart; }
+        }
+
 		#endregion
 
 		#region Constructor (s) / Destructor

Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/TransactionTest.cs
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/TransactionTest.cs?view=diff&rev=513043&r1=513042&r2=513043
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/TransactionTest.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/TransactionTest.cs Wed Feb 28 14:56:03 2007
@@ -40,6 +40,38 @@
 
 		#region Transaction tests
 
+        /// <summary>
+        /// Test IsTransactionStart
+        /// </summary>
+        [Test]
+        public void TestIsTransactionStartProperty()
+        {
+            Account account = NewAccount6();
+
+            sqlMap.BeginTransaction();
+            sqlMap.Insert("InsertAccountViaParameterMap", account);
+            InsertNewAccount();
+            sqlMap.CommitTransaction();
+
+        }
+
+        public void InsertNewAccount()
+        {
+            Account account = NewAccount6();
+            account.Id = 7;
+            bool existingTransaction = (sqlMap.LocalSession != null && !sqlMap.LocalSession.IsTransactionStart);
+
+            if (existingTransaction)
+            {
+                 sqlMap.BeginTransaction();
+            }
+            sqlMap.Insert("InsertAccountViaParameterMap", account);
+            if (existingTransaction)
+            {
+                sqlMap.CommitTransaction();
+            }
+        }
+
 		/// <summary>
 		/// Test BeginTransaction, CommitTransaction
 		/// </summary>

Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper/SqlMapSession.cs
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/SqlMapSession.cs?view=diff&rev=513043&r1=513042&r2=513043
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/SqlMapSession.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/SqlMapSession.cs Wed Feb 28 14:56:03 2007
@@ -65,7 +65,7 @@
         #region IDalSession Members
 
         #region Fields
-        private bool _isOpenTransaction = false;
+        private bool _isTransactionOpen = false;
 		/// <summary>
 		/// Changes the vote to commit (true) or to abort (false) in transsaction
 		/// </summary>
@@ -84,48 +84,63 @@
 
 		#region Properties
 
-		/// <summary>
-		/// 
-		/// </summary>
+
+        /// <summary>
+        /// Gets the SQL mapper.
+        /// </summary>
+        /// <value>The SQL mapper.</value>
 		public ISqlMapper SqlMapper
 		{
 			get { return _sqlMapper; }
 		}
 
-		/// <summary>
-		/// 
-		/// </summary>
+
+        /// <summary>
+        /// The data source use by the session.
+        /// </summary>
+        /// <value></value>
 		public IDataSource DataSource
 		{
 			get { return _dataSource; }
 		}
 
-		/// <summary>
-		/// 
-		/// </summary>
+
+        /// <summary>
+        /// The Connection use by the session.
+        /// </summary>
+        /// <value></value>
 		public IDbConnection Connection
 		{
 			get { return _connection; }
 		}
 
-		/// <summary>
-		/// 
-		/// </summary>
+
+        /// <summary>
+        /// The Transaction use by the session.
+        /// </summary>
+        /// <value></value>
 		public IDbTransaction Transaction
 		{
 			get { return _transaction; }
 		}
 
+        /// <summary>
+        /// Indicates if a transaction is open  on
+        /// the session.
+        /// </summary>
+        public bool IsTransactionStart
+        {
+            get { return _isTransactionOpen; }
+        }
+
 		/// <summary>
 		/// Changes the vote for transaction to commit (true) or to abort (false).
 		/// </summary>
 		private bool Consistent
 		{
-			set
-			{
-				_consistent = value;
-			}
+			set { _consistent = value; }
 		}
+
 		#endregion
 
 		#region Methods
@@ -245,7 +260,7 @@
 			{
 				_logger.Debug("Begin Transaction.");
 			}
-			_isOpenTransaction = true;
+			_isTransactionOpen = true;
 		}
 
 		/// <summary>
@@ -269,7 +284,7 @@
 				{
 					_logger.Debug("Begin Transaction.");
 				}
-				_isOpenTransaction = true;
+				_isTransactionOpen = true;
 			}
 		}
 
@@ -300,7 +315,7 @@
 			{
 				_logger.Debug("Begin Transaction.");
 			}
-			_isOpenTransaction = true;			
+			_isTransactionOpen = true;			
 		}
 
 		/// <summary>
@@ -338,7 +353,7 @@
 				{
 					_logger.Debug("Begin Transaction.");
 				}
-				_isOpenTransaction = true;
+				_isTransactionOpen = true;
 			}			
 		}
 
@@ -356,6 +371,8 @@
 			}
 			_transaction.Commit();
 			_transaction.Dispose();
+            _isTransactionOpen = false;
+
 			if (_connection.State != ConnectionState.Closed)
 			{
 				this.CloseConnection();
@@ -374,12 +391,14 @@
 			}
 			else
 			{
-				_transaction.Commit();
 				if (_logger.IsDebugEnabled)
 				{
 					_logger.Debug("Commit Transaction.");
-				}
+				}				
+                _transaction.Commit();
 				_transaction.Dispose();
+                _transaction = null;
+                _isTransactionOpen = false;
 			}
 		}
 
@@ -391,13 +410,14 @@
 		/// </remarks>
 		public void RollBackTransaction()
 		{
-			_transaction.Rollback();
 			if (_logger.IsDebugEnabled)
 			{
 				_logger.Debug("RollBack Transaction.");
 			}
+			_transaction.Rollback();
 			_transaction.Dispose();
 			_transaction = null;
+            _isTransactionOpen = false;
 			if (_connection.State != ConnectionState.Closed)
 			{
 				this.CloseConnection();
@@ -423,6 +443,7 @@
 				_transaction.Rollback();
 				_transaction.Dispose();
 				_transaction = null;
+                _isTransactionOpen = false;
 			}
 		}
 
@@ -519,7 +540,7 @@
 			{
 				_logger.Debug("Dispose SqlMapSession");
 			}
-			if (_isOpenTransaction == false)
+			if (_isTransactionOpen == false)
 			{
 				if (_connection.State != ConnectionState.Closed)
 				{
@@ -531,12 +552,14 @@
 				if (_consistent)
 				{
 					_sqlMapper.CommitTransaction();
+                    _isTransactionOpen = false;
 				}
 				else
 				{
 					if (_connection.State != ConnectionState.Closed)
 					{
 						_sqlMapper.RollBackTransaction();
+                        _isTransactionOpen = false;
 					}
 				}
 			}