C# 클래스 Spring.Data.NHibernate.SessionFactoryUtils

Helper class featuring methods for Hibernate Session handling, allowing for reuse of Hibernate Session instances within transactions. Also provides support for exception translation.
파일 보기 프로젝트 열기: spring-projects/spring-net 1 사용 예제들

공개 프로퍼티들

프로퍼티 타입 설명
SESSION_SYNCHRONIZATION_ORDER int

공개 메소드들

메소드 설명
ApplyTransactionTimeout ( ICriteria criteria, ISessionFactory sessionFactory ) : void

Applies the current transaction timeout, if any, to the given criteria object

ApplyTransactionTimeout ( IQuery query, ISessionFactory sessionFactory ) : void

Applies the current transaction timeout, if any, to the given Hibenrate query object.

CloseSession ( ISession session ) : void

Perform the actual closing of the Hibernate Session catching and logging any cleanup exceptions thrown.

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

Converts a Hibernate ADOException to a Spring DataAccessExcption, extracting the underlying error code from ADO.NET. Will extract the ADOException Message and SqlString properties and pass them to the translate method of the provided IAdoExceptionTranslator.

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

Convert the given HibernateException to an appropriate exception from the Spring.Dao hierarchy. Note that it is advisable to handle AdoException specifically by using a AdoExceptionTranslator for the underlying ADO.NET exception.

DoGetSession ( ISessionFactory sessionFactory, bool allowCreate ) : ISession

Get a Hibernate Session for the given SessionFactory.

Is aware of and will return any existing corresponding Session bound to the current thread, for example whenusing HibernateTransactionManager. Will create a new Session otherwise, if "allowCreate" is true.

Throws the orginal HibernateException, in contrast to GetSession(ISessionFactory, bool).

GetDbProvider ( ISessionFactory sessionFactory ) : IDbProvider

Gets the Spring IDbProvider given the ISessionFactory.

The matching is performed by comparing the assembly qualified name string of the hibernate Driver.ConnectionType to those in the DbProviderFactory definitions. No connections are created in performing this comparison.

GetNewSession ( ISessionFactory sessionFactory, IInterceptor interceptor ) : ISession

Get a new Hibernate Session from the given SessionFactory. Will return a new Session even if there already is a pre-bound Session for the given SessionFactory.

Within a transaction, this method will create a new Session that shares the transaction's ADO.NET Connection. More specifically, it will use the same ADO.NET Connection as the pre-bound Hibernate Session.

GetSession ( ISessionFactory sessionFactory, IInterceptor entityInterceptor, IAdoExceptionTranslator adoExceptionTranslator ) : ISession

Get a Hibernate Session for the given SessionFactory. Is aware of and will return any existing corresponding Session bound to the current thread, for example when using HibernateTransactionManager. Will always create a new Session otherwise.

Supports setting a Session-level Hibernate entity interceptor that allows to inspect and change property values before writing to and reading from the database. Such an interceptor can also be set at the SessionFactory level (i.e. on LocalSessionFactoryObject), on HibernateTransactionManager, or on HibernateInterceptor/HibernateTemplate.

GetSession ( ISessionFactory sessionFactory, bool allowCreate ) : ISession

Get a Hibernate Session for the given SessionFactory. Is aware of and will return any existing corresponding Session bound to the current thread, for example when using HibernateTransactionManager. Will create a new Session otherwise, if allowCreate is true.

InitDeferredClose ( ISessionFactory sessionFactory ) : void

Initialize deferred close for the current thread and the given SessionFactory. Sessions will not be actually closed on close calls then, but rather at a processDeferredClose call at a finishing point (like request completion).

IsDeferredCloseActive ( ISessionFactory sessionFactory ) : bool

Return if deferred close is active for the current thread and the given SessionFactory.

IsSessionTransactional ( ISession session, ISessionFactory sessionFactory ) : bool

Return whether the given Hibernate Session is transactional, that is, bound to the current thread by Spring's transaction facilities.

NewAdoExceptionTranslator ( ISessionFactory sessionFactory ) : IAdoExceptionTranslator

Create a IAdoExceptionTranslator from the given SessionFactory.

If a corresponding IDbProvider is found, a ErrorcodeExceptionTranslator for the IDbProvider is created. Otherwise, a FallbackException is created.

ProcessDeferredClose ( ISessionFactory sessionFactory ) : void

Process Sessions that have been registered for deferred close for the given SessionFactory.

ReleaseSession ( ISession session, ISessionFactory sessionFactory ) : void

Close the given Session, created via the given factory, if it is not managed externally (i.e. not bound to the thread).

SessionFactoryUtils ( ) : System

