Click here to Skip to main content
15,896,343 members
Articles / Programming Languages / C#

Data Access and Transaction Handling Framework

Rate me:
Please Sign up or sign in to vote.
4.69/5 (107 votes)
13 Jan 200510 min read 929K   2.1K   282  
Generic data access component for different datasources, sprocs/SQL, implicitly propagated transactions, explicitly managed transaction contexts etc.
//using System; 
//using System.Data;
//using System.Data.SqlClient;
//using System.EnterpriseServices; 
//
//namespace Framework.DataAccess.TransactionHandling.ESTransactionHandler
//{ 
//	// simple no-argument delegate for your callback routine 
//	public delegate void ContextCallback(); 
// 
//	// simple interface that allows you to invoke code in the configured 
//	// component's context 
//	public interface IManagedTransactionContext 
//	{ 
//		void DoCallback(ContextCallback callback); 
//		void SetComplete();
//		void SetAbort();
//		void OpenConnection(IDbConnection con);
//		IManagedTransactionContext ParentContext { get; }
//		IManagedTransactionContext GetControllingContext();
//	} 
// 
//	// The obvious class that does what you'd expect 
//	//[ Transaction(TransactionOption.Required) ] 
//	public class BaseTransactionContext 
//		: ServicedComponent, IManagedTransactionContext 
//	{ 
//		private IManagedTransactionContext _parentTC = null;
//
//		public BaseTransactionContext(IManagedTransactionContext parentTc)
//		{
//			_parentTC = parentTc;
//		}
//
//		public IManagedTransactionContext ParentContext
//		{
//			get
//			{
//				return _parentTC;
//			}
//		}
//
//		//[AutoComplete] 
//		void IManagedTransactionContext.DoCallback(ContextCallback callback) 
//		{ 
//			if (callback == null) throw new ArgumentNullException("callback"); 
//			callback(); 
//		} 
//
//		void IManagedTransactionContext.SetComplete()
//		{
//			ContextUtil.SetComplete();
//		}
//
//		void IManagedTransactionContext.SetAbort()
//		{
//			ContextUtil.SetAbort();
//		}
//
//		void IManagedTransactionContext.OpenConnection(IDbConnection con)
//		{
//			con.Open();
//		}
//
//		public virtual IManagedTransactionContext GetControllingContext()
//		{
//			return this;
//		}
//
//	} 
//
//	[Transaction(TransactionOption.Required)]
//	public class RequiredTransactionContext : BaseTransactionContext 
//	{
//		public RequiredTransactionContext(IManagedTransactionContext parentTc)
//			: base(parentTc) {}
//
//		public override IManagedTransactionContext GetControllingContext()
//		{
//			if(this.ParentContext != null)
//				return this.ParentContext;
//			else
//				return this;
//		}
//	}
//	[Transaction(TransactionOption.RequiresNew)]
//	public class RequiresNewTransactionContext : BaseTransactionContext 
//	{
//		public RequiresNewTransactionContext(IManagedTransactionContext parentTc)
//			: base(parentTc) {}
//
//		public override IManagedTransactionContext GetControllingContext()
//		{
//			return this;
//		}	
//	}
//	[Transaction(TransactionOption.Supported)]
//	public class SupportedTransactionContext : BaseTransactionContext 
//	{
//		public SupportedTransactionContext(IManagedTransactionContext parentTc)
//			: base(parentTc) {}
//
//		public override IManagedTransactionContext GetControllingContext()
//		{
//			if(this.ParentContext != null)
//				return this.ParentContext;
//			else
//				return null;
//		}	
//	}
//	[Transaction(TransactionOption.NotSupported)]
//	public class NotSupportedTransactionContext : BaseTransactionContext 
//	{
//		public NotSupportedTransactionContext(IManagedTransactionContext parentTc)
//			: base(parentTc) {}
//
//		public override IManagedTransactionContext GetControllingContext()
//		{
//			return null;
//		}	
//	}
//
//}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Austria Austria
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions