This repository has been archived by the owner on Oct 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NHibInstaller.cs
70 lines (62 loc) · 1.74 KB
/
NHibInstaller.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using Castle.Facilities.NHibernate;
using Castle.Transactions;
using NHibernate;
using NHibernate.Cfg;
using NHibernate.Mapping.Attributes;
using NHibernate.Tool.hbm2ddl;
namespace SimpleToDo
{
public class NHibInstaller : INHibernateInstaller
{
private readonly Maybe<IInterceptor> interceptor;
private Configuration config;
public NHibInstaller()
{
interceptor = Maybe.None<IInterceptor>();
}
public void Registered(ISessionFactory factory)
{
}
public bool IsDefault
{
get { return true; }
}
public string SessionFactoryKey
{
get { return "default"; }
}
public Maybe<IInterceptor> Interceptor
{
get { return interceptor; }
}
public Configuration Config
{
get
{
if (config == null)
{
IDictionary<string, string> props = new Dictionary<string, string>()
{
{"connection.driver_class", "NHibernate.Driver.NpgsqlDriver"},
{"connection.connection_string", "Server=localhost; Port=5432; User Id=test; Password=test; Database=testdb;"},
{"dialect", "NHibernate.Dialect.PostgreSQL82Dialect"},
{"show_sql", "true"}
};
HbmSerializer.Default.Serialize(Assembly.GetExecutingAssembly(), "schema.hbm.xml");
config = new Configuration()
.SetProperties(props)
.AddInputStream(HbmSerializer.Default.Serialize(Assembly.GetExecutingAssembly()));
// apply schema
new SchemaUpdate(config).Execute(false, true);
}
return config;
}
}
}
}