Browse Source

* 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

lbsa71 16 years ago
parent
commit
f52886f8f5

+ 52 - 0
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;
+        }
+    }
+}

+ 7 - 6
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 + "].");
             }            
         }
     }

+ 10 - 2
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");
                 }
             }

+ 1 - 0
bin/OpenSim.ini.example

@@ -30,6 +30,7 @@ storage_prim_inventories = true
 
 ; Avatar appearance persistence
 appearance_persist = false
+appearance_database = "MySQL"
 appearance_connection_string = "Data Source=localhost;Database=avatar_appearance;User ID=root;Password=xxxx;pooling=false;"
 
 ; Select whether you want to use local or grid asset storage.

+ 29 - 0
prebuild.xml

@@ -234,6 +234,34 @@
       </Files>
     </Project>
 
+    <Project name="OpenSim.Framework.Data.MSSQLMapper" path="OpenSim/Framework/Data.MSSQLMapper" type="Library">
+      <Configuration name="Debug">
+        <Options>
+          <OutputPath>../../../bin/</OutputPath>
+        </Options>
+      </Configuration>
+      <Configuration name="Release">
+        <Options>
+          <OutputPath>../../../bin/</OutputPath>
+        </Options>
+      </Configuration>
+
+      <ReferencePath>../../../bin/</ReferencePath>
+      <Reference name="System" localCopy="false"/>
+      <Reference name="System.Xml"/>
+      <Reference name="System.Data"/>
+      <Reference name="OpenSim.Framework"/>
+      <Reference name="OpenSim.Framework.Data"/>
+      <Reference name="OpenSim.Framework.Data.Base"/>
+      <Reference name="libsecondlife.dll"/>
+      <Reference name="OpenSim.Framework.Console"/>
+      <Reference name="log4net"/>
+
+      <Files>
+        <Match pattern="*.cs" recurse="true"/>
+      </Files>
+    </Project>
+
     <Project name="OpenSim.Framework.Data.MapperFactory" path="OpenSim/Framework/Data.MapperFactory" type="Library">
       <Configuration name="Debug">
         <Options>
@@ -254,6 +282,7 @@
       <Reference name="OpenSim.Framework.Data"/>
       <Reference name="OpenSim.Framework.Data.Base"/>
       <Reference name="OpenSim.Framework.Data.MySQLMapper"/>
+      <Reference name="OpenSim.Framework.Data.MSSQLMapper"/>
 
       <Files>
         <Match pattern="*.cs" recurse="true"/>