C# Class Customer.Project.DataAccess.NHibernateHelpers.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.
显示文件 Open project: atosorigin/AtosMvcStarterKit

Private Properties

Property Type Description
AutoMappings ISessionFactory
BeginTransaction void
GetSession ISession
IsInWebContext bool
NHibernateSessionManager System

Public Methods

Method Description
BeginTransaction ( ) : void

Begins the transaction.

CloseSession ( ) : void

Closes the session.

CloseSessionFactory ( ) : void

Closes the session and the disposes the session factory

CommitTransaction ( ) : void

Commits the transaction / Unit of Work if autocommit is set to true, canceltransaction to false and if the transaction is not committed or rolled back yet

ExportDatabaseSchema ( ) : void

Exports the database schema.

GetSession ( ) : ISession

Gets the session.

ImportDatabaseSchema ( ) : void

Imports the database schema.

InitSessionFactory ( ) : void
InitSessionFactory ( string xmlConfigFile ) : void

Inits the session factory.

OpenNewSession ( ) : ISession
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

Rollbacks the transaction.

Private Methods

Method Description
AutoMappings ( ) : ISessionFactory
BeginTransaction ( ISession session ) : void
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.

IsInWebContext ( ) : bool
NHibernateSessionManager ( ) : System

Initializes the NHibernate session factory upon instantiation.

Method Details

BeginTransaction() public method

Begins the transaction.
public BeginTransaction ( ) : void
return void

CloseSession() public method

Closes the session.
public CloseSession ( ) : void
return void

CloseSessionFactory() public method

Closes the session and the disposes the session factory
public CloseSessionFactory ( ) : void
return void

CommitTransaction() public method

Commits the transaction / Unit of Work if autocommit is set to true, canceltransaction to false and if the transaction is not committed or rolled back yet
public CommitTransaction ( ) : void
return void

ExportDatabaseSchema() public method

Exports the database schema.
public ExportDatabaseSchema ( ) : void
return void

GetSession() public method

Gets the session.
public GetSession ( ) : ISession
return ISession

ImportDatabaseSchema() public method

Imports the database schema.
public ImportDatabaseSchema ( ) : void
return void

InitSessionFactory() public method

public InitSessionFactory ( ) : void
return void

InitSessionFactory() public method

Inits the session factory.
public InitSessionFactory ( string xmlConfigFile ) : void
xmlConfigFile string
return void

OpenNewSession() public method

public OpenNewSession ( ) : ISession
return ISession

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

Rollbacks the transaction.
public RollbackTransaction ( ) : void
return void