Update of /cvsroot/springnet/Spring.Net/src/Spring/Spring.Data.NHibernate12/Data/NHibernate/Generic
In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv27236
Modified Files:
HibernateDaoSupport.cs
Log Message:
Add missing methods to generic version of HibernateDaoSupport. Some general code cleanup..
Index: HibernateDaoSupport.cs
===================================================================
RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Data.NHibernate12/Data/NHibernate/Generic/HibernateDaoSupport.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** HibernateDaoSupport.cs 1 Jun 2007 02:34:12 -0000 1.1
--- HibernateDaoSupport.cs 28 Aug 2007 15:26:29 -0000 1.2
***************
*** 23,26 ****
--- 23,27 ----
using System;
using NHibernate;
+ using Spring.Dao;
using Spring.Dao.Support;
***************
*** 105,108 ****
--- 106,135 ----
}
}
+
+ /// <summary>
+ /// Get a Hibernate Session, either from the current transaction or a new one.
+ /// The latter is only allowed if the "allowCreate" setting of this object's
+ /// HibernateTemplate is true.
+ /// </summary>
+ /// <remarks>
+ /// <p><b>Note that this is not meant to be invoked from HibernateTemplate code
+ /// but rather just in plain Hibernate code.</b> Use it in combination with
+ /// <b>ReleaseSession</b>.
+ /// </p>
+ /// <p>In general, it is recommended to use HibernateTemplate, either with
+ /// the provided convenience operations or with a custom HibernateCallback
+ /// that provides you with a Session to work on. HibernateTemplate will care
+ /// for all resource management and for proper exception conversion.
+ /// </p>
+ /// </remarks>
+ /// <value>The Hibernate session.</value>
+ public ISession Session
+ {
+ get
+ {
+ return DoGetSession(HibernateTemplate.AllowCreate);
+ }
+ }
+
#endregion
***************
*** 123,138 ****
}
- #endregion
-
/// <summary>
/// Check if the hibernate template property has been set.
/// </summary>
! protected override void CheckDaoConfig()
! {
! if (this.hibernateTemplate == null)
{
throw new ArgumentException("sessionFactory or hibernateTemplate is required");
}
! }
}
}
--- 150,233 ----
}
/// <summary>
/// Check if the hibernate template property has been set.
/// </summary>
! protected override void CheckDaoConfig()
! {
! if (this.hibernateTemplate == null)
{
throw new ArgumentException("sessionFactory or hibernateTemplate is required");
}
! }
! /// <summary>
! /// Get a Hibernate Session, either from the current transaction or
! /// a new one. The latter is only allowed if "allowCreate" is true.
! /// </summary>
! /// <remarks>Note that this is not meant to be invoked from HibernateTemplate code
! /// but rather just in plain Hibernate code. Either rely on a thread-bound
! /// Session (via HibernateInterceptor), or use it in combination with
! /// ReleaseSession.
! /// <para>
! /// In general, it is recommended to use HibernateTemplate, either with
! /// the provided convenience operations or with a custom HibernateCallback
! /// that provides you with a Session to work on. HibernateTemplate will care
! /// for all resource management and for proper exception conversion.
! /// </para>
! /// </remarks>
! /// <param name="allowCreate"> if a non-transactional Session should be created when no
! /// transactional Session can be found for the current thread
! /// </param>
! /// <returns>Hibernate session.</returns>
! /// <exception cref="DataAccessResourceFailureException">
! /// If the Session couldn't be created
! /// </exception>
! /// <exception cref="InvalidOperationException">
! /// if no thread-bound Session found and allowCreate false
! /// </exception>
! /// <seealso cref="ReleaseSession"/>
! protected ISession DoGetSession(bool allowCreate)
! {
! return (!allowCreate ?
! SessionFactoryUtils.GetSession(SessionFactory, false) :
! SessionFactoryUtils.GetSession(
! SessionFactory,
! this.hibernateTemplate.EntityInterceptor,
! this.hibernateTemplate.AdoExceptionTranslator));
! }
!
! /// <summary>
! /// Convert the given HibernateException to an appropriate exception from the
! /// <code>org.springframework.dao</code> hierarchy. Will automatically detect
! /// wrapped ADO.NET Exceptions and convert them accordingly.
! /// </summary>
! /// <param name="ex">HibernateException that occured.</param>
! /// <returns>
! /// The corresponding DataAccessException instance
! /// </returns>
! /// <remarks>
! /// The default implementation delegates to SessionFactoryUtils
! /// and convertAdoAccessException. Can be overridden in subclasses.
! /// </remarks>
! protected DataAccessException ConvertHibernateAccessException(HibernateException ex)
! {
! return hibernateTemplate.ConvertHibernateAccessException(ex);
! }
!
! /// <summary>
! /// Close the given Hibernate Session, created via this DAO's SessionFactory,
! /// if it isn't bound to the thread.
! /// </summary>
! /// <remarks>
! /// Typically used in plain Hibernate code, in combination with the
! /// Session property and ConvertHibernateAccessException.
! /// </remarks>
! /// <param name="session">The session to close.</param>
! protected void ReleaseSession(ISession session)
! {
! SessionFactoryUtils.ReleaseSession(session, SessionFactory);
! }
! #endregion
!
!
}
}
|