C# Class UCDArch.Data.NHibernate.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.
Mostrar archivo Open project: ucdavis/UCDArch

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

Shortcut which just calls into the GetSession overload with the current registered interceptor. If no interceptor has been registered, it will be null

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

Allows you to set the interceptor which will be used in all subsequent sessions

RollbackTransaction ( ) : void
SetFlushMode ( FlushMode flushMode ) : void

Allows you to set the flush mode which will be used with all sessions

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

Shortcut which just calls into the GetSession overload with the current registered interceptor. If no interceptor has been registered, it will be null
public GetSession ( ) : ISession
return ISession

HasOpenTransaction() public method

public HasOpenTransaction ( ) : bool
return bool

RegisterInterceptor() public method

Allows you to set the interceptor which will be used in all subsequent sessions
public RegisterInterceptor ( IInterceptor interceptor ) : void
interceptor IInterceptor
return void

RollbackTransaction() public method

public RollbackTransaction ( ) : void
return void

SetFlushMode() public method

Allows you to set the flush mode which will be used with all sessions
public SetFlushMode ( FlushMode flushMode ) : void
flushMode FlushMode
return void