The DataPluginFactory is now a set of generic methods instead of
multiple duplicates of the same code.0.6.3-post-fixes
parent
d85fce99f4
commit
369eef5fcd
|
@ -25,21 +25,80 @@
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using OpenSim.Framework;
|
using OpenSim.Framework;
|
||||||
|
|
||||||
namespace OpenSim.Data
|
namespace OpenSim.Data
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A static class containing a series of methods for obtaining handles to
|
/// A static class containing methods for obtaining handles to database
|
||||||
/// database storage objects.
|
/// storage objects.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
// Yeah, it's not really a factory, but maybe it'll morph into one?
|
|
||||||
public static class DataPluginFactory
|
public static class DataPluginFactory
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns a list of new inventory data plugins. Plugins will be
|
/// Based on <typeparam name="T" />, returns the appropriate
|
||||||
/// requested in the order they were added.
|
/// PluginInitialiserBase instance in <paramref name="init" /> and
|
||||||
|
/// extension point path in <paramref name="path" />.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="connect">
|
||||||
|
/// The DB connection string used when creating a new
|
||||||
|
/// PluginInitialiserBase, returned in <paramref name="init" />.
|
||||||
|
/// </param>
|
||||||
|
/// <param name="init">
|
||||||
|
/// A reference to a PluginInitialiserBase object in which the proper
|
||||||
|
/// initialiser will be returned.
|
||||||
|
/// </param>
|
||||||
|
/// <param name="path">
|
||||||
|
/// A string in which the proper extension point path will be returned.
|
||||||
|
/// </param>
|
||||||
|
/// <typeparam name="T">
|
||||||
|
/// The type of data plugin requested.
|
||||||
|
/// </typeparam>
|
||||||
|
/// <exception cref="NotImplementedException">
|
||||||
|
/// Thrown if <typeparamref name="T" /> is not one of the expected data
|
||||||
|
/// interfaces.
|
||||||
|
/// </exception>
|
||||||
|
private static void PluginLoaderParamFactory<T>(string connect, out PluginInitialiserBase init, out string path) where T : IPlugin
|
||||||
|
{
|
||||||
|
Type type = typeof(T);
|
||||||
|
|
||||||
|
if (type == typeof(IInventoryDataPlugin))
|
||||||
|
{
|
||||||
|
init = new InventoryDataInitialiser(connect);
|
||||||
|
path = "/OpenSim/InventoryData";
|
||||||
|
}
|
||||||
|
else if (type == typeof(IUserDataPlugin))
|
||||||
|
{
|
||||||
|
init = new UserDataInitialiser(connect);
|
||||||
|
path = "/OpenSim/UserData";
|
||||||
|
}
|
||||||
|
else if (type == typeof(IGridDataPlugin))
|
||||||
|
{
|
||||||
|
init = new GridDataInitialiser(connect);
|
||||||
|
path = "/OpenSim/GridData";
|
||||||
|
}
|
||||||
|
else if (type == typeof(ILogDataPlugin))
|
||||||
|
{
|
||||||
|
init = new LogDataInitialiser(connect);
|
||||||
|
path = "/OpenSim/LogData";
|
||||||
|
}
|
||||||
|
else if (type == typeof(IAssetDataPlugin))
|
||||||
|
{
|
||||||
|
init = new AssetDataInitialiser(connect);
|
||||||
|
path = "/OpenSim/AssetData";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// We don't support this data plugin.
|
||||||
|
throw new NotImplementedException(String.Format("The type '{0}' is not a valid data plugin.", type));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns a list of new <typeparamref name="T" /> data plugins.
|
||||||
|
/// Plugins will be requested in the order they were added.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="provider">
|
/// <param name="provider">
|
||||||
/// The filename of the inventory server plugin DLL.
|
/// The filename of the inventory server plugin DLL.
|
||||||
|
@ -47,95 +106,49 @@ namespace OpenSim.Data
|
||||||
/// <param name="connect">
|
/// <param name="connect">
|
||||||
/// The connection string for the storage backend.
|
/// The connection string for the storage backend.
|
||||||
/// </param>
|
/// </param>
|
||||||
public static List<IInventoryDataPlugin> LoadInventoryDataPlugins(string provider, string connect)
|
/// <typeparam name="T">
|
||||||
|
/// The type of data plugin requested.
|
||||||
|
/// </typeparam>
|
||||||
|
/// <returns>
|
||||||
|
/// A list of all loaded plugins matching <typeparamref name="T" />.
|
||||||
|
/// </returns>
|
||||||
|
public static List<T> LoadDataPlugins<T>(string provider, string connect) where T : IPlugin
|
||||||
{
|
{
|
||||||
PluginLoader<IInventoryDataPlugin> loader = new PluginLoader<IInventoryDataPlugin> (new InventoryDataInitialiser(connect));
|
PluginInitialiserBase pluginInitialiser;
|
||||||
|
string extensionPointPath;
|
||||||
|
|
||||||
|
PluginLoaderParamFactory<T>(connect, out pluginInitialiser, out extensionPointPath);
|
||||||
|
|
||||||
|
PluginLoader<T> loader = new PluginLoader<T>(pluginInitialiser);
|
||||||
|
|
||||||
// loader will try to load all providers (MySQL, MSSQL, etc)
|
// loader will try to load all providers (MySQL, MSSQL, etc)
|
||||||
// unless it is constrainted to the correct "Provider" entry in the addin.xml
|
// unless it is constrainted to the correct "Provider" entry in the addin.xml
|
||||||
loader.Add ("/OpenSim/InventoryData", new PluginProviderFilter(provider));
|
loader.Add(extensionPointPath, new PluginProviderFilter(provider));
|
||||||
loader.Load();
|
loader.Load();
|
||||||
|
|
||||||
return loader.Plugins;
|
return loader.Plugins;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns a list of new user data plugins. Plugins will be requested
|
/// Returns a new <typeparamref name="T" /> data plugin instance if
|
||||||
/// in the order they were added.
|
/// only one was loaded, otherwise returns null (<c>default(T)</c>).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="provider">
|
/// <param name="provider">
|
||||||
/// The filename of the user data plugin DLL.
|
/// The filename of the inventory server plugin DLL.
|
||||||
/// </param>
|
/// </param>
|
||||||
/// <param name="connect">
|
/// <param name="connect">
|
||||||
/// The connection string for the storage backend.
|
/// The connection string for the storage backend.
|
||||||
/// </param>
|
/// </param>
|
||||||
public static List<IUserDataPlugin> LoadUserDataPlugins(string provider, string connect)
|
/// <typeparam name="T">
|
||||||
|
/// The type of data plugin requested.
|
||||||
|
/// </typeparam>
|
||||||
|
/// <returns>
|
||||||
|
/// A list of all loaded plugins matching <typeparamref name="T" />.
|
||||||
|
/// </returns>
|
||||||
|
public static T LoadDataPlugin<T>(string provider, string connect) where T : IPlugin
|
||||||
{
|
{
|
||||||
PluginLoader<IUserDataPlugin> loader = new PluginLoader<IUserDataPlugin>(new UserDataInitialiser(connect));
|
List<T> plugins = LoadDataPlugins<T>(provider, connect);
|
||||||
|
return (plugins.Count == 1) ? plugins[0] : default(T);
|
||||||
// loader will try to load all providers (MySQL, MSSQL, etc)
|
|
||||||
// unless it is constrainted to the correct "Provider" entry in the addin.xml
|
|
||||||
loader.Add("/OpenSim/UserData", new PluginProviderFilter(provider));
|
|
||||||
loader.Load();
|
|
||||||
|
|
||||||
return loader.Plugins;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Returns a list of new grid data plugins. Plugins will be requested
|
|
||||||
/// in the order they were added.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="provider">
|
|
||||||
/// The filename of the user data plugin DLL.
|
|
||||||
/// </param>
|
|
||||||
/// <param name="connect">
|
|
||||||
/// The connection string for the storage backend.
|
|
||||||
/// </param>
|
|
||||||
public static List<IGridDataPlugin> LoadGridDataPlugins(string provider, string connect)
|
|
||||||
{
|
|
||||||
PluginLoader<IGridDataPlugin> loader = new PluginLoader<IGridDataPlugin>(new GridDataInitialiser(connect));
|
|
||||||
|
|
||||||
// loader will try to load all providers (MySQL, MSSQL, etc)
|
|
||||||
// unless it is constrainted to the correct "Provider" entry in the addin.xml
|
|
||||||
loader.Add("/OpenSim/GridData", new PluginProviderFilter(provider));
|
|
||||||
loader.Load();
|
|
||||||
|
|
||||||
return loader.Plugins;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Returns a list of new log data plugins. Plugins will be requested
|
|
||||||
/// in the order they were added.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="provider">
|
|
||||||
/// The filename of the user data plugin DLL.
|
|
||||||
/// </param>
|
|
||||||
/// <param name="connect">
|
|
||||||
/// The connection string for the storage backend.
|
|
||||||
/// </param>
|
|
||||||
public static List<ILogDataPlugin> LoadLogDataPlugins(string provider, string connect)
|
|
||||||
{
|
|
||||||
PluginLoader<ILogDataPlugin> loader = new PluginLoader<ILogDataPlugin>(new LogDataInitialiser(connect));
|
|
||||||
|
|
||||||
// loader will try to load all providers (MySQL, MSSQL, etc)
|
|
||||||
// unless it is constrainted to the correct "Provider" entry in the addin.xml
|
|
||||||
loader.Add("/OpenSim/LogData", new PluginProviderFilter(provider));
|
|
||||||
loader.Load();
|
|
||||||
|
|
||||||
return loader.Plugins;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IAssetDataPlugin LoadAssetDataPlugin(string provider, string connect)
|
|
||||||
{
|
|
||||||
PluginLoader<IAssetDataPlugin> loader = new PluginLoader<IAssetDataPlugin> (new AssetDataInitialiser (connect));
|
|
||||||
|
|
||||||
// loader will try to load all providers (MySQL, MSSQL, etc)
|
|
||||||
// unless it is constrainted to the correct "Provider" entry in the addin.xml
|
|
||||||
loader.Add ("/OpenSim/AssetData", new PluginProviderFilter (provider));
|
|
||||||
loader.Load();
|
|
||||||
|
|
||||||
return loader.Plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,7 +70,7 @@ namespace OpenSim.Framework.Communications
|
||||||
/// </param>
|
/// </param>
|
||||||
public void AddPlugin(string provider, string connect)
|
public void AddPlugin(string provider, string connect)
|
||||||
{
|
{
|
||||||
m_plugins.AddRange(DataPluginFactory.LoadInventoryDataPlugins(provider, connect));
|
m_plugins.AddRange(DataPluginFactory.LoadDataPlugins<IInventoryDataPlugin>(provider, connect));
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
|
@ -85,7 +85,7 @@ namespace OpenSim.Framework.Communications
|
||||||
/// </param>
|
/// </param>
|
||||||
public void AddPlugin(string provider, string connect)
|
public void AddPlugin(string provider, string connect)
|
||||||
{
|
{
|
||||||
_plugins.AddRange(DataPluginFactory.LoadUserDataPlugins(provider, connect));
|
_plugins.AddRange(DataPluginFactory.LoadDataPlugins<IUserDataPlugin>(provider, connect));
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Get UserProfile
|
#region Get UserProfile
|
||||||
|
|
|
@ -118,7 +118,7 @@ namespace OpenSim.Grid.AssetServer
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
m_assetProvider = DataPluginFactory.LoadAssetDataPlugin(config.DatabaseProvider, config.DatabaseConnect);
|
m_assetProvider = DataPluginFactory.LoadDataPlugin<IAssetDataPlugin>(config.DatabaseProvider, config.DatabaseConnect);
|
||||||
if (m_assetProvider == null)
|
if (m_assetProvider == null)
|
||||||
{
|
{
|
||||||
m_log.Error("[ASSET]: Failed to load a database plugin, server halting");
|
m_log.Error("[ASSET]: Failed to load a database plugin, server halting");
|
||||||
|
|
|
@ -83,8 +83,8 @@ namespace OpenSim.Grid.GridServer
|
||||||
/// </param>
|
/// </param>
|
||||||
public void AddPlugin(string provider, string connect)
|
public void AddPlugin(string provider, string connect)
|
||||||
{
|
{
|
||||||
_plugins = DataPluginFactory.LoadGridDataPlugins(provider, connect);
|
_plugins = DataPluginFactory.LoadDataPlugins<IGridDataPlugin>(provider, connect);
|
||||||
_logplugins = DataPluginFactory.LoadLogDataPlugins(provider, connect);
|
_logplugins = DataPluginFactory.LoadDataPlugins<ILogDataPlugin>(provider, connect);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
Loading…
Reference in New Issue