Feature: Log sql can be turned on or off from the Config file
This commit is contained in:
@ -17,17 +17,17 @@ namespace Tanshu.Accounts.Repository
|
||||
private readonly ISessionFactory factory;
|
||||
|
||||
private static SessionManager instance;
|
||||
private SessionManager()
|
||||
private SessionManager(bool forTesting)
|
||||
{
|
||||
cfg = ConfigureNHibernate();
|
||||
cfg = ConfigureNHibernate(forTesting);
|
||||
factory = cfg.BuildSessionFactory();
|
||||
}
|
||||
|
||||
public static void Initialize()
|
||||
public static void Initialize(bool forTesting)
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
instance = new SessionManager();
|
||||
instance = new SessionManager(forTesting);
|
||||
}
|
||||
}
|
||||
public static ISession Session
|
||||
@ -35,9 +35,7 @@ namespace Tanshu.Accounts.Repository
|
||||
get
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
instance = new SessionManager();
|
||||
}
|
||||
throw new ApplicationException("Session factory not initalized. Cannot get Session");
|
||||
return instance.GetSession();
|
||||
}
|
||||
}
|
||||
@ -46,29 +44,11 @@ namespace Tanshu.Accounts.Repository
|
||||
get
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
instance = new SessionManager();
|
||||
}
|
||||
throw new ApplicationException("Session factory not initalized. Cannot get Session");
|
||||
return instance.GetStatelessSession();
|
||||
}
|
||||
}
|
||||
public static Configuration Configuration
|
||||
{
|
||||
get
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
instance = new SessionManager();
|
||||
}
|
||||
return instance.GetConfiguration();
|
||||
}
|
||||
|
||||
}
|
||||
private Configuration GetConfiguration()
|
||||
{
|
||||
return cfg;
|
||||
}
|
||||
private Configuration ConfigureNHibernate()
|
||||
private Configuration ConfigureNHibernate(bool forTesting)
|
||||
{
|
||||
var configure = new Configuration();
|
||||
configure.SessionFactoryName("BuildIt");
|
||||
@ -81,10 +61,14 @@ namespace Tanshu.Accounts.Repository
|
||||
db.IsolationLevel = IsolationLevel.ReadCommitted;
|
||||
db.ConnectionStringName = "Con";
|
||||
db.Timeout = 10;
|
||||
// enabled for testing
|
||||
//db.LogFormattedSql = true;
|
||||
//db.LogSqlInConsole = true;
|
||||
//db.AutoCommentSql = true;
|
||||
|
||||
if (forTesting)
|
||||
{
|
||||
// enabled for testing
|
||||
db.LogFormattedSql = true;
|
||||
db.LogSqlInConsole = true;
|
||||
db.AutoCommentSql = true;
|
||||
}
|
||||
});
|
||||
|
||||
var mapping = GetMappings();
|
||||
|
||||
Reference in New Issue
Block a user