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 ++++----- .../Communications/InventoryServiceBase.cs | 4 +-- OpenSim/Framework/IInventoryData.cs | 2 +- OpenSim/Framework/InventoryConfig.cs | 42 ++++++++++++---------- OpenSim/Grid/InventoryServer/InventoryManager.cs | 4 +-- OpenSim/Grid/InventoryServer/Main.cs | 2 +- OpenSim/Region/Application/OpenSimMain.cs | 2 +- 11 files changed, 69 insertions(+), 51 deletions(-) (limited to 'OpenSim') 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(); diff --git a/OpenSim/Framework/Communications/InventoryServiceBase.cs b/OpenSim/Framework/Communications/InventoryServiceBase.cs index 769c530..5cbfcf9 100644 --- a/OpenSim/Framework/Communications/InventoryServiceBase.cs +++ b/OpenSim/Framework/Communications/InventoryServiceBase.cs @@ -46,7 +46,7 @@ namespace OpenSim.Framework.Communications /// Adds a new user server plugin - plugins will be requested in the order they were loaded. /// /// The filename to the user server plugin DLL - public void AddPlugin(string FileName) + public void AddPlugin(string FileName, string connect) { if (!String.IsNullOrEmpty(FileName)) { @@ -63,7 +63,7 @@ namespace OpenSim.Framework.Communications { IInventoryData plug = (IInventoryData) Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString())); - plug.Initialise(); + plug.Initialise(connect); m_plugins.Add(plug.getName(), plug); m_log.Info("[AGENTINVENTORY]: Added IInventoryData Interface"); } diff --git a/OpenSim/Framework/IInventoryData.cs b/OpenSim/Framework/IInventoryData.cs index d72231d..508099e 100644 --- a/OpenSim/Framework/IInventoryData.cs +++ b/OpenSim/Framework/IInventoryData.cs @@ -38,7 +38,7 @@ namespace OpenSim.Framework /// /// Initialises the interface /// - void Initialise(); + void Initialise(string connect); /// /// Closes the interface diff --git a/OpenSim/Framework/InventoryConfig.cs b/OpenSim/Framework/InventoryConfig.cs index 39a6930..1e22fe8 100644 --- a/OpenSim/Framework/InventoryConfig.cs +++ b/OpenSim/Framework/InventoryConfig.cs @@ -40,6 +40,7 @@ namespace OpenSim.Framework public string UserRecvKey = String.Empty; public string DatabaseProvider = String.Empty; + public string DatabaseConnect = String.Empty; public static uint DefaultHttpPort = 8004; public uint HttpPort = DefaultHttpPort; @@ -68,6 +69,8 @@ namespace OpenSim.Framework "Key to expect from user server", "null", false); configMember.addConfigurationOption("database_provider", ConfigurationOption.ConfigurationTypes.TYPE_STRING, "DLL for database provider", "OpenSim.Data.SQLite.dll", false); + configMember.addConfigurationOption("database_connect", ConfigurationOption.ConfigurationTypes.TYPE_STRING, + "Database Connect String", "", false); configMember.addConfigurationOption("http_port", ConfigurationOption.ConfigurationTypes.TYPE_UINT32, "Http Listener port", DefaultHttpPort.ToString(), false); } @@ -76,24 +79,27 @@ namespace OpenSim.Framework { switch (configuration_key) { - case "default_startup_message": - DefaultStartupMsg = (string) configuration_result; - break; - case "default_user_server": - UserServerURL = (string) configuration_result; - break; - case "user_send_key": - UserSendKey = (string) configuration_result; - break; - case "user_recv_key": - UserRecvKey = (string) configuration_result; - break; - case "database_provider": - DatabaseProvider = (string) configuration_result; - break; - case "http_port": - HttpPort = (uint) configuration_result; - break; + case "default_startup_message": + DefaultStartupMsg = (string) configuration_result; + break; + case "default_user_server": + UserServerURL = (string) configuration_result; + break; + case "user_send_key": + UserSendKey = (string) configuration_result; + break; + case "user_recv_key": + UserRecvKey = (string) configuration_result; + break; + case "database_provider": + DatabaseProvider = (string) configuration_result; + break; + case "database_connect": + DatabaseConnect = (string) configuration_result; + break; + case "http_port": + HttpPort = (uint) configuration_result; + break; } return true; diff --git a/OpenSim/Grid/InventoryServer/InventoryManager.cs b/OpenSim/Grid/InventoryServer/InventoryManager.cs index b3c6891..1d4a4e3 100644 --- a/OpenSim/Grid/InventoryServer/InventoryManager.cs +++ b/OpenSim/Grid/InventoryServer/InventoryManager.cs @@ -48,7 +48,7 @@ namespace OpenSim.Grid.InventoryServer /// Adds a new inventory server plugin - user servers will be requested in the order they were loaded. /// /// The filename to the inventory server plugin DLL - public void AddDatabasePlugin(string FileName) + public void AddDatabasePlugin(string FileName, string dbconnect) { m_log.Info("[" + OpenInventory_Main.LogName + "]: Invenstorage: Attempting to load " + FileName); Assembly pluginAssembly = Assembly.LoadFrom(FileName); @@ -65,7 +65,7 @@ namespace OpenSim.Grid.InventoryServer { IInventoryData plug = (IInventoryData) Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString())); - plug.Initialise(); + plug.Initialise(dbconnect); _databasePlugin = plug; m_log.Info("[" + OpenInventory_Main.LogName + "]: " + "Invenstorage: Added IInventoryData Interface"); diff --git a/OpenSim/Grid/InventoryServer/Main.cs b/OpenSim/Grid/InventoryServer/Main.cs index 2454650..85d9ba5 100644 --- a/OpenSim/Grid/InventoryServer/Main.cs +++ b/OpenSim/Grid/InventoryServer/Main.cs @@ -72,7 +72,7 @@ namespace OpenSim.Grid.InventoryServer m_inventoryService = new GridInventoryService(); // m_inventoryManager = new InventoryManager(); - m_inventoryService.AddPlugin(m_config.DatabaseProvider); + m_inventoryService.AddPlugin(m_config.DatabaseProvider, m_config.DatabaseConnect); m_log.Info("[" + LogName + "]: Starting HTTP server ..."); diff --git a/OpenSim/Region/Application/OpenSimMain.cs b/OpenSim/Region/Application/OpenSimMain.cs index c01fc5a..aaf2d7e 100644 --- a/OpenSim/Region/Application/OpenSimMain.cs +++ b/OpenSim/Region/Application/OpenSimMain.cs @@ -353,7 +353,7 @@ namespace OpenSim if (m_sandbox) { LocalInventoryService inventoryService = new LocalInventoryService(); - inventoryService.AddPlugin(m_standaloneInventoryPlugin); + inventoryService.AddPlugin(m_standaloneInventoryPlugin, m_standaloneInventorySource); LocalUserServices userService = new LocalUserServices(m_networkServersInfo, m_networkServersInfo.DefaultHomeLocX, -- cgit v1.1