From: Michael D. <mik...@us...> - 2005-01-30 19:36:27
|
Update of /cvsroot/nhibernate/nhibernate/src/NHibernate/Transaction In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32147/NHibernate/Transaction Modified Files: AdoTransaction.cs Log Message: Implemented IDisposable according to standard .net pattern Added some more xml comments to Connection namespace. Index: AdoTransaction.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Transaction/AdoTransaction.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** AdoTransaction.cs 23 Jan 2005 15:41:03 -0000 1.1 --- AdoTransaction.cs 30 Jan 2005 19:36:16 -0000 1.2 *************** *** 7,11 **** { /// <summary> ! /// Wraps an ADO.NET transaction to implements the <c>ITransaction</c> interface /// </summary> public class AdoTransaction : ITransaction --- 7,12 ---- { /// <summary> ! /// Wraps an ADO.NET <see cref="IDbTransaction"/> to implement ! /// the <see cref="ITransaction" /> interface. /// </summary> public class AdoTransaction : ITransaction *************** *** 19,25 **** /// <summary> ! /// /// </summary> ! /// <param name="session"></param> public AdoTransaction( ISessionImplementor session ) { --- 20,26 ---- /// <summary> ! /// Initializes a new instance of the <see cref="AdoTransaction"/> class. /// </summary> ! /// <param name="session">The <see cref="ISessionImplementor"/> the Transaction is for.</param> public AdoTransaction( ISessionImplementor session ) { *************** *** 28,34 **** /// <summary> ! /// /// </summary> ! /// <param name="command"></param> public void Enlist( IDbCommand command ) { --- 29,40 ---- /// <summary> ! /// Enlist the <see cref="IDbCommand"/> in the current <see cref="ITransaction"/>. /// </summary> ! /// <param name="command">The <see cref="IDbCommand"/> to enlist in this Transaction.</param> ! /// <remarks> ! /// This takes care of making sure the <see cref="IDbCommand"/>'s Transaction property ! /// contains the correct <see cref="IDbTransaction"/> or <c>null</c> if there is no ! /// Transaction for the ISession - ie <c>BeginTransaction()</c> not called. ! /// </remarks> public void Enlist( IDbCommand command ) { *************** *** 63,67 **** } ! /// <summary></summary> public void Begin() { --- 69,80 ---- } ! /// <summary> ! /// Begins the <see cref="IDbTransaction"/> on the <see cref="IDbConnection"/> ! /// used by the <see cref="ISession"/>. ! /// </summary> ! /// <exception cref="TransactionException"> ! /// Thrown if there is any problems encountered while trying to create ! /// the <see cref="IDbTransaction"/>. ! /// </exception> public void Begin() { *************** *** 89,93 **** } ! /// <summary></summary> public void Commit() { --- 102,113 ---- } ! /// <summary> ! /// Commits the <see cref="ITransaction"/> by flushing the <see cref="ISession"/> ! /// and committing the <see cref="IDbTransaction"/>. ! /// </summary> ! /// <exception cref="TransactionException"> ! /// Thrown if there is any exception while trying to call <c>Commit()</c> on ! /// the underlying <see cref="IDbTransaction"/>. ! /// </exception> public void Commit() { *************** *** 122,126 **** } ! /// <summary></summary> public void Rollback() { --- 142,153 ---- } ! /// <summary> ! /// Rolls back the <see cref="ITransaction"/> by calling the method <c>Rollback</c> ! /// on the underlying <see cref="IDbTransaction"/>. ! /// </summary> ! /// <exception cref="TransactionException"> ! /// Thrown if there is any exception while trying to call <c>Rollback()</c> on ! /// the underlying <see cref="IDbTransaction"/>. ! /// </exception> public void Rollback() { *************** *** 147,151 **** } ! /// <summary></summary> public bool WasRolledBack { --- 174,184 ---- } ! /// <summary> ! /// Gets a <see cref="Boolean"/> indicating if the transaction was rolled back. ! /// </summary> ! /// <value> ! /// <c>true</c> if the <see cref="IDbTransaction"/> had <c>Rollback</c> called ! /// without any exceptions. ! /// </value> public bool WasRolledBack { *************** *** 153,157 **** } ! /// <summary></summary> public bool WasCommitted { --- 186,196 ---- } ! /// <summary> ! /// Gets a <see cref="Boolean"/> indicating if the transaction was committed. ! /// </summary> ! /// <value> ! /// <c>true</c> if the <see cref="IDbTransaction"/> had <c>Commit</c> called ! /// without any exceptions. ! /// </value> public bool WasCommitted { *************** *** 159,162 **** --- 198,262 ---- } + #region System.IDisposable Members + + /// <summary> + /// A flag to indicate if <c>Disose()</c> has been called. + /// </summary> + private bool _isAlreadyDisposed; + + /// <summary> + /// Finalizer that ensures the object is correctly disposed of. + /// </summary> + ~AdoTransaction() + { + Dispose( false ); + } + + /// <summary> + /// Takes care of freeing the managed and unmanaged resources that + /// this class is responsible for. + /// </summary> + public void Dispose() + { + log.Debug( "running AdoTransaction.Dispose()" ); + Dispose( true ); + } + + /// <summary> + /// Takes care of freeing the managed and unmanaged resources that + /// this class is responsible for. + /// </summary> + /// <param name="isDisposing">Indicates if this AdoTransaction is being Disposed of or Finalized.</param> + /// <remarks> + /// If this AdoTransaction is being Finalized (<c>isDisposing==false</c>) then make sure not + /// to call any methods that could potentially bring this AdoTransaction back to life. + /// </remarks> + protected virtual void Dispose(bool isDisposing) + { + if( _isAlreadyDisposed ) + { + // don't dispose of multiple times. + return; + } + + // free managed resources that are being managed by the AdoTransaction if we + // know this call came through Dispose() + if( isDisposing ) + { + if( trans!=null ) + { + trans.Dispose(); + } + } + + // free unmanaged resources here + + _isAlreadyDisposed = true; + // nothing for Finalizer to do - so tell the GC to ignore it + GC.SuppressFinalize( this ); + + } + #endregion + } } \ No newline at end of file |