From: Michael D. <mik...@us...> - 2005-01-30 19:36:26
|
Update of /cvsroot/nhibernate/nhibernate/src/NHibernate/Connection In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32147/NHibernate/Connection Modified Files: ConnectionProvider.cs DriverConnectionProvider.cs IConnectionProvider.cs UserSuppliedConnectionProvider.cs Log Message: Implemented IDisposable according to standard .net pattern Added some more xml comments to Connection namespace. Index: IConnectionProvider.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Connection/IConnectionProvider.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** IConnectionProvider.cs 31 Dec 2004 16:46:43 -0000 1.6 --- IConnectionProvider.cs 30 Jan 2005 19:36:15 -0000 1.7 *************** *** 1,2 **** --- 1,3 ---- + using System; using System.Collections; using System.Data; *************** *** 6,26 **** { /// <summary> ! /// A strategy for obtaining ADO.NET connections. /// </summary> /// <remarks> /// The <c>IConnectionProvider</c> interface is not intended to be exposed to the application. ! /// Instead it is used internally by Hibernate to obtain connections. Implementors should provide ! /// a public default constructor. /// </remarks> ! public interface IConnectionProvider { /// <summary> - /// The Driver this ConnectionProvider should use to communicate with the .NET Data Provider - /// </summary> - /// <value></value> - /// <remarks></remarks> - IDriver Driver { get; } - - /// <summary> /// Initialize the connection provider from the given properties. /// </summary> --- 7,20 ---- { /// <summary> ! /// A strategy for obtaining ADO.NET <see cref="IDbConnection"/>. /// </summary> /// <remarks> /// The <c>IConnectionProvider</c> interface is not intended to be exposed to the application. ! /// Instead it is used internally by NHibernate to obtain <see cref="IDbConnection"/>. ! /// Implementors should provide a public default constructor. /// </remarks> ! public interface IConnectionProvider : IDisposable { /// <summary> /// Initialize the connection provider from the given properties. /// </summary> *************** *** 29,55 **** /// <summary> ! /// Grab a connection ! /// </summary> ! /// <returns>An ADO.NET connection</returns> ! IDbConnection GetConnection(); ! ! /// <summary> ! /// Dispose of a used connection /// </summary> ! /// <param name="conn">An ADO.NET connection</param> void CloseConnection( IDbConnection conn ); /// <summary> ! /// Does this ConnectionProvider implement a <c>PreparedStatemnt</c> cache?. /// </summary> ! /// <remarks> ! /// If so, Hibernate will not use its own cache ! /// </remarks> ! bool IsStatementCache { get; } /// <summary> ! /// Release all resources held by this ConnectionProvider. /// </summary> ! void Close(); } --- 23,45 ---- /// <summary> ! /// Dispose of a used <see cref="IDbConnection"/> /// </summary> ! /// <param name="conn">The <see cref="IDbConnection"/> to clean up.</param> void CloseConnection( IDbConnection conn ); /// <summary> ! /// Gets the <see cref="IDriver"/> this ConnectionProvider should use to ! /// communicate with the .NET Data Provider /// </summary> ! /// <value> ! /// The <see cref="IDriver"/> to communicate with the .NET Data Provider. ! /// </value> ! IDriver Driver { get; } /// <summary> ! /// Get an open <see cref="IDbConnection"/>. /// </summary> ! /// <returns>An open <see cref="IDbConnection"/>.</returns> ! IDbConnection GetConnection(); } Index: DriverConnectionProvider.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Connection/DriverConnectionProvider.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** DriverConnectionProvider.cs 31 Dec 2004 16:46:43 -0000 1.4 --- DriverConnectionProvider.cs 30 Jan 2005 19:36:15 -0000 1.5 *************** *** 12,16 **** private static readonly ILog log = LogManager.GetLogger( typeof( DriverConnectionProvider ) ); ! /// <summary></summary> public DriverConnectionProvider() { --- 12,18 ---- private static readonly ILog log = LogManager.GetLogger( typeof( DriverConnectionProvider ) ); ! /// <summary> ! /// Initializes a new instance of the <see cref="DriverConnectionProvider"/> class. ! /// </summary> public DriverConnectionProvider() { *************** *** 18,24 **** /// <summary> ! /// /// </summary> ! /// <returns></returns> public override IDbConnection GetConnection() { --- 20,43 ---- /// <summary> ! /// Closes and Disposes of the <see cref="IDbConnection"/>. /// </summary> ! /// <param name="conn">The <see cref="IDbConnection"/> to clean up.</param> ! public override void CloseConnection( IDbConnection conn ) ! { ! base.CloseConnection( conn ); ! //TODO: make sure I want to do this - pretty sure I do because of Oracle problems. ! conn.Dispose(); ! } ! ! /// <summary> ! /// Gets a new open <see cref="IDbConnection"/> through ! /// the <see cref="NHibernate.Driver.IDriver"/>. ! /// </summary> ! /// <returns> ! /// An Open <see cref="IDbConnection"/>. ! /// </returns> ! /// <exception cref="ADOException"> ! /// If there is any problem creating or opening the <see cref="IDbConnection"/>. ! /// </exception> public override IDbConnection GetConnection() { *************** *** 37,63 **** } - /// <summary></summary> - public override bool IsStatementCache - { - get { return false; } - } - - /// <summary></summary> - public override void Close() - { - log.Info( "cleaning up connection pool" ); - } - - /// <summary> - /// - /// </summary> - /// <param name="conn"></param> - public override void CloseConnection( IDbConnection conn ) - { - base.CloseConnection( conn ); - //TODO: make sure I want to do this - pretty sure I do because of Oracle problems. - conn.Dispose(); - } - } --- 56,59 ---- Index: ConnectionProvider.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Connection/ConnectionProvider.cs,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** ConnectionProvider.cs 31 Dec 2004 16:46:43 -0000 1.9 --- ConnectionProvider.cs 30 Jan 2005 19:36:15 -0000 1.10 *************** *** 11,15 **** /// The base class for the ConnectionProvider. /// </summary> ! public abstract class ConnectionProvider : IConnectionProvider, IDisposable { private static readonly ILog log = LogManager.GetLogger( typeof( ConnectionProvider ) ); --- 11,15 ---- /// The base class for the ConnectionProvider. /// </summary> ! public abstract class ConnectionProvider : IConnectionProvider { private static readonly ILog log = LogManager.GetLogger( typeof( ConnectionProvider ) ); *************** *** 18,24 **** /// <summary> ! /// /// </summary> ! /// <param name="conn"></param> public virtual void CloseConnection( IDbConnection conn ) { --- 18,24 ---- /// <summary> ! /// Closes the <see cref="IDbConnection"/>. /// </summary> ! /// <param name="conn">The <see cref="IDbConnection"/> to clean up.</param> public virtual void CloseConnection( IDbConnection conn ) { *************** *** 37,42 **** /// Configures the ConnectionProvider with the Driver and the ConnectionString. /// </summary> ! /// <param name="settings">A name/value Dictionary that contains the settings for this ConnectionProvider.</param> ! /// <exception cref="HibernateException">Thrown when a ConnectionString could not be found or the Driver Class could not be loaded.</exception> public virtual void Configure( IDictionary settings ) { --- 37,45 ---- /// Configures the ConnectionProvider with the Driver and the ConnectionString. /// </summary> ! /// <param name="settings">An <see cref="IDictionary"/> that contains the settings for this ConnectionProvider.</param> ! /// <exception cref="HibernateException"> ! /// Thrown when a <see cref="Environment.ConnectionString"/> could not be found ! /// in the <c>settings</c> parameter or the Driver Class could not be loaded. ! /// </exception> public virtual void Configure( IDictionary settings ) { *************** *** 56,60 **** /// Configures the driver for the ConnectionProvider. /// </summary> ! /// <param name="settings">A name/value Dictionary that contains the settings for the Driver.</param> protected virtual void ConfigureDriver( IDictionary settings ) { --- 59,68 ---- /// Configures the driver for the ConnectionProvider. /// </summary> ! /// <param name="settings">An <see cref="IDictionary"/> that contains the settings for the Driver.</param> ! /// <exception cref="HibernateException"> ! /// Thrown when the <see cref="Environment.ConnectionDriver"/> could not be ! /// found in the <c>settings</c> parameter or there is a problem with creating ! /// the <see cref="IDriver"/>. ! /// </exception> protected virtual void ConfigureDriver( IDictionary settings ) { *************** *** 79,84 **** /// <summary> ! /// /// </summary> protected virtual string ConnectionString { --- 87,97 ---- /// <summary> ! /// Gets the <see cref="String"/> for the <see cref="IDbConnection"/> ! /// to connect to the database. /// </summary> + /// <value> + /// The <see cref="String"/> for the <see cref="IDbConnection"/> + /// to connect to the database. + /// </value> protected virtual string ConnectionString { *************** *** 87,92 **** /// <summary> ! /// /// </summary> public IDriver Driver { --- 100,108 ---- /// <summary> ! /// Gets the <see cref="IDriver"/> that can create the <see cref="IDbConnection"/> object. /// </summary> + /// <value> + /// The <see cref="IDriver"/> that can create the <see cref="IDbConnection"/>. + /// </value> public IDriver Driver { *************** *** 95,123 **** /// <summary> ! /// Grab a Connection from this ConnectionProvider /// </summary> ! /// <returns></returns> public abstract IDbConnection GetConnection(); /// <summary> ! /// /// </summary> ! public abstract bool IsStatementCache { get; } /// <summary> ! /// /// </summary> ! public abstract void Close(); ! ! #region IDisposable Members /// <summary> ! /// /// </summary> public void Dispose() { ! Close(); } #endregion } --- 111,180 ---- /// <summary> ! /// Get an open <see cref="IDbConnection"/>. /// </summary> ! /// <returns>An open <see cref="IDbConnection"/>.</returns> public abstract IDbConnection GetConnection(); + #region 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> ! ~ConnectionProvider() ! { ! Dispose( false ); ! } /// <summary> ! /// Takes care of freeing the managed and unmanaged resources that ! /// this class is responsible for. /// </summary> public void 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 ConnectionProvider is being Disposed of or Finalized.</param> + /// <remarks> + /// <p> + /// If this ConnectionProvider is being Finalized (<c>isDisposing==false</c>) then make + /// sure not to call any methods that could potentially bring this + /// ConnectionProvider back to life. + /// </p> + /// <p> + /// If any subclasses manage resources that also need to be disposed of this method + /// should be overridden, but don't forget to call it in the override. + /// </p> + /// </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 ConnectionProvider if we + // know this call came through Dispose() + if( isDisposing ) + { + log.Debug( "Disposing of ConnectionProvider." ); + } + + // free unmanaged resources here + + _isAlreadyDisposed = true; + // nothing for Finalizer to do - so tell the GC to ignore it + GC.SuppressFinalize( this ); + } #endregion } Index: UserSuppliedConnectionProvider.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Connection/UserSuppliedConnectionProvider.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** UserSuppliedConnectionProvider.cs 31 Dec 2004 16:46:43 -0000 1.6 --- UserSuppliedConnectionProvider.cs 30 Jan 2005 19:36:15 -0000 1.7 *************** *** 18,24 **** /// <summary> ! /// /// </summary> ! /// <param name="conn"></param> public override void CloseConnection( IDbConnection conn ) { --- 18,29 ---- /// <summary> ! /// Throws an <see cref="InvalidOperationException"/> if this method is called ! /// because the user is responsible for closing <see cref="IDbConnection"/>s. /// </summary> ! /// <param name="conn">The <see cref="IDbConnection"/> to clean up.</param> ! /// <exception cref="InvalidOperationException"> ! /// Thrown when this method is called. User is responsible for closing ! /// <see cref="IDbConnection"/>s. ! /// </exception> public override void CloseConnection( IDbConnection conn ) { *************** *** 27,33 **** /// <summary> ! /// /// </summary> ! /// <returns></returns> public override IDbConnection GetConnection() { --- 32,45 ---- /// <summary> ! /// Throws an <see cref="InvalidOperationException"/> if this method is called ! /// because the user is responsible for creating <see cref="IDbConnection"/>s. /// </summary> ! /// <returns> ! /// No value is returned because an <see cref="InvalidOperationException"/> is thrown. ! /// </returns> ! /// <exception cref="InvalidOperationException"> ! /// Thrown when this method is called. User is responsible for creating ! /// <see cref="IDbConnection"/>s. ! /// </exception> public override IDbConnection GetConnection() { *************** *** 50,67 **** } - /// <summary></summary> - public override bool IsStatementCache - { - get { return false; } - } - - /// <summary></summary> - public override void Close() - { - // do nothing - don't need to throw an error because this is something - // that NHibernate will call. - } - - } } \ No newline at end of file --- 62,65 ---- |