C# Класс 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.
Показать файл Открыть проект

Private Properties

Свойство Тип Описание
AutoMappings ISessionFactory
BeginTransaction void
GetSession ISession
IsInWebContext bool
NHibernateSessionManager System

Открытые методы

Метод Описание
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.

Приватные методы

Метод Описание
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.

Описание методов

BeginTransaction() публичный Метод

Begins the transaction.
public BeginTransaction ( ) : void
Результат void

CloseSession() публичный Метод

Closes the session.
public CloseSession ( ) : void
Результат void

CloseSessionFactory() публичный Метод

Closes the session and the disposes the session factory
public CloseSessionFactory ( ) : void
Результат void

CommitTransaction() публичный Метод

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
Результат void

ExportDatabaseSchema() публичный Метод

Exports the database schema.
public ExportDatabaseSchema ( ) : void
Результат void

GetSession() публичный Метод

Gets the session.
public GetSession ( ) : ISession
Результат ISession

ImportDatabaseSchema() публичный Метод

Imports the database schema.
public ImportDatabaseSchema ( ) : void
Результат void

InitSessionFactory() публичный Метод

public InitSessionFactory ( ) : void
Результат void

InitSessionFactory() публичный Метод

Inits the session factory.
public InitSessionFactory ( string xmlConfigFile ) : void
xmlConfigFile string
Результат void

OpenNewSession() публичный Метод

public OpenNewSession ( ) : ISession
Результат ISession

RegisterInterceptor() публичный Метод

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
Результат void

RollbackTransaction() публичный Метод

Rollbacks the transaction.
public RollbackTransaction ( ) : void
Результат void