From 84a4a9ecf71eca102eff785430d0ccc27c3fdb2f Mon Sep 17 00:00:00 2001 From: Justin Clarke Casey Date: Tue, 20 Jan 2009 18:27:30 +0000 Subject: * 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! --- OpenSim/Data/NHibernate/NHibernateManager.cs | 59 +++++++++++++++++++++++----- 1 file changed, 49 insertions(+), 10 deletions(-) (limited to 'OpenSim/Data/NHibernate/NHibernateManager.cs') 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 private Configuration configuration; private ISessionFactory sessionFactory; - public NHibernateManager(string connect, string store) + /// + /// Parses the connection string and creates the NHibernate configuration + /// + /// NHibernate dialect, driver and connection string separated by ';' + private void parseConnectionString(string connect) { - // Split out the dialect, driver, and connect string char[] split = { ';' }; string[] parts = connect.Split(split, 3); @@ -70,28 +73,64 @@ namespace OpenSim.Data.NHibernate configuration.SetProperty(Environment.ConnectionString, parts[2]); configuration.AddAssembly("OpenSim.Data.NHibernate"); - //To create sql file uncomment code below and write the name of the file - //SchemaExport exp = new SchemaExport(cfg); - //exp.SetOutputFile("nameofthefile.sql"); - //exp.Create(false, true); - sessionFactory = configuration.BuildSessionFactory(); + } - Assembly assembly = GetType().Assembly; - + /// + /// Runs migration for the the store in assembly + /// + /// Dialect in use + /// Assembly where migration files exist + /// Name of the store in use + private void runMigration(string dialect, Assembly assembly, string store) + { // Migration subtype is the folder name under which migrations are stored. For mysql this folder is // MySQLDialect instead of MySQL5Dialect which is the dialect currently in use. To avoid renaming // this folder each time the mysql version changes creating simple mapping: String migrationSubType = dialect; if (dialect.StartsWith("MySQL")) { - migrationSubType="MySQLDialect"; + migrationSubType = "MySQLDialect"; } Migration migration = new Migration((System.Data.Common.DbConnection)sessionFactory.ConnectionProvider.GetConnection(), assembly, migrationSubType, store); migration.Update(); } + /// + /// Initiate NHibernate Manager + /// + /// NHibernate dialect, driver and connection string separated by ';' + /// Name of the store + public NHibernateManager(string connect, string store) + { + parseConnectionString(connect); + + //To create sql file uncomment code below and write the name of the file + //SchemaExport exp = new SchemaExport(cfg); + //exp.SetOutputFile("nameofthefile.sql"); + //exp.Create(false, true); + + Assembly assembly = GetType().Assembly; + + runMigration(dialect, assembly, store); + } + + /// + /// Initiate NHibernate Manager with spesific assembly + /// + /// NHibernate dialect, driver and connection string separated by ';' + /// Name of the store + /// + public NHibernateManager(string connect, string store, Assembly assembly) + { + parseConnectionString(connect); + + configuration.AddAssembly(assembly); + + runMigration(dialect, assembly, store); + } + public object Load(Type type, UUID uuid) { using (IStatelessSession session = sessionFactory.OpenStatelessSession()) -- cgit v1.1