Click here to Skip to main content
15,888,968 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 158.6K   2.4K   109  
Building a highly pluggable middle-tier component with NHibernate and Spring.Net.
using System;
using System.Collections;
using Spring.Orm.Hibernate.Support;

namespace SpringClient.Utility.Product
{
	/// <summary>
	/// The Implementation of the IUProductDAO.
	/// 
	/// This is a concrete Data Access Object for the Product object.
	/// 
	/// Implemented all the methods remains in <see cref="SpringClient.Utility.Product.IUProduct"/> DAO interface.
	/// 
	/// Inherited from <see cref="Spring.Orm.Hibernate.Support.HibernateDaoSupport"/> for
	/// the Data Acccess support provided by the Hibernate ORM.
	/// 
	/// <author> Moim Hossain</author>
	/// </summary>
	public class UProductDAO : HibernateDaoSupport, IUProductDAO
	{
		/// <summary>
		/// Constructor
		/// </summary>
		public UProductDAO()
		{
		}

		#region IUProductDAO Members
		/// <summary>
		/// Create a Product. 
		/// </summary>
		/// <param name="Product">The Product That will be Persisted</param>
		/// <returns>The Product The has saved to the Data Store. Contains the ID (Generated by datastore)</returns>
		public UProductDTO Create(UProductDTO Product)
		{
			HibernateTemplate.Save( Product ) ;

			return Product;
		}
		/// <summary>
		/// Retrive a Product from the Data Store by ID
		/// </summary>
		/// <param name="ProductID">The ID that will be searched into the Data store</param>
		/// <returns>The Retrived Data Object</returns>
		public UProductDTO Retrive( long ProductID )
		{
			return HibernateTemplate.Load( typeof( UProductDTO ) , ProductID ) as UProductDTO;
		}
		/// <summary>
		/// Update a product Object
		/// </summary>
		/// <param name="Product">The Product Instance that should be Updated</param>
		public void Update( UProductDTO Product )
		{
			HibernateTemplate.Update( Product );
		}
		/// <summary>
		/// Deletes a product
		/// </summary>
		/// <param name="Product">The product that will be Deleted</param>
		public void Delete( UProductDTO Product )
		{
			HibernateTemplate.Delete( Product );
		}
		/// <summary>
		/// Search for some object by matching a criteria
		/// </summary>
		/// <param name="queryString">The Hibernate Query string</param>
		/// <param name="Parameters">The parameter values for the query</param>
		/// <returns>The List of UProducts that has a match for the given query</returns>
		public UProductDTO[]FindProducts( string queryString , object[]Parameters )
		{
			IList resultList = HibernateTemplate.Find( queryString , Parameters ) as IList;

			if( null != resultList )
			{
				UProductDTO[]products = new UProductDTO[resultList.Count];

				resultList.CopyTo( products , 0 );

				return products;
			}
			return null;
		}
		#endregion
	}
}

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