Click here to Skip to main content
15,896,118 members
Articles / Programming Languages / XML

Building a Middle Tier Component using NHibernate and Spring.NET

Rate me:
Please Sign up or sign in to vote.
4.50/5 (21 votes)
10 May 2006CPOL8 min read 159.1K   2.4K   109  
Building a highly pluggable middle-tier component with NHibernate and Spring.Net.
#region Licence

/*
 * Copyright � 2002-2005 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#endregion

#region Imports

using System;
using AopAlliance.Intercept;
using Spring.Aop.Framework;
using Spring.Objects.Factory;
using log4net;
using System.Collections.Specialized;
#endregion

namespace Spring.Transaction.Interceptor
{
	/// <summary>
	///
	/// This Class describes a Transaction propagation behaviour and the Isolation level.
	/// 
	/// <author> Rod Johnson </author>
	/// <author> Moim Hossain (.NET)</author>
	/// </summary>
	public class TransactionAttribute
	{
		/// <summary>
		/// Default Transaction Attribute
		/// </summary>
		public static TransactionAttribute DefaultTransactionAttribute
		{
			get
			{
				return new TransactionAttribute( TransactionAttribute.PROPAGATION_REQUIRED );
			}
		}
		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="PropagationMode"></param>
		public TransactionAttribute(string PropagationMode)
		{
			SetPropagationMode( PropagationMode );
		}
		/// <summary>
		/// Define a propagation as MUST REQUIED, IF NOT EXISTS THEN CREATE A NEW ONE
		/// </summary>
		public static string PROPAGATION_REQUIRED = "PROPAGATION_REQUIRED";
		/// <summary>
		/// IF ALLREADY RUNNING ONE IT WILL WORK
		/// </summary>
		public static string PROPAGATION_SUPPORTS = "PROPAGATION_SUPPORTS";
		/// <summary>
		/// MUST RUN INSIDE A TRANSACTION BOUNDARY
		/// </summary>
		public static string PROPAGATION_MANDATORY = "PROPAGATION_MANDATORY";
		/// <summary>
		/// ALWAYS REQUIRED A NEW TRANSACTION BOUNDARY
		/// </summary>
		public static string PROPAGATION_REQUIRES_NEW = "PROPAGATION_REQUIRES_NEW";
		/// <summary>
		/// DOES NOT SUPPORTS TRANSACTION 
		/// </summary>
		public static string PROPAGATION_NOT_SUPPORTED = "PROPAGATION_NOT_SUPPORTED";
		/// <summary>
		/// NEVER RUN INSIDE A TRANSACTION BOUNDARY
		/// </summary>
		public static string PROPAGATION_NEVER = "PROPAGATION_NEVER";
		/// <summary>
		/// NESTED
		/// </summary>
		public static string PROPAGATION_NESTED = "PROPAGATION_NESTED";
		/// <summary>
		/// 
		/// </summary>
		private static string[]PROPAGATIONS = new string[]
			{
				PROPAGATION_REQUIRED,
				PROPAGATION_SUPPORTS,
				PROPAGATION_MANDATORY,
				PROPAGATION_REQUIRES_NEW,
				PROPAGATION_NOT_SUPPORTED,
				PROPAGATION_NEVER,
				PROPAGATION_NESTED
			};

		private string m_CurrentPropagationMode = string.Empty;
		/// <summary>
		/// Determine the current propagation mode
		/// </summary>
		public string CurrentPropagationMode
		{
			get
			{
				return m_CurrentPropagationMode;
			}
		}
		/// <summary>
		/// Set the current propagation mode
		/// </summary>
		/// <param name="PropagationMode"></param>
		public void SetPropagationMode( string PropagationMode )
		{
			bool l_InvalidPropagationDefined = true;

			foreach( string Propagation in PROPAGATIONS )
			{
				if( Propagation.Equals( PropagationMode ))
				{
					l_InvalidPropagationDefined = false;
					break;
				}
			}

			if( l_InvalidPropagationDefined )
				throw new ArgumentException("Invalid propagation defined.", "PropagationMode");

			m_CurrentPropagationMode = PropagationMode;
		}
	}
}

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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
Netherlands Netherlands
Engineer Powered by the Cloud

Comments and Discussions