* Allows different assemblies to be used in NHibernateManager, which makes it possible to use mapping and migration files in different assemblies. * Thanks mpallari!0.6.3-post-fixes
parent
e94d862db2
commit
84a4a9ecf7
|
@ -67,6 +67,7 @@ Patches
|
||||||
* Mic Bowman
|
* Mic Bowman
|
||||||
* mikkopa/_someone - RealXtend
|
* mikkopa/_someone - RealXtend
|
||||||
* Mircea Kitsune
|
* Mircea Kitsune
|
||||||
|
* mpallari
|
||||||
* nlin
|
* nlin
|
||||||
* nornalbion
|
* nornalbion
|
||||||
* openlifegrid.com
|
* openlifegrid.com
|
||||||
|
|
|
@ -45,9 +45,12 @@ namespace OpenSim.Data.NHibernate
|
||||||
private Configuration configuration;
|
private Configuration configuration;
|
||||||
private ISessionFactory sessionFactory;
|
private ISessionFactory sessionFactory;
|
||||||
|
|
||||||
public NHibernateManager(string connect, string store)
|
/// <summary>
|
||||||
|
/// Parses the connection string and creates the NHibernate configuration
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="connect">NHibernate dialect, driver and connection string separated by ';'</param>
|
||||||
|
private void parseConnectionString(string connect)
|
||||||
{
|
{
|
||||||
|
|
||||||
// Split out the dialect, driver, and connect string
|
// Split out the dialect, driver, and connect string
|
||||||
char[] split = { ';' };
|
char[] split = { ';' };
|
||||||
string[] parts = connect.Split(split, 3);
|
string[] parts = connect.Split(split, 3);
|
||||||
|
@ -70,28 +73,64 @@ namespace OpenSim.Data.NHibernate
|
||||||
configuration.SetProperty(Environment.ConnectionString, parts[2]);
|
configuration.SetProperty(Environment.ConnectionString, parts[2]);
|
||||||
configuration.AddAssembly("OpenSim.Data.NHibernate");
|
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();
|
sessionFactory = configuration.BuildSessionFactory();
|
||||||
|
}
|
||||||
|
|
||||||
Assembly assembly = GetType().Assembly;
|
/// <summary>
|
||||||
|
/// Runs migration for the the store in assembly
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="dialect">Dialect in use</param>
|
||||||
|
/// <param name="assembly">Assembly where migration files exist</param>
|
||||||
|
/// <param name="store">Name of the store in use</param>
|
||||||
|
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
|
// 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
|
// 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:
|
// this folder each time the mysql version changes creating simple mapping:
|
||||||
String migrationSubType = dialect;
|
String migrationSubType = dialect;
|
||||||
if (dialect.StartsWith("MySQL"))
|
if (dialect.StartsWith("MySQL"))
|
||||||
{
|
{
|
||||||
migrationSubType="MySQLDialect";
|
migrationSubType = "MySQLDialect";
|
||||||
}
|
}
|
||||||
|
|
||||||
Migration migration = new Migration((System.Data.Common.DbConnection)sessionFactory.ConnectionProvider.GetConnection(), assembly, migrationSubType, store);
|
Migration migration = new Migration((System.Data.Common.DbConnection)sessionFactory.ConnectionProvider.GetConnection(), assembly, migrationSubType, store);
|
||||||
migration.Update();
|
migration.Update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initiate NHibernate Manager
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="connect">NHibernate dialect, driver and connection string separated by ';'</param>
|
||||||
|
/// <param name="store">Name of the store</param>
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initiate NHibernate Manager with spesific assembly
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="connect">NHibernate dialect, driver and connection string separated by ';'</param>
|
||||||
|
/// <param name="store">Name of the store</param>
|
||||||
|
/// <param name="assembly"></param>
|
||||||
|
public NHibernateManager(string connect, string store, Assembly assembly)
|
||||||
|
{
|
||||||
|
parseConnectionString(connect);
|
||||||
|
|
||||||
|
configuration.AddAssembly(assembly);
|
||||||
|
|
||||||
|
runMigration(dialect, assembly, store);
|
||||||
|
}
|
||||||
|
|
||||||
public object Load(Type type, UUID uuid)
|
public object Load(Type type, UUID uuid)
|
||||||
{
|
{
|
||||||
using (IStatelessSession session = sessionFactory.OpenStatelessSession())
|
using (IStatelessSession session = sessionFactory.OpenStatelessSession())
|
||||||
|
|
Loading…
Reference in New Issue