From 3dd98a112f4308532d768943690b13c403dff68b Mon Sep 17 00:00:00 2001 From: Sean Dague Date: Wed, 23 Apr 2008 20:48:23 +0000 Subject: allow for Inventory database source to be specified in main configs. This works with sqlite and nhibernate backends, and stays with default seperate ini files for mysql and mssql until someone writes those. --- OpenSim/Data/MSSQL/MSSQLInventoryData.cs | 6 +++++ OpenSim/Data/MySQL/MySQLInventoryData.cs | 6 +++++ OpenSim/Data/NHibernate/NHibernateAssetData.cs | 10 ++++++--- OpenSim/Data/NHibernate/NHibernateInventoryData.cs | 26 +++++++++++----------- OpenSim/Data/SQLite/SQLiteInventoryStore.cs | 16 +++++-------- 5 files changed, 38 insertions(+), 26 deletions(-) (limited to 'OpenSim/Data') diff --git a/OpenSim/Data/MSSQL/MSSQLInventoryData.cs b/OpenSim/Data/MSSQL/MSSQLInventoryData.cs index 27f8b60..c524fc0 100644 --- a/OpenSim/Data/MSSQL/MSSQLInventoryData.cs +++ b/OpenSim/Data/MSSQL/MSSQLInventoryData.cs @@ -51,6 +51,12 @@ namespace OpenSim.Data.MSSQL /// /// Loads and initialises this database plugin /// + public void Initialise(string connect) + { + // TODO: actually use the provided connect string + Initialise(); + } + public void Initialise() { IniFile GridDataMySqlFile = new IniFile("mssql_connection.ini"); diff --git a/OpenSim/Data/MySQL/MySQLInventoryData.cs b/OpenSim/Data/MySQL/MySQLInventoryData.cs index dbcb9bd..6261d37 100644 --- a/OpenSim/Data/MySQL/MySQLInventoryData.cs +++ b/OpenSim/Data/MySQL/MySQLInventoryData.cs @@ -51,6 +51,12 @@ namespace OpenSim.Data.MySQL /// /// Loads and initialises this database plugin /// + public void Initialise(string connect) + { + // TODO: actually use the provided connect string + Initialise(); + } + public void Initialise() { IniFile GridDataMySqlFile = new IniFile("mysql_connection.ini"); diff --git a/OpenSim/Data/NHibernate/NHibernateAssetData.cs b/OpenSim/Data/NHibernate/NHibernateAssetData.cs index 7bd4a0b..beac693 100644 --- a/OpenSim/Data/NHibernate/NHibernateAssetData.cs +++ b/OpenSim/Data/NHibernate/NHibernateAssetData.cs @@ -55,11 +55,11 @@ namespace OpenSim.Data.NHibernate public override void Initialise(string connect) { - // TODO: hard coding for sqlite based stuff to begin with, just making it easier to test + // Split out the dialect, driver, and connect string char[] split = {';'}; string[] parts = connect.Split(split); - // This is stubbing for now, it will become dynamic later and support different db backends + // NHibernate setup cfg = new Configuration(); cfg.SetProperty(Environment.ConnectionProvider, "NHibernate.Connection.DriverConnectionProvider"); @@ -74,7 +74,11 @@ namespace OpenSim.Data.NHibernate using ( MemoryStream stream = HbmSerializer.Default.Serialize(Assembly.GetExecutingAssembly())) cfg.AddInputStream(stream); - + + // If uncommented this will auto create tables, but it + // does drops of the old tables, so we need a smarter way + // to acturally manage this. + // new SchemaExport(cfg).Create(true, true); factory = cfg.BuildSessionFactory(); diff --git a/OpenSim/Data/NHibernate/NHibernateInventoryData.cs b/OpenSim/Data/NHibernate/NHibernateInventoryData.cs index 1ac0f0c..938f47c 100644 --- a/OpenSim/Data/NHibernate/NHibernateInventoryData.cs +++ b/OpenSim/Data/NHibernate/NHibernateInventoryData.cs @@ -50,25 +50,21 @@ namespace OpenSim.Data.NHibernate /// /// Initialises the interface /// - public void Initialise() + public void Initialise(string connect) { - Initialise("Inventory.db", "Inventory"); - } - - public void Initialise(string dbfile, string dbname) - { - // TODO: hard coding for sqlite based stuff to begin with, just making it easier to test - - // This is stubbing for now, it will become dynamic later and support different db backends + // Split out the dialect, driver, and connect string + char[] split = {';'}; + string[] parts = connect.Split(split); + + // Establish NHibernate Connection cfg = new Configuration(); cfg.SetProperty(Environment.ConnectionProvider, "NHibernate.Connection.DriverConnectionProvider"); cfg.SetProperty(Environment.Dialect, - "NHibernate.Dialect.SQLiteDialect"); + "NHibernate.Dialect." + parts[0]); cfg.SetProperty(Environment.ConnectionDriver, - "NHibernate.Driver.SqliteClientDriver"); - cfg.SetProperty(Environment.ConnectionString, - "URI=file:" + dbfile + ",version=3"); + "NHibernate.Driver." + parts[1]); + cfg.SetProperty(Environment.ConnectionString, parts[2]); cfg.AddAssembly("OpenSim.Data.NHibernate"); HbmSerializer.Default.Validate = true; @@ -76,6 +72,10 @@ namespace OpenSim.Data.NHibernate HbmSerializer.Default.Serialize(Assembly.GetExecutingAssembly())) cfg.AddInputStream(stream); + // If uncommented this will auto create tables, but it + // does drops of the old tables, so we need a smarter way + // to acturally manage this. + // new SchemaExport(cfg).Create(true, true); factory = cfg.BuildSessionFactory(); diff --git a/OpenSim/Data/SQLite/SQLiteInventoryStore.cs b/OpenSim/Data/SQLite/SQLiteInventoryStore.cs index 442ba39..2eb0ad5 100644 --- a/OpenSim/Data/SQLite/SQLiteInventoryStore.cs +++ b/OpenSim/Data/SQLite/SQLiteInventoryStore.cs @@ -50,17 +50,13 @@ namespace OpenSim.Data.SQLite /// /// Initialises the interface /// - public void Initialise() + public void Initialise(string dbconnect) { - Initialise("inventoryStore.db", "inventoryDatabase"); - } - - public void Initialise(string dbfile, string dbname) - { - string connectionString = "URI=file:" + dbfile + ",version=3"; - - m_log.Info("[Inventory]: Sqlite - connecting: " + dbfile); - SqliteConnection conn = new SqliteConnection(connectionString); + if (dbconnect == string.Empty) { + dbconnect = "URI=file:inventoryStore.db,version=3"; + } + m_log.Info("[Inventory]: Sqlite - connecting: " + dbconnect); + SqliteConnection conn = new SqliteConnection(dbconnect); conn.Open(); -- cgit v1.1