Initializes a new instance of the SessionFactoryUtils class.

비공개 메소드들

메소드 설명
CloseSessionOrRegisterDeferredClose ( ISession session, ISessionFactory sessionFactory ) : void

Close the given Session or register it for deferred close.

DoGetSession ( ISessionFactory sessionFactory, IInterceptor entityInterceptor, IAdoExceptionTranslator adoExceptionTranslator, bool allowCreate ) : ISession
GetSession ( ISessionFactory sessionFactory, IInterceptor entityInterceptor, IAdoExceptionTranslator adoExceptionTranslator, bool allowCreate ) : ISession
OpenSession ( ISessionFactory sessionFactory, IInterceptor entityInterceptor ) : ISession

Open a new Session from the factory.

메소드 상세

ApplyTransactionTimeout() 공개 정적인 메소드

Applies the current transaction timeout, if any, to the given criteria object
If criteria argument is null.
public static ApplyTransactionTimeout ( ICriteria criteria, ISessionFactory sessionFactory ) : void
criteria ICriteria The Hibernate Criteria object.
sessionFactory ISessionFactory Hibernate SessionFactory that the Criteria was created for /// (can be null).
리턴 void

ApplyTransactionTimeout() 공개 정적인 메소드

Applies the current transaction timeout, if any, to the given Hibenrate query object.
If query argument is null.
public static ApplyTransactionTimeout ( IQuery query, ISessionFactory sessionFactory ) : void
query IQuery The Hibernate Query object.
sessionFactory ISessionFactory Hibernate SessionFactory that the Query was created for /// (can be null).
리턴 void

CloseSession() 공개 정적인 메소드

Perform the actual closing of the Hibernate Session catching and logging any cleanup exceptions thrown.
public static CloseSession ( ISession session ) : void
session ISession The hibernate session to close
리턴 void

ConvertAdoAccessException() 공개 정적인 메소드

Converts a Hibernate ADOException to a Spring DataAccessExcption, extracting the underlying error code from ADO.NET. Will extract the ADOException Message and SqlString properties and pass them to the translate method of the provided IAdoExceptionTranslator.
public static ConvertAdoAccessException ( IAdoExceptionTranslator translator, ADOException ex ) : Spring.Dao.DataAccessException
translator IAdoExceptionTranslator The IAdoExceptionTranslator, may be a user provided implementation as configured on /// HibernateTemplate. ///
ex NHibernate.ADOException The ADOException throw
리턴 Spring.Dao.DataAccessException

ConvertHibernateAccessException() 공개 정적인 메소드

Convert the given HibernateException to an appropriate exception from the Spring.Dao hierarchy. Note that it is advisable to handle AdoException specifically by using a AdoExceptionTranslator for the underlying ADO.NET exception.
public static ConvertHibernateAccessException ( NHibernate.HibernateException ex ) : Spring.Dao.DataAccessException
ex NHibernate.HibernateException The Hibernate exception that occured.
리턴 Spring.Dao.DataAccessException

DoGetSession() 공개 정적인 메소드

Get a Hibernate Session for the given SessionFactory.
Is aware of and will return any existing corresponding Session bound to the current thread, for example whenusing HibernateTransactionManager. Will create a new Session otherwise, if "allowCreate" is true.

Throws the orginal HibernateException, in contrast to GetSession(ISessionFactory, bool).

/// if the Session couldn't be created /// /// If no thread-bound Session found and allowCreate is false. ///
public static DoGetSession ( ISessionFactory sessionFactory, bool allowCreate ) : ISession
sessionFactory ISessionFactory The session factory.
allowCreate bool if set to true [allow create].
리턴 ISession

GetDbProvider() 공개 정적인 메소드

Gets the Spring IDbProvider given the ISessionFactory.
The matching is performed by comparing the assembly qualified name string of the hibernate Driver.ConnectionType to those in the DbProviderFactory definitions. No connections are created in performing this comparison.
If DbProviderFactory's ApplicaitonContext is not /// an instance of IConfigurableApplicaitonContext.
public static GetDbProvider ( ISessionFactory sessionFactory ) : IDbProvider
sessionFactory ISessionFactory The session factory.
리턴 IDbProvider

GetNewSession() 공개 정적인 메소드

Get a new Hibernate Session from the given SessionFactory. Will return a new Session even if there already is a pre-bound Session for the given SessionFactory.
Within a transaction, this method will create a new Session that shares the transaction's ADO.NET Connection. More specifically, it will use the same ADO.NET Connection as the pre-bound Hibernate Session.
If could not open Hibernate session
public static GetNewSession ( ISessionFactory sessionFactory, IInterceptor interceptor ) : ISession
sessionFactory ISessionFactory The session factory to create the session with.
interceptor IInterceptor The Hibernate entity interceptor, or null if none.
리턴 ISession

