From: Michael D. <mik...@us...> - 2004-08-28 04:07:37
|
Update of /cvsroot/nhibernate/nhibernate/src/NHibernate/Transaction In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28447/src/NHibernate/Transaction Modified Files: Transaction.cs Log Message: Added code so BeginTransaction(IsolationLevel) works with hibernate.connection.isolation configuration Index: Transaction.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Transaction/Transaction.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Transaction.cs 10 Feb 2004 18:40:53 -0000 1.2 --- Transaction.cs 28 Aug 2004 04:07:05 -0000 1.3 *************** *** 1,7 **** using System; using System.Data; - using NHibernate.Engine; - namespace NHibernate.Transaction { /// <summary> /// Wraps an ADO.NET transaction to implements the <c>ITransaction</c> interface --- 1,8 ---- using System; using System.Data; + using NHibernate.Engine; + namespace NHibernate.Transaction + { /// <summary> /// Wraps an ADO.NET transaction to implements the <c>ITransaction</c> interface *************** *** 12,16 **** /// for JDBC Transactions or JTA Transactions. /// </remarks> ! public class Transaction : ITransaction { private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(Transaction)); private ISessionImplementor session; --- 13,18 ---- /// for JDBC Transactions or JTA Transactions. /// </remarks> ! public class Transaction : ITransaction ! { private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(Transaction)); private ISessionImplementor session; *************** *** 20,37 **** private bool rolledBack; ! public Transaction(ISessionImplementor session) { this.session = session; } ! public IDbTransaction AdoTransaction { get { return trans; } } ! public void Begin() { log.Debug("begin"); ! try { ! trans = session.Connection.BeginTransaction(); ! } catch (Exception e) { log.Error("Begin transaction failed", e); throw new TransactionException("Begin failed with SQL exception", e); --- 22,53 ---- private bool rolledBack; ! public Transaction(ISessionImplementor session) ! { this.session = session; } ! public IDbTransaction AdoTransaction ! { get { return trans; } } ! public void Begin() ! { log.Debug("begin"); ! try ! { ! IsolationLevel isolation = session.Factory.Isolation; ! if( isolation==IsolationLevel.Unspecified ) ! { ! trans = session.Connection.BeginTransaction(); ! } ! else ! { ! trans = session.Connection.BeginTransaction( isolation ); ! } ! } ! catch( Exception e ) ! { log.Error("Begin transaction failed", e); throw new TransactionException("Begin failed with SQL exception", e); *************** *** 41,83 **** } ! public void Commit() { ! if (!begun) throw new TransactionException("Transaction not successfully started"); log.Debug("commit"); ! try { ! if ( session.FlushMode != FlushMode.Never ) session.Flush(); ! try { trans.Commit(); committed = true; ! } catch (Exception e) { log.Error("Commit failed", e); throw new TransactionException("Commit failed with SQL exception", e); } ! } finally { session.AfterTransactionCompletion(); } } ! public void Rollback() { ! if (!begun) throw new TransactionException("Transaction not successfully started"); log.Debug("rollback"); ! try { trans.Rollback(); rolledBack = true; ! } catch(Exception e) { log.Error("Rollback failed", e); throw new TransactionException("Rollback failed with SQL Exception", e); ! } finally { session.AfterTransactionCompletion(); } } ! public bool WasRolledBack { get { return rolledBack; } } ! public bool WasCommitted { get { return committed; } } --- 57,123 ---- } ! public void Commit() ! { ! if (!begun) ! { ! throw new TransactionException("Transaction not successfully started"); ! } log.Debug("commit"); ! try ! { ! if( session.FlushMode!=FlushMode.Never ) ! { ! session.Flush(); ! } ! try ! { trans.Commit(); committed = true; ! } ! catch( Exception e ) ! { log.Error("Commit failed", e); throw new TransactionException("Commit failed with SQL exception", e); } ! } ! finally ! { session.AfterTransactionCompletion(); } } ! public void Rollback() ! { ! if (!begun) ! { ! throw new TransactionException("Transaction not successfully started"); ! } log.Debug("rollback"); ! try ! { trans.Rollback(); rolledBack = true; ! } ! catch( Exception e ) ! { log.Error("Rollback failed", e); throw new TransactionException("Rollback failed with SQL Exception", e); ! } ! finally ! { session.AfterTransactionCompletion(); } } ! public bool WasRolledBack ! { get { return rolledBack; } } ! public bool WasCommitted ! { get { return committed; } } |