C# Class CAESDO.Recruitment.Data.NHibernateSessionManager

Handles creation and management of sessions and transactions. It is a singleton because building the initial session factory is very expensive. Inspiration for this class came from Chapter 8 of Hibernate in Action by Bauer and King. Although it is a sealed singleton you can use TypeMock (http://www.typemock.com) for more flexible testing.
Show file Open project: ucdavis/Recruitments

Private Properties

Property Type Description
GetSession ISession
InitSessionFactory void
IsInWebContext bool
NHibernateSessionManager System.Runtime.Remoting.Messaging

Public Methods

Method Description
BeginTransaction ( ) : void
CloseSession ( ) : void
CommitTransaction ( ) : void
EnsureFreshness ( object o ) : void

Make sure the object given is connected to the current session

GetSession ( ) : ISession
HasOpenTransaction ( ) : bool
RegisterInterceptor ( IInterceptor interceptor ) : void

Allows you to register an interceptor on a new session. This may not be called if there is already an open session attached to the HttpContext. If you have an interceptor to be used, modify the HttpModule to call this before calling BeginTransaction().

RollbackTransaction ( ) : void

Private Methods

Method Description
GetSession ( IInterceptor interceptor ) : ISession

Gets a session with or without an interceptor. This method is not called directly; instead, it gets invoked from other public methods.

InitSessionFactory ( ) : void
IsInWebContext ( ) : bool
NHibernateSessionManager ( ) : System.Runtime.Remoting.Messaging

Initializes the NHibernate session factory upon instantiation.

Method Details

BeginTransaction() public method

public BeginTransaction ( ) : void
return void

CloseSession() public method

public CloseSession ( ) : void
return void

CommitTransaction() public method

public CommitTransaction ( ) : void
return void

EnsureFreshness() public method

Make sure the object given is connected to the current session
public EnsureFreshness ( object o ) : void
o object Mapped Object
return void

GetSession() public method

public GetSession ( ) : ISession
return ISession

HasOpenTransaction() public method

public HasOpenTransaction ( ) : bool
return bool

RegisterInterceptor() public method

Allows you to register an interceptor on a new session. This may not be called if there is already an open session attached to the HttpContext. If you have an interceptor to be used, modify the HttpModule to call this before calling BeginTransaction().
public RegisterInterceptor ( IInterceptor interceptor ) : void
interceptor IInterceptor
return void

RollbackTransaction() public method

public RollbackTransaction ( ) : void
return void