GetSession() 공개 정적인 메소드

Get a Hibernate Session for the given SessionFactory. Is aware of and will return any existing corresponding Session bound to the current thread, for example when using HibernateTransactionManager. Will always create a new Session otherwise.
Supports setting a Session-level Hibernate entity interceptor that allows to inspect and change property values before writing to and reading from the database. Such an interceptor can also be set at the SessionFactory level (i.e. on LocalSessionFactoryObject), on HibernateTransactionManager, or on HibernateInterceptor/HibernateTemplate.
/// If the session couldn't be created. /// /// If no thread-bound Session found and allowCreate is false. ///
public static GetSession ( ISessionFactory sessionFactory, IInterceptor entityInterceptor, IAdoExceptionTranslator adoExceptionTranslator ) : ISession
sessionFactory ISessionFactory The session factory to create the /// session with.
entityInterceptor IInterceptor Hibernate entity interceptor, or null if none.
adoExceptionTranslator IAdoExceptionTranslator AdoExceptionTranslator to use for flushing the /// Session on transaction synchronization (can be null; only used when actually /// registering a transaction synchronization).
리턴 ISession

GetSession() 공개 정적인 메소드

Get a Hibernate Session for the given SessionFactory. Is aware of and will return any existing corresponding Session bound to the current thread, for example when using HibernateTransactionManager. Will create a new Session otherwise, if allowCreate is true.
/// If the session couldn't be created. /// /// If no thread-bound Session found and allowCreate is false. ///
public static GetSession ( ISessionFactory sessionFactory, bool allowCreate ) : ISession
sessionFactory ISessionFactory The session factory to create the session with.
allowCreate bool if set to true create a non-transactional Session when no /// transactional Session can be found for the current thread.
리턴 ISession

InitDeferredClose() 공개 정적인 메소드

Initialize deferred close for the current thread and the given SessionFactory. Sessions will not be actually closed on close calls then, but rather at a processDeferredClose call at a finishing point (like request completion).
public static InitDeferredClose ( ISessionFactory sessionFactory ) : void
sessionFactory ISessionFactory The session factory.
리턴 void

IsDeferredCloseActive() 공개 정적인 메소드

Return if deferred close is active for the current thread and the given SessionFactory.
If SessionFactory argument is null.
public static IsDeferredCloseActive ( ISessionFactory sessionFactory ) : bool
sessionFactory ISessionFactory The session factory.
리턴 bool

IsSessionTransactional() 공개 정적인 메소드

Return whether the given Hibernate Session is transactional, that is, bound to the current thread by Spring's transaction facilities.
public static IsSessionTransactional ( ISession session, ISessionFactory sessionFactory ) : bool
session ISession The hibernate session to check
sessionFactory ISessionFactory The session factory that the session /// was created with, can be null.
리턴 bool

NewAdoExceptionTranslator() 공개 정적인 메소드

Create a IAdoExceptionTranslator from the given SessionFactory.
If a corresponding IDbProvider is found, a ErrorcodeExceptionTranslator for the IDbProvider is created. Otherwise, a FallbackException is created.
public static NewAdoExceptionTranslator ( ISessionFactory sessionFactory ) : IAdoExceptionTranslator
sessionFactory ISessionFactory The session factory to create the translator for
리턴 IAdoExceptionTranslator

ProcessDeferredClose() 공개 정적인 메소드

Process Sessions that have been registered for deferred close for the given SessionFactory.
If there is no session factory associated with the thread.
public static ProcessDeferredClose ( ISessionFactory sessionFactory ) : void
sessionFactory ISessionFactory The session factory.
리턴 void

ReleaseSession() 공개 정적인 메소드

Close the given Session, created via the given factory, if it is not managed externally (i.e. not bound to the thread).
public static ReleaseSession ( ISession session, ISessionFactory sessionFactory ) : void
session ISession The hibernate session to close
sessionFactory ISessionFactory The hibernate SessionFactory that /// the session was created with.
리턴 void

SessionFactoryUtils() 공개 메소드

Initializes a new instance of the SessionFactoryUtils class.
public SessionFactoryUtils ( ) : System
리턴 System

프로퍼티 상세

SESSION_SYNCHRONIZATION_ORDER 공개적으로 정적으로 프로퍼티

The ordering value for synchronizaiton this session resources. Set to be lower than ADO.NET synchronization.
public static int SESSION_SYNCHRONIZATION_ORDER
리턴 int