Update of /cvsroot/springnet/Spring.Net/src/Spring/Spring.Data.NHibernate/Data/NHibernate
In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv9441
Modified Files:
HibernateTransactionManager.cs SpringSessionSynchronization.cs
Log Message:
NHibernate unit tests
SPRNET-714 - SessionFactory not bound to thread local storage if DbProvider for HibernateTransactionManager is null
SPRNET-715 - SpringSessionSynchronization did not close hibernate session with a nested transaction with TransactionPropagation.NotSupported
Index: SpringSessionSynchronization.cs
===================================================================
RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Data.NHibernate/Data/NHibernate/SpringSessionSynchronization.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** SpringSessionSynchronization.cs 31 May 2007 20:25:13 -0000 1.1
--- SpringSessionSynchronization.cs 29 Aug 2007 03:42:06 -0000 1.2
***************
*** 61,65 ****
/// Initializes a new instance of the <see cref="SpringSessionSynchronization"/> class.
/// </summary>
! public SpringSessionSynchronization(SessionHolder sessionHolder, ISessionFactory sessionFactory,
IAdoExceptionTranslator adoExceptionTranslator, bool newSession)
{
--- 61,65 ----
/// Initializes a new instance of the <see cref="SpringSessionSynchronization"/> class.
/// </summary>
! public SpringSessionSynchronization(SessionHolder sessionHolder, ISessionFactory sessionFactory,
IAdoExceptionTranslator adoExceptionTranslator, bool newSession)
{
***************
*** 241,261 ****
public override void AfterCompletion(TransactionSynchronizationStatus status)
{
- if (!newSession)
- {
- ISession session = sessionHolder.Session;
! // Provide correct transaction status for releasing the Session's cache locks,
! // if possible. Else, closing will release all cache locks assuming a rollback.
! ISessionImplementor sessionImplementor = session as ISessionImplementor;
! if (sessionImplementor != null)
! {
! sessionImplementor.AfterTransactionCompletion(status == TransactionSynchronizationStatus.Committed);
! }
- if (newSession)
- {
- SessionFactoryUtils.CloseSessionOrRegisterDeferredClose(session, sessionFactory);
- }
- }
if (!newSession && status != TransactionSynchronizationStatus.Committed)
{
--- 241,260 ----
public override void AfterCompletion(TransactionSynchronizationStatus status)
{
! ISession session = sessionHolder.Session;
!
! // Provide correct transaction status for releasing the Session's cache locks,
! // if possible. Else, closing will release all cache locks assuming a rollback.
! ISessionImplementor sessionImplementor = session as ISessionImplementor;
! if (sessionImplementor != null)
! {
! sessionImplementor.AfterTransactionCompletion(status == TransactionSynchronizationStatus.Committed);
! }
!
! if (newSession)
! {
! SessionFactoryUtils.CloseSessionOrRegisterDeferredClose(session, sessionFactory);
! }
if (!newSession && status != TransactionSynchronizationStatus.Committed)
{
Index: HibernateTransactionManager.cs
===================================================================
RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Data.NHibernate/Data/NHibernate/HibernateTransactionManager.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** HibernateTransactionManager.cs 31 Jul 2007 18:17:45 -0000 1.2
--- HibernateTransactionManager.cs 29 Aug 2007 03:42:05 -0000 1.3
***************
*** 87,97 ****
#region Constructor (s)
- /// <summary>
- /// Initializes a new instance of the <see cref="HibernateTransactionManager"/> class.
- /// </summary>
- public HibernateTransactionManager()
- {
! }
#endregion
--- 87,107 ----
#region Constructor (s)
! /// <summary>
! /// Initializes a new instance of the <see cref="HibernateTransactionManager"/> class.
! /// </summary>
! public HibernateTransactionManager()
! {
! }
!
! /// <summary>
! /// Initializes a new instance of the <see cref="HibernateTransactionManager"/> class.
! /// </summary>
! /// <param name="sessionFactory">The session factory.</param>
! public HibernateTransactionManager(ISessionFactory sessionFactory)
! {
! this.sessionFactory = sessionFactory;
! AfterPropertiesSet();
! }
#endregion
***************
*** 311,314 ****
--- 321,326 ----
protected override void DoBegin(object transaction, ITransactionDefinition definition)
{
+ HibernateTransactionObject txObject = (HibernateTransactionObject) transaction;
+
if (DbProvider != null && TransactionSynchronizationManager.HasResource(DbProvider))
{
***************
*** 319,327 ****
"on a single DbProvider, no matter whether Hibernate or ADO.NET access.");
}
-
ISession session = null;
try
{
! HibernateTransactionObject txObject = (HibernateTransactionObject) transaction;
if (txObject.SessionHolder == null)
{
--- 331,338 ----
"on a single DbProvider, no matter whether Hibernate or ADO.NET access.");
}
ISession session = null;
try
{
!
if (txObject.SessionHolder == null)
{
***************
*** 391,406 ****
TransactionSynchronizationManager.BindResource(DbProvider, conHolder);
txObject.ConnectionHolder = conHolder;
! // Bind the session holder to the thread.
! if (txObject.NewSessionHolder)
! {
! TransactionSynchronizationManager.BindResource(SessionFactory, txObject.SessionHolder);
! }
}
! }catch (Exception ex)
{
! SessionFactoryUtils.CloseSession(session);
! throw new CannotCreateTransactionException("Could not open Hibernate Session for transaction", ex);
}
--- 402,417 ----
TransactionSynchronizationManager.BindResource(DbProvider, conHolder);
txObject.ConnectionHolder = conHolder;
+ }
! // Bind the session holder to the thread.
! if (txObject.NewSessionHolder)
! {
! TransactionSynchronizationManager.BindResource(SessionFactory, txObject.SessionHolder);
}
! } catch (Exception ex)
{
! SessionFactoryUtils.CloseSession(session);
! throw new CannotCreateTransactionException("Could not open Hibernate Session for transaction", ex);
}
***************
*** 578,581 ****
--- 589,593 ----
}
+
/// <summary>
/// Set the given transaction rollback-only. Only called on rollback
***************
*** 594,598 ****
txObject.SessionHolder.Session + "] rollback-only");
}
! txObject.setRollbackOnly();
}
--- 606,610 ----
txObject.SessionHolder.Session + "] rollback-only");
}
! txObject.SetRollbackOnly();
}
***************
*** 694,701 ****
TransactionSynchronizationManager.UnbindResource(DbProvider);
}
try
{
- IDbConnection con = txObject.SessionHolder.Session.Connection;
//TODO investigate isolation level settings...
//AdoUtils.ResetConnectionAfterTransaction(con, txObject.PreviousIsolationLevel);
}
--- 706,714 ----
TransactionSynchronizationManager.UnbindResource(DbProvider);
}
+ /*
try
{
//TODO investigate isolation level settings...
+ //IDbConnection con = txObject.SessionHolder.Session.Connection;
//AdoUtils.ResetConnectionAfterTransaction(con, txObject.PreviousIsolationLevel);
}
***************
*** 704,707 ****
--- 717,721 ----
log.Info("Could not access ADO.NET IDbConnection of Hibernate Session", ex);
}
+ */
ISession session = txObject.SessionHolder.Session;
if (txObject.NewSessionHolder)
***************
*** 720,726 ****
}
if (txObject.SessionHolder.AssignedPreviousFlushMode)
! {
session.FlushMode = txObject.SessionHolder.PreviousFlushMode;
! }
}
txObject.SessionHolder.Clear();
--- 734,740 ----
}
if (txObject.SessionHolder.AssignedPreviousFlushMode)
! {
session.FlushMode = txObject.SessionHolder.PreviousFlushMode;
! }
}
txObject.SessionHolder.Clear();
***************
*** 765,769 ****
}
! public void setRollbackOnly()
{
SessionHolder.RollbackOnly = true;
--- 779,783 ----
}
! public void SetRollbackOnly()
{
SessionHolder.RollbackOnly = true;
***************
*** 774,781 ****
}
! public bool IsRollbackOnly()
{
! return SessionHolder.RollbackOnly ||
! (ConnectionHolder != null && ConnectionHolder.RollbackOnly);
}
}
--- 788,803 ----
}
! /// <summary>
! /// Return whether the transaction is internally marked as rollback-only.
! /// </summary>
! /// <value></value>
! /// <returns>True of the transaction is marked as rollback-only.</returns>
! public override bool RollbackOnly
{
! get
! {
! return SessionHolder.RollbackOnly ||
! (ConnectionHolder != null && ConnectionHolder.RollbackOnly);
! }
}
}
|