2011-01-31 20:33:22 +00:00
|
|
|
|
using FluentNHibernate.Automapping;
|
2011-01-30 07:14:05 +00:00
|
|
|
|
using FluentNHibernate.Cfg;
|
|
|
|
|
using FluentNHibernate.Cfg.Db;
|
|
|
|
|
using NHibernate;
|
|
|
|
|
using NHibernate.Cfg;
|
2011-01-31 20:33:22 +00:00
|
|
|
|
using Tanshu.Accounts.Conventions;
|
|
|
|
|
using Tanshu.Accounts.Entities;
|
|
|
|
|
using Tanshu.Accounts.SqlDAO;
|
2011-01-30 07:14:05 +00:00
|
|
|
|
|
2011-01-31 20:33:22 +00:00
|
|
|
|
namespace Tanshu.Accounts.Repository
|
2011-01-30 07:14:05 +00:00
|
|
|
|
{
|
|
|
|
|
public sealed class SessionManager
|
|
|
|
|
{
|
|
|
|
|
private readonly Configuration cfg;
|
|
|
|
|
private readonly ISessionFactory factory;
|
|
|
|
|
private SessionManager()
|
|
|
|
|
{
|
|
|
|
|
cfg = GetConfiguration();
|
|
|
|
|
factory = cfg.BuildSessionFactory();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//public static SessionManager Instance
|
|
|
|
|
//{
|
|
|
|
|
// get { return Nested.sessionManager; }
|
|
|
|
|
//}
|
|
|
|
|
public static ISession Session
|
|
|
|
|
{
|
|
|
|
|
get { return Nested.sessionManager.GetSession(); }
|
|
|
|
|
}
|
2011-01-31 20:33:22 +00:00
|
|
|
|
public static IStatelessSession StatelessSession
|
|
|
|
|
{
|
|
|
|
|
get { return Nested.sessionManager.GetStatelessSession(); }
|
|
|
|
|
}
|
2011-01-30 07:14:05 +00:00
|
|
|
|
public static Configuration Configuration
|
|
|
|
|
{
|
|
|
|
|
get { return Nested.sessionManager.GetConfiguration(); }
|
|
|
|
|
}
|
|
|
|
|
private class Nested
|
|
|
|
|
{
|
|
|
|
|
static Nested() { }
|
|
|
|
|
internal static readonly SessionManager sessionManager = new SessionManager();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Configuration GetConfiguration()
|
|
|
|
|
{
|
|
|
|
|
var storeConfiguration = new StoreConfiguration();
|
|
|
|
|
var persistenceModel = AutoMap.AssemblyOf<Voucher>(storeConfiguration)
|
|
|
|
|
.Conventions.Setup(c =>
|
|
|
|
|
{
|
|
|
|
|
c.Add<PrimaryKeyConvention>();
|
|
|
|
|
c.Add<CustomForeignKeyConvention>();
|
|
|
|
|
c.Add<ClassConvention>();
|
2011-01-31 20:33:22 +00:00
|
|
|
|
c.Add<CascadeConvention>();
|
2011-02-04 19:30:55 +00:00
|
|
|
|
//c.Add<AllowNullConvention>();
|
|
|
|
|
//c.Add<NotNullConvention>();
|
2011-01-31 20:33:22 +00:00
|
|
|
|
//c.Add(DefaultLazy.Never());
|
2011-01-30 07:14:05 +00:00
|
|
|
|
//c.Add<EnumConvention>();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return Fluently.Configure()
|
|
|
|
|
.Database(MsSqlConfiguration.MsSql2005.ConnectionString(p => p.FromConnectionStringWithKey("FluentCon")))
|
|
|
|
|
.Mappings(m => m.AutoMappings.Add(persistenceModel))
|
|
|
|
|
.BuildConfiguration()
|
|
|
|
|
.SetInterceptor(new NHSQLInterceptor());
|
|
|
|
|
}
|
|
|
|
|
public ISession GetSession()
|
|
|
|
|
{
|
|
|
|
|
return factory.OpenSession();
|
|
|
|
|
}
|
2011-01-31 20:33:22 +00:00
|
|
|
|
public IStatelessSession GetStatelessSession()
|
|
|
|
|
{
|
|
|
|
|
return factory.OpenStatelessSession();
|
|
|
|
|
}
|
2011-01-30 07:14:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|