diff options
author | Justin Clarke Casey | 2009-01-20 18:27:30 +0000 |
---|---|---|
committer | Justin Clarke Casey | 2009-01-20 18:27:30 +0000 |
commit | 84a4a9ecf71eca102eff785430d0ccc27c3fdb2f (patch) | |
tree | a275cae1118f91afa5daa13cbe22bd521b278298 /OpenSim/Data/NHibernate | |
parent | Removed some of the darker colors from console messages as they were not visi... (diff) | |
download | opensim-SC-84a4a9ecf71eca102eff785430d0ccc27c3fdb2f.zip opensim-SC-84a4a9ecf71eca102eff785430d0ccc27c3fdb2f.tar.gz opensim-SC-84a4a9ecf71eca102eff785430d0ccc27c3fdb2f.tar.bz2 opensim-SC-84a4a9ecf71eca102eff785430d0ccc27c3fdb2f.tar.xz |
* Apply http://opensimulator.org/mantis/view.php?id=3012
* Allows different assemblies to be used in NHibernateManager, which makes it possible to use mapping and migration files in different assemblies.
* Thanks mpallari!
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Data/NHibernate/NHibernateManager.cs | 59 |
1 files changed, 49 insertions, 10 deletions
diff --git a/OpenSim/Data/NHibernate/NHibernateManager.cs b/OpenSim/Data/NHibernate/NHibernateManager.cs index 0692f26..0ceaf9b 100644 --- a/OpenSim/Data/NHibernate/NHibernateManager.cs +++ b/OpenSim/Data/NHibernate/NHibernateManager.cs | |||
@@ -45,9 +45,12 @@ namespace OpenSim.Data.NHibernate | |||
45 | private Configuration configuration; | 45 | private Configuration configuration; |
46 | private ISessionFactory sessionFactory; | 46 | private ISessionFactory sessionFactory; |
47 | 47 | ||
48 | public NHibernateManager(string connect, string store) | 48 | /// <summary> |
49 | /// Parses the connection string and creates the NHibernate configuration | ||
50 | /// </summary> | ||
51 | /// <param name="connect">NHibernate dialect, driver and connection string separated by ';'</param> | ||
52 | private void parseConnectionString(string connect) | ||
49 | { | 53 | { |
50 | |||
51 | // Split out the dialect, driver, and connect string | 54 | // Split out the dialect, driver, and connect string |
52 | char[] split = { ';' }; | 55 | char[] split = { ';' }; |
53 | string[] parts = connect.Split(split, 3); | 56 | string[] parts = connect.Split(split, 3); |
@@ -70,28 +73,64 @@ namespace OpenSim.Data.NHibernate | |||
70 | configuration.SetProperty(Environment.ConnectionString, parts[2]); | 73 | configuration.SetProperty(Environment.ConnectionString, parts[2]); |
71 | configuration.AddAssembly("OpenSim.Data.NHibernate"); | 74 | configuration.AddAssembly("OpenSim.Data.NHibernate"); |
72 | 75 | ||
73 | //To create sql file uncomment code below and write the name of the file | ||
74 | //SchemaExport exp = new SchemaExport(cfg); | ||
75 | //exp.SetOutputFile("nameofthefile.sql"); | ||
76 | //exp.Create(false, true); | ||
77 | |||
78 | sessionFactory = configuration.BuildSessionFactory(); | 76 | sessionFactory = configuration.BuildSessionFactory(); |
77 | } | ||
79 | 78 | ||
80 | Assembly assembly = GetType().Assembly; | 79 | /// <summary> |
81 | 80 | /// Runs migration for the the store in assembly | |
81 | /// </summary> | ||
82 | /// <param name="dialect">Dialect in use</param> | ||
83 | /// <param name="assembly">Assembly where migration files exist</param> | ||
84 | /// <param name="store">Name of the store in use</param> | ||
85 | private void runMigration(string dialect, Assembly assembly, string store) | ||
86 | { | ||
82 | // Migration subtype is the folder name under which migrations are stored. For mysql this folder is | 87 | // Migration subtype is the folder name under which migrations are stored. For mysql this folder is |
83 | // MySQLDialect instead of MySQL5Dialect which is the dialect currently in use. To avoid renaming | 88 | // MySQLDialect instead of MySQL5Dialect which is the dialect currently in use. To avoid renaming |
84 | // this folder each time the mysql version changes creating simple mapping: | 89 | // this folder each time the mysql version changes creating simple mapping: |
85 | String migrationSubType = dialect; | 90 | String migrationSubType = dialect; |
86 | if (dialect.StartsWith("MySQL")) | 91 | if (dialect.StartsWith("MySQL")) |
87 | { | 92 | { |
88 | migrationSubType="MySQLDialect"; | 93 | migrationSubType = "MySQLDialect"; |
89 | } | 94 | } |
90 | 95 | ||
91 | Migration migration = new Migration((System.Data.Common.DbConnection)sessionFactory.ConnectionProvider.GetConnection(), assembly, migrationSubType, store); | 96 | Migration migration = new Migration((System.Data.Common.DbConnection)sessionFactory.ConnectionProvider.GetConnection(), assembly, migrationSubType, store); |
92 | migration.Update(); | 97 | migration.Update(); |
93 | } | 98 | } |
94 | 99 | ||
100 | /// <summary> | ||
101 | /// Initiate NHibernate Manager | ||
102 | /// </summary> | ||
103 | /// <param name="connect">NHibernate dialect, driver and connection string separated by ';'</param> | ||
104 | /// <param name="store">Name of the store</param> | ||
105 | public NHibernateManager(string connect, string store) | ||
106 | { | ||
107 | parseConnectionString(connect); | ||
108 | |||
109 | //To create sql file uncomment code below and write the name of the file | ||
110 | //SchemaExport exp = new SchemaExport(cfg); | ||
111 | //exp.SetOutputFile("nameofthefile.sql"); | ||
112 | //exp.Create(false, true); | ||
113 | |||
114 | Assembly assembly = GetType().Assembly; | ||
115 | |||
116 | runMigration(dialect, assembly, store); | ||
117 | } | ||
118 | |||
119 | /// <summary> | ||
120 | /// Initiate NHibernate Manager with spesific assembly | ||
121 | /// </summary> | ||
122 | /// <param name="connect">NHibernate dialect, driver and connection string separated by ';'</param> | ||
123 | /// <param name="store">Name of the store</param> | ||
124 | /// <param name="assembly"></param> | ||
125 | public NHibernateManager(string connect, string store, Assembly assembly) | ||
126 | { | ||
127 | parseConnectionString(connect); | ||
128 | |||
129 | configuration.AddAssembly(assembly); | ||
130 | |||
131 | runMigration(dialect, assembly, store); | ||
132 | } | ||
133 | |||
95 | public object Load(Type type, UUID uuid) | 134 | public object Load(Type type, UUID uuid) |
96 | { | 135 | { |
97 | using (IStatelessSession session = sessionFactory.OpenStatelessSession()) | 136 | using (IStatelessSession session = sessionFactory.OpenStatelessSession()) |