C# Class Spring.Data.NHibernate.HibernateTransactionManager

PlatformTransactionManager implementation for a single Hibernate SessionFactory. Binds a Hibernate Session from the specified factory to the thread, potentially allowing for one thread Session per factory
SessionFactoryUtils and HibernateTemplate are aware of thread-bound Sessions and participate in such transactions automatically. Using either of those is required for Hibernate access code that needs to support this transaction handling mechanism.

Supports custom isolation levels at the start of the transaction , and timeouts that get applied as appropriate Hibernate query timeouts. To support the latter, application code must either use HibernateTemplate (which by default applies the timeouts) or call SessionFactoryUtils.applyTransactionTimeout for each created Hibernate Query object.

Note that you can specify a Spring IDbProvider instance which if shared with a corresponding instance of AdoTemplate will allow for mixing ADO.NET/NHibernate operations within a single transaction.

Inheritance: Spring.Transaction.Support.AbstractPlatformTransactionManager, IResourceTransactionManager, IObjectFactoryAware, IInitializingObject
Mostrar archivo Open project: spring-projects/spring-net Class Usage Examples

Public Methods

Method Description
AfterPropertiesSet ( ) : void

Invoked by an Spring.Objects.Factory.IObjectFactory after it has injected all of an object's dependencies.

This method allows the object instance to perform the kind of initialization only possible when all of it's dependencies have been injected (set), and to throw an appropriate exception in the event of misconfiguration.

Please do consult the class level documentation for the Spring.Objects.Factory.IObjectFactory interface for a description of exactly when this method is invoked. In particular, it is worth noting that the Spring.Objects.Factory.IObjectFactoryAware and Spring.Context.IApplicationContextAware callbacks will have been invoked prior to this method being called.

HibernateTransactionManager ( ) : System

Initializes a new instance of the HibernateTransactionManager class.

HibernateTransactionManager ( ISessionFactory sessionFactory ) : System

Initializes a new instance of the HibernateTransactionManager class.

Protected Methods

Method Description
ConvertAdoAccessException ( ADOException ex, IAdoExceptionTranslator translator ) : Spring.Dao.DataAccessException

Convert the given ADOException to an appropriate exception from the the Spring.Dao hierarchy. Can be overridden in subclasses.

ConvertHibernateAccessException ( NHibernate.HibernateException ex ) : Spring.Dao.DataAccessException

Convert the given HibernateException to an appropriate exception from the Spring.Dao hierarchy. Can be overridden in subclasses.

DoBegin ( object transaction, ITransactionDefinition definition ) : void

Begin a new transaction with the given transaction definition.

Does not have to care about applying the propagation behavior, as this has already been handled by this abstract manager.

DoCleanupAfterCompletion ( object transaction ) : void

Cleanup resources after transaction completion.

This implemenation unbinds the SessionFactory and DbProvider from thread local storage and closes the ISession.

Called after M:Spring.Transaction.Support.AbstractPlatformTransactionManager.DoCommit(Spring.Transaction.Support.DefaultTransactionStatus) and M:Spring.Transaction.Support.AbstractPlatformTransactionManager.DoRollback(Spring.Transaction.Support.DefaultTransactionStatus) execution on any outcome.

Should not throw any exceptions but just issue warnings on errors.

DoCommit ( Spring.Transaction.Support.DefaultTransactionStatus status ) : void

Perform an actual commit on the given transaction.

An implementation does not need to check the rollback-only flag.

DoGetTransaction ( ) : object

Return the current transaction object.

DoResume ( object transaction, object suspendedResources ) : void

Resume the resources of the current transaction.

Transaction synchronization will be resumed afterwards.

DoRollback ( Spring.Transaction.Support.DefaultTransactionStatus status ) : void

Perform an actual rollback on the given transaction.

An implementation does not need to check the new transaction flag.

DoSetRollbackOnly ( Spring.Transaction.Support.DefaultTransactionStatus status ) : void

Set the given transaction rollback-only. Only called on rollback if the current transaction takes part in an existing one.

DoSuspend ( object transaction ) : object

Suspend the resources of the current transaction.

Transaction synchronization will already have been suspended.

GetIDbTransaction ( ITransaction hibernateTx ) : IDbTransaction

Gets the ADO.NET IDbTransaction object from the NHibernate ITransaction object.

IsExistingTransaction ( object transaction ) : bool

Check if the given transaction object indicates an existing, i.e. already begun, transaction.

Method Details

AfterPropertiesSet() public method

Invoked by an Spring.Objects.Factory.IObjectFactory after it has injected all of an object's dependencies.

This method allows the object instance to perform the kind of initialization only possible when all of it's dependencies have been injected (set), and to throw an appropriate exception in the event of misconfiguration.

Please do consult the class level documentation for the Spring.Objects.Factory.IObjectFactory interface for a description of exactly when this method is invoked. In particular, it is worth noting that the Spring.Objects.Factory.IObjectFactoryAware and Spring.Context.IApplicationContextAware callbacks will have been invoked prior to this method being called.

