From f52886f8f55ba6fd520cc3fffefd9a5607ad2a33 Mon Sep 17 00:00:00 2001 From: lbsa71 Date: Sun, 30 Mar 2008 21:04:45 +0000 Subject: * Added competely untested MSSQLMapper * Added the new mapper to the mapper factory * Made choice of mapper configurable * This means, in hteory, that we can persist avatar appearance on MSSQL as well --- .../Data.MSSQLMapper/MSSQLDatabaseMapper.cs | 52 ++++++++++++++++++++++ .../Data.MapperFactory/DataMapperFactory.cs | 13 +++--- .../Modules/AvatarFactory/AvatarFactoryModule.cs | 12 ++++- 3 files changed, 69 insertions(+), 8 deletions(-) create mode 100644 OpenSim/Framework/Data.MSSQLMapper/MSSQLDatabaseMapper.cs (limited to 'OpenSim') diff --git a/OpenSim/Framework/Data.MSSQLMapper/MSSQLDatabaseMapper.cs b/OpenSim/Framework/Data.MSSQLMapper/MSSQLDatabaseMapper.cs new file mode 100644 index 0000000..725322d --- /dev/null +++ b/OpenSim/Framework/Data.MSSQLMapper/MSSQLDatabaseMapper.cs @@ -0,0 +1,52 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSim Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using System.Data.Common; +using System.Data.SqlClient; +using OpenSim.Framework.Data; + +namespace OpenSim.Framework.Data.MSSQLMapper +{ + public class MSSQLDatabaseMapper : OpenSimDatabaseConnector + { + public MSSQLDatabaseMapper(string connectionString) + : base(connectionString) + { + } + + public override DbConnection GetNewConnection() + { + SqlConnection connection = new SqlConnection(m_connectionString); + return connection; + } + + public override string CreateParamName(string fieldName) + { + return "@" + fieldName; + } + } +} \ No newline at end of file diff --git a/OpenSim/Framework/Data.MapperFactory/DataMapperFactory.cs b/OpenSim/Framework/Data.MapperFactory/DataMapperFactory.cs index 37b933c..8995b9e 100644 --- a/OpenSim/Framework/Data.MapperFactory/DataMapperFactory.cs +++ b/OpenSim/Framework/Data.MapperFactory/DataMapperFactory.cs @@ -1,8 +1,6 @@ using System; -using System.Collections.Generic; -using OpenSim.Framework; -using OpenSim.Framework.Data; using OpenSim.Framework.Data.Base; +using OpenSim.Framework.Data.MSSQLMapper; using OpenSim.Framework.Data.MySQLMapper; namespace OpenSim.Framework.Data.MapperFactory @@ -10,16 +8,19 @@ namespace OpenSim.Framework.Data.MapperFactory public class DataMapperFactory { public enum MAPPER_TYPE { - MYSQL, + MySQL, + MSSQL, }; static public BaseDatabaseConnector GetDataBaseMapper(MAPPER_TYPE type, string connectionString) { switch (type) { - case MAPPER_TYPE.MYSQL: + case MAPPER_TYPE.MySQL: return new MySQLDatabaseMapper(connectionString); + case MAPPER_TYPE.MSSQL: + return new MSSQLDatabaseMapper(connectionString); default: - return null; + throw new ArgumentException("Unknown Database Mapper type [" + type + "]."); } } } diff --git a/OpenSim/Region/Modules/AvatarFactory/AvatarFactoryModule.cs b/OpenSim/Region/Modules/AvatarFactory/AvatarFactoryModule.cs index b1a138b..751e92e 100644 --- a/OpenSim/Region/Modules/AvatarFactory/AvatarFactoryModule.cs +++ b/OpenSim/Region/Modules/AvatarFactory/AvatarFactoryModule.cs @@ -220,14 +220,22 @@ namespace OpenSim.Region.Modules.AvatarFactory try { m_enablePersist = source.Configs["Startup"].GetBoolean("appearance_persist", false); - m_connectionString = source.Configs["Startup"].GetString("appearance_connection_string", ""); } catch (Exception) { } if (m_enablePersist) { - m_databaseMapper = DataMapperFactory.GetDataBaseMapper(DataMapperFactory.MAPPER_TYPE.MYSQL, m_connectionString); + m_connectionString = source.Configs["Startup"].GetString("appearance_connection_string", ""); + + string mapperTypeStr = source.Configs["Startup"].GetString("appearance_database", "MYSQL"); + + DataMapperFactory.MAPPER_TYPE mapperType = + (DataMapperFactory.MAPPER_TYPE) + Enum.Parse(typeof (DataMapperFactory.MAPPER_TYPE), mapperTypeStr); + + m_databaseMapper = DataMapperFactory.GetDataBaseMapper(mapperType, m_connectionString); + m_appearanceMapper = new AppearanceTableMapper(m_databaseMapper, "AvatarAppearance"); } } -- cgit v1.1