From: Michael D. <mik...@us...> - 2005-01-23 15:41:11
|
Update of /cvsroot/nhibernate/nhibernate/src/NHibernate/Transaction In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15817/Transaction Modified Files: TransactionFactory.cs Added Files: AdoTransaction.cs Removed Files: Transaction.cs Log Message: Moved EmptyInterceptor out of Configuration and into its own class. Renamed Transaction to AdoTransaction. --- NEW FILE: AdoTransaction.cs --- using System; using System.Data; using log4net; using NHibernate.Engine; namespace NHibernate.Transaction { /// <summary> /// Wraps an ADO.NET transaction to implements the <c>ITransaction</c> interface /// </summary> public class AdoTransaction : ITransaction { private static readonly ILog log = LogManager.GetLogger( typeof( AdoTransaction ) ); private ISessionImplementor session; private IDbTransaction trans; private bool begun; private bool committed; private bool rolledBack; /// <summary> /// /// </summary> /// <param name="session"></param> public AdoTransaction( ISessionImplementor session ) { this.session = session; } /// <summary> /// /// </summary> /// <param name="command"></param> public void Enlist( IDbCommand command ) { if( trans == null ) { if( log.IsWarnEnabled ) { if( command.Transaction != null ) { log.Warn( "set a nonnull IDbCommand.Transaction to null because the Session had no Transaction" ); } } command.Transaction = null; return; } else { if( log.IsWarnEnabled ) { // got into here because the command was being initialized and had a null Transaction - probably // don't need to be confused by that - just a normal part of initialization... if( command.Transaction != null && command.Transaction != trans ) { log.Warn( "The IDbCommand had a different Transaction than the Session. This can occur when " + "Disconnecting and Reconnecting Sessions because the PreparedCommand Cache is Session specific." ); } } command.Transaction = trans; } } /// <summary></summary> 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 ); } begun = true; } /// <summary></summary> 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(); } } /// <summary></summary> 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(); } } /// <summary></summary> public bool WasRolledBack { get { return rolledBack; } } /// <summary></summary> public bool WasCommitted { get { return committed; } } } } --- Transaction.cs DELETED --- Index: TransactionFactory.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Transaction/TransactionFactory.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** TransactionFactory.cs 31 Dec 2004 22:41:39 -0000 1.2 --- TransactionFactory.cs 23 Jan 2005 15:41:03 -0000 1.3 *************** *** 16,20 **** public ITransaction BeginTransaction( ISessionImplementor session ) { ! Transaction tx = new Transaction( session ); tx.Begin(); return tx; --- 16,20 ---- public ITransaction BeginTransaction( ISessionImplementor session ) { ! AdoTransaction tx = new AdoTransaction( session ); tx.Begin(); return tx; |