narsil/Tanshu.Accounts.SqlDAO/BaseDAO.cs

66 lines
2.0 KiB
C#
Raw Normal View History

2010-03-02 17:56:21 +00:00
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using Tanshu.Data.DAO;
namespace Tanshu.Accounts.SqlDAO
{
public abstract class BaseDAO : IDisposable
{
protected IConnectionDAO connection;
protected BaseDAO(IConnectionDAO connection)
{
this.connection = connection;
}
#region IDisposable Members
private bool disposed = false;
~BaseDAO()
{
// call Dispose with false. Since we're in the
// destructor call, the managed resources will be
// disposed of anyways.
Dispose(false);
}
public void Dispose()
{
// dispose of the managed and unmanaged resources
Dispose(true);
// tell the GC that the Finalize process no longer needs
// to be run for this object.
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposeManagedResources)
{
// process only if mananged and unmanaged resources have
// not been disposed of.
if (!this.disposed)
{
Trace.WriteLine("Tanshu.WebAccounts.SqlDAO.BaseDAO: Resources not disposed");
if (disposeManagedResources)
{
Trace.WriteLine("Tanshu.WebAccounts.SqlDAO.BaseDAO: Disposing managed resources");
// dispose managed resources
//if (connection != null)
//{
// connection.Dispose();
// connection = null;
//}
}
// dispose unmanaged resources
Trace.WriteLine("Tanshu.WebAccounts.SqlDAO.BaseDAO: Disposing unmanaged resouces");
disposed = true;
}
else
{
Trace.WriteLine("Tanshu.WebAccounts.SqlDAO.BaseDAO: Resources already disposed");
}
}
#endregion
}
}