/// In the event of misconfiguration (such as the failure to set a /// required property) or if initialization fails. ///
public AfterPropertiesSet ( ) : void
return void

ConvertAdoAccessException() protected method

Convert the given ADOException to an appropriate exception from the the Spring.Dao hierarchy. Can be overridden in subclasses.
protected ConvertAdoAccessException ( ADOException ex, IAdoExceptionTranslator translator ) : Spring.Dao.DataAccessException
ex NHibernate.ADOException The ADOException that occured, wrapping the underlying /// ADO.NET thrown exception.
translator IAdoExceptionTranslator The translator to convert hibernate ADOExceptions.
return Spring.Dao.DataAccessException

ConvertHibernateAccessException() protected method

Convert the given HibernateException to an appropriate exception from the Spring.Dao hierarchy. Can be overridden in subclasses.
protected ConvertHibernateAccessException ( NHibernate.HibernateException ex ) : Spring.Dao.DataAccessException
ex NHibernate.HibernateException The HibernateException that occured.
return Spring.Dao.DataAccessException

DoBegin() protected method

Begin a new transaction with the given transaction definition.
Does not have to care about applying the propagation behavior, as this has already been handled by this abstract manager.
/// In the case of creation or system errors. ///
protected DoBegin ( object transaction, ITransactionDefinition definition ) : void
transaction object /// Transaction object returned by /// . ///
definition ITransactionDefinition /// instance, describing /// propagation behavior, isolation level, timeout etc. ///
return void

DoCleanupAfterCompletion() protected method

Cleanup resources after transaction completion.
This implemenation unbinds the SessionFactory and DbProvider from thread local storage and closes the ISession.

Called after M:Spring.Transaction.Support.AbstractPlatformTransactionManager.DoCommit(Spring.Transaction.Support.DefaultTransactionStatus) and M:Spring.Transaction.Support.AbstractPlatformTransactionManager.DoRollback(Spring.Transaction.Support.DefaultTransactionStatus) execution on any outcome.

Should not throw any exceptions but just issue warnings on errors.

protected DoCleanupAfterCompletion ( object transaction ) : void
transaction object Transaction object returned by /// .
return void

DoCommit() protected method

Perform an actual commit on the given transaction.

An implementation does not need to check the rollback-only flag.

/// In the case of system errors. ///
protected DoCommit ( Spring.Transaction.Support.DefaultTransactionStatus status ) : void
status Spring.Transaction.Support.DefaultTransactionStatus The status representation of the transaction.
return void

DoGetTransaction() protected method

Return the current transaction object.
/// If transaction support is not available. /// /// In the case of lookup or system errors. ///
protected DoGetTransaction ( ) : object
return object

DoResume() protected method

Resume the resources of the current transaction.
Transaction synchronization will be resumed afterwards.
/// If suspending is not supported by the transaction manager implementation. /// /// In the case of system errors. ///
protected DoResume ( object transaction, object suspendedResources ) : void
transaction object /// Transaction object returned by /// . ///
suspendedResources object /// The object that holds suspended resources as returned by /// . ///
return void

DoRollback() protected method

Perform an actual rollback on the given transaction.
An implementation does not need to check the new transaction flag.
/// In the case of system errors. ///
protected DoRollback ( Spring.Transaction.Support.DefaultTransactionStatus status ) : void
status Spring.Transaction.Support.DefaultTransactionStatus The status representation of the transaction.
return void

DoSetRollbackOnly() protected method

Set the given transaction rollback-only. Only called on rollback if the current transaction takes part in an existing one.
/// In the case of system errors. ///
protected DoSetRollbackOnly ( Spring.Transaction.Support.DefaultTransactionStatus status ) : void
status Spring.Transaction.Support.DefaultTransactionStatus The status representation of the transaction.
return void

DoSuspend() protected method

Suspend the resources of the current transaction.
Transaction synchronization will already have been suspended.
/// If suspending is not supported by the transaction manager implementation. /// /// in case of system errors. ///
protected DoSuspend ( object transaction ) : object
transaction object /// Transaction object returned by /// . ///
return object

GetIDbTransaction() protected method

Gets the ADO.NET IDbTransaction object from the NHibernate ITransaction object.
protected GetIDbTransaction ( ITransaction hibernateTx ) : IDbTransaction
hibernateTx ITransaction The hibernate transaction.
return IDbTransaction

HibernateTransactionManager() public method

Initializes a new instance of the HibernateTransactionManager class.
public HibernateTransactionManager ( ) : System
return System

HibernateTransactionManager() public method

Initializes a new instance of the HibernateTransactionManager class.
public HibernateTransactionManager ( ISessionFactory sessionFactory ) : System
sessionFactory ISessionFactory The session factory.
return System

IsExistingTransaction() protected method

Check if the given transaction object indicates an existing, i.e. already begun, transaction.
/// In the case of system errors. ///
protected IsExistingTransaction ( object transaction ) : bool
transaction object /// Transaction object returned by /// . ///
return bool