* Removed the unused Data.Base Framework

0.6.3-post-fixes
lbsa71 2009-02-02 11:16:41 +00:00
parent 496ed4488d
commit d91bc08737
18 changed files with 0 additions and 1990 deletions

View File

@ -1,205 +0,0 @@
/*
* 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;
using System.Data;
using System.IO;
namespace OpenSim.Data.Base
{
/// <summary>
///
/// </summary>
public abstract class BaseDataReader
{
private readonly IDataReader m_source;
/// <summary>
///
/// </summary>
/// <param name="source"></param>
public BaseDataReader(IDataReader source)
{
m_source = source;
}
/// <summary>
///
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public object Get(string name)
{
return m_source[name];
}
/// <summary>
///
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public ushort GetUShort(string name)
{
return (ushort)m_source.GetInt32(m_source.GetOrdinal(name));
}
/// <summary>
///
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public byte GetByte(string name)
{
int ordinal = m_source.GetOrdinal(name);
byte value = (byte)m_source.GetInt16(ordinal);
return value;
}
/// <summary>
///
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public sbyte GetSByte(string name)
{
return (sbyte)m_source.GetInt16(m_source.GetOrdinal(name));
}
/// <summary>
///
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public float GetFloat(string name)
{
return m_source.GetFloat(m_source.GetOrdinal(name));
}
/// <summary>
///
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public byte[] GetBytes(string name)
{
int ordinal = m_source.GetOrdinal(name);
if (m_source.GetValue(ordinal) == DBNull.Value)
{
return null;
}
byte[] buffer = new byte[16384];
MemoryStream memStream = new MemoryStream();
long totalRead = 0;
int bytesRead;
do
{
bytesRead = (int)m_source.GetBytes(ordinal, totalRead, buffer, 0, buffer.Length);
totalRead += bytesRead;
memStream.Write(buffer, 0, bytesRead);
} while (bytesRead == buffer.Length);
return memStream.ToArray();
}
/// <summary>
///
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public string GetString(string name)
{
int ordinal = m_source.GetOrdinal(name);
object value = m_source.GetValue(ordinal);
if (value is DBNull)
{
return null;
}
return (string)value;
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public bool Read()
{
return m_source.Read();
}
/// <summary>
///
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public virtual Guid GetGuid(string name)
{
return m_source.GetGuid(m_source.GetOrdinal(name));
}
/// <summary>
///
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public UInt32 GetUInt32(string name)
{
return (UInt32)GetInt32(name);
}
/// <summary>
///
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
private Int32 GetInt32(string name)
{
int ordinal = m_source.GetOrdinal(name);
int int32 = m_source.GetInt32(ordinal);
return int32;
}
/// <summary>
///
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public Int64 GetInt64(string name)
{
int ordinal = m_source.GetOrdinal(name);
long int64 = m_source.GetInt64(ordinal);
return int64;
}
}
}

View File

@ -1,185 +0,0 @@
/*
* 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;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
namespace OpenSim.Data.Base
{
/// <summary>
///
/// </summary>
public abstract class BaseDatabaseConnector
{
protected string m_connectionString;
/// <summary>
///
/// </summary>
/// <param name="connectionString"></param>
public BaseDatabaseConnector(string connectionString)
{
m_connectionString = connectionString;
}
public abstract DbConnection GetNewConnection();
public abstract string CreateParamName(string fieldName);
/// <summary>
///
/// </summary>
/// <param name="mapper"></param>
/// <param name="connection"></param>
/// <param name="fieldName"></param>
/// <param name="key"></param>
/// <returns></returns>
public DbCommand CreateSelectCommand(BaseTableMapper mapper, DbConnection connection, string fieldName, object key)
{
string table = mapper.TableName;
DbCommand command = connection.CreateCommand();
string conditionString = CreateCondition(mapper, command, fieldName, key);
string query =
String.Format("select * from {0} where {1}", table, conditionString);
command.CommandText = query;
command.CommandType = CommandType.Text;
return command;
}
/// <summary>
///
/// </summary>
/// <param name="mapper"></param>
/// <param name="command"></param>
/// <param name="fieldName"></param>
/// <param name="key"></param>
/// <returns></returns>
public string CreateCondition(BaseTableMapper mapper, DbCommand command, string fieldName, object key)
{
string keyFieldParamName = mapper.CreateParamName(fieldName);
DbParameter param = command.CreateParameter();
param.ParameterName = keyFieldParamName;
param.Value = ConvertToDbType(key);
command.Parameters.Add(param);
return String.Format("{0}={1}", fieldName, keyFieldParamName);
}
/// <summary>
///
/// </summary>
/// <param name="mapper"></param>
/// <param name="connection"></param>
/// <param name="rowMapper"></param>
/// <param name="primaryKey"></param>
/// <returns></returns>
public DbCommand CreateUpdateCommand(BaseTableMapper mapper, DbConnection connection, object rowMapper, object primaryKey)
{
string table = mapper.TableName;
List<string> fieldNames = new List<string>();
DbCommand command = connection.CreateCommand();
foreach (BaseFieldMapper fieldMapper in mapper.Schema.Fields.Values)
{
if (fieldMapper != mapper.KeyFieldMapper)
{
fieldMapper.ExpandField(rowMapper, command, fieldNames);
}
}
List<string> assignments = new List<string>();
foreach (string field in fieldNames)
{
assignments.Add(String.Format("{0}={1}", field, mapper.CreateParamName(field)));
}
string conditionString = mapper.CreateCondition(command, mapper.KeyFieldMapper.FieldName, primaryKey);
command.CommandText =
String.Format("update {0} set {1} where {2}", table, String.Join(", ", assignments.ToArray()),
conditionString);
return command;
}
/// <summary>
///
/// </summary>
/// <param name="mapper"></param>
/// <param name="connection"></param>
/// <param name="obj"></param>
/// <returns></returns>
public DbCommand CreateInsertCommand(BaseTableMapper mapper, DbConnection connection, object obj)
{
string table = mapper.TableName;
List<string> fieldNames = new List<string>();
DbCommand command = connection.CreateCommand();
foreach (BaseFieldMapper fieldMapper in mapper.Schema.Fields.Values)
{
fieldMapper.ExpandField(obj, command, fieldNames);
}
List<string> paramNames = new List<string>();
foreach (string field in fieldNames)
{
paramNames.Add(mapper.CreateParamName(field));
}
command.CommandText =
String.Format("insert into {0} ({1}) values ({2})", table, String.Join(", ", fieldNames.ToArray()),
String.Join(", ", paramNames.ToArray()));
return command;
}
/// <summary>
///
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public virtual object ConvertToDbType(object value)
{
return value;
}
public abstract BaseDataReader CreateReader(IDataReader reader);
}
}

View File

@ -1,214 +0,0 @@
/*
* 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;
using System.Collections.Generic;
using System.Data.Common;
namespace OpenSim.Data.Base
{
public delegate TField ObjectGetAccessor<TObj, TField>(TObj obj);
public delegate void ObjectSetAccessor<TObj, TField>(TObj obj, TField value);
/// <summary>
///
/// </summary>
public abstract class BaseFieldMapper
{
private readonly BaseTableMapper m_tableMapper;
private readonly string m_fieldName;
/// <summary>
///
/// </summary>
public string FieldName
{
get { return m_fieldName; }
}
protected Type m_valueType;
/// <summary>
///
/// </summary>
public Type ValueType
{
get { return m_valueType; }
}
public abstract object GetParamValue(object obj);
/// <summary>
///
/// </summary>
/// <param name="tableMapper"></param>
/// <param name="fieldName"></param>
/// <param name="valueType"></param>
public BaseFieldMapper(BaseTableMapper tableMapper, string fieldName, Type valueType)
{
m_fieldName = fieldName;
m_valueType = valueType;
m_tableMapper = tableMapper;
}
public abstract void SetPropertyFromReader(object mapper, BaseDataReader reader);
/// <summary>
///
/// </summary>
/// <param name="command"></param>
/// <param name="fieldNames"></param>
/// <param name="fieldName"></param>
/// <param name="value"></param>
public void RawAddParam(DbCommand command, List<string> fieldNames, string fieldName, object value)
{
string paramName = m_tableMapper.CreateParamName(fieldName);
fieldNames.Add(fieldName);
DbParameter param = command.CreateParameter();
param.ParameterName = paramName;
param.Value = value;
command.Parameters.Add(param);
}
/// <summary>
///
/// </summary>
/// <typeparam name="TObj"></typeparam>
/// <param name="obj"></param>
/// <param name="command"></param>
/// <param name="fieldNames"></param>
public virtual void ExpandField<TObj>(TObj obj, DbCommand command, List<string> fieldNames)
{
string fieldName = FieldName;
object value = GetParamValue(obj);
RawAddParam(command, fieldNames, fieldName, m_tableMapper.ConvertToDbType(value));
}
/// <summary>
///
/// </summary>
/// <param name="reader"></param>
/// <returns></returns>
protected virtual object GetValue(BaseDataReader reader)
{
object value;
if (ValueType == typeof(Guid))
{
value = reader.GetGuid(m_fieldName);
}
else if (ValueType == typeof(bool))
{
uint boolVal = reader.GetUShort(m_fieldName);
value = (boolVal == 1);
}
else
if (ValueType == typeof(byte))
{
value = reader.GetByte(m_fieldName);
}
else if (ValueType == typeof(sbyte))
{
value = reader.GetSByte(m_fieldName);
}
else if (ValueType == typeof(ushort))
{
value = reader.GetUShort(m_fieldName);
}
else if (ValueType == typeof(uint))
{
value = reader.GetUInt32(m_fieldName);
}
else if (ValueType == typeof(byte[]))
{
value = reader.GetBytes(m_fieldName);
}
else
{
value = reader.Get(m_fieldName);
}
if (value is DBNull)
{
value = default(ValueType);
}
return value;
}
}
/// <summary>
///
/// </summary>
/// <typeparam name="TObject"></typeparam>
/// <typeparam name="TField"></typeparam>
public class ObjectField<TObject, TField> : BaseFieldMapper
{
private readonly ObjectGetAccessor<TObject, TField> m_fieldGetAccessor;
private readonly ObjectSetAccessor<TObject, TField> m_fieldSetAccessor;
public override object GetParamValue(object obj)
{
return m_fieldGetAccessor((TObject)obj);
}
public override void SetPropertyFromReader(object obj, BaseDataReader reader)
{
object value;
value = GetValue(reader);
if (value == null)
{
m_fieldSetAccessor((TObject)obj, default(TField));
}
else
{
m_fieldSetAccessor((TObject)obj, (TField)value);
}
}
/// <summary>
///
/// </summary>
/// <param name="tableMapper"></param>
/// <param name="fieldName"></param>
/// <param name="rowMapperGetAccessor"></param>
/// <param name="rowMapperSetAccessor"></param>
public ObjectField(BaseTableMapper tableMapper, string fieldName, ObjectGetAccessor<TObject, TField> rowMapperGetAccessor,
ObjectSetAccessor<TObject, TField> rowMapperSetAccessor)
: base(tableMapper, fieldName, typeof(TField))
{
m_fieldGetAccessor = rowMapperGetAccessor;
m_fieldSetAccessor = rowMapperSetAccessor;
}
}
}

View File

@ -1,78 +0,0 @@
/*
* 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.
*/
namespace OpenSim.Data.Base
{
/// <summary>
///
/// </summary>
public abstract class BaseRowMapper
{
public abstract void FiPrimitive(BaseDataReader reader);
}
/// <summary>
///
/// </summary>
/// <typeparam name="TObj"></typeparam>
public class BaseRowMapper<TObj> : BaseRowMapper
{
private readonly BaseSchema m_schema;
private readonly TObj m_obj;
/// <summary>
///
/// </summary>
public TObj Object
{
get { return m_obj; }
}
/// <summary>
///
/// </summary>
/// <param name="schema"></param>
/// <param name="obj"></param>
public BaseRowMapper(BaseSchema schema, TObj obj)
{
m_schema = schema;
m_obj = obj;
}
/// <summary>
///
/// </summary>
/// <param name="reader"></param>
public override void FiPrimitive(BaseDataReader reader)
{
foreach (BaseFieldMapper fieldMapper in m_schema.Fields.Values)
{
fieldMapper.SetPropertyFromReader(this, reader);
}
}
}
}

View File

@ -1,94 +0,0 @@
/*
* 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.Collections.Generic;
namespace OpenSim.Data.Base
{
/// <summary>
///
/// </summary>
public class BaseSchema
{
protected BaseTableMapper m_tableMapper;
protected Dictionary<string, BaseFieldMapper> m_mappings;
/// <summary>
///
/// </summary>
public Dictionary<string, BaseFieldMapper> Fields
{
get { return m_mappings; }
}
/// <summary>
///
/// </summary>
/// <param name="tableMapper"></param>
public BaseSchema(BaseTableMapper tableMapper)
{
m_mappings = new Dictionary<string, BaseFieldMapper>();
m_tableMapper = tableMapper;
}
}
/// <summary>
///
/// </summary>
/// <typeparam name="TObj"></typeparam>
public class BaseSchema<TObj> : BaseSchema
{
/// <summary>
///
/// </summary>
/// <param name="tableMapper"></param>
public BaseSchema(BaseTableMapper tableMapper)
: base(tableMapper)
{
}
/// <summary>
///
/// </summary>
/// <typeparam name="TField"></typeparam>
/// <param name="fieldName"></param>
/// <param name="rowMapperGetAccessor"></param>
/// <param name="rowMapperSetAccessor"></param>
/// <returns></returns>
public ObjectField<TObj, TField> AddMapping<TField>(string fieldName,
ObjectGetAccessor<TObj, TField> rowMapperGetAccessor,
ObjectSetAccessor<TObj, TField> rowMapperSetAccessor)
{
ObjectField<TObj, TField> rowMapperField =
new ObjectField<TObj, TField>(m_tableMapper, fieldName, rowMapperGetAccessor, rowMapperSetAccessor);
m_mappings.Add(fieldName, rowMapperField);
return rowMapperField;
}
}
}

View File

@ -1,399 +0,0 @@
/*
* 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;
using System.Data;
using System.Data.Common;
namespace OpenSim.Data.Base
{
/// <summary>
///
/// </summary>
public abstract class BaseTableMapper
{
private readonly BaseDatabaseConnector m_database;
private readonly object m_syncRoot = new object();
/// <summary>
///
/// </summary>
/// <param name="action"></param>
protected void WithConnection(Action<DbConnection> action)
{
lock (m_syncRoot)
{
DbConnection m_connection = m_database.GetNewConnection();
if (m_connection.State != ConnectionState.Open)
{
m_connection.Open();
}
action(m_connection);
if (m_connection.State == ConnectionState.Open)
{
m_connection.Close();
}
}
}
private readonly string m_tableName;
public string TableName
{
get { return m_tableName; }
}
protected BaseSchema m_schema;
public BaseSchema Schema
{
get { return m_schema; }
}
protected BaseFieldMapper m_keyFieldMapper;
public BaseFieldMapper KeyFieldMapper
{
get { return m_keyFieldMapper; }
}
/// <summary>
///
/// </summary>
/// <param name="database"></param>
/// <param name="tableName"></param>
public BaseTableMapper(BaseDatabaseConnector database, string tableName)
{
m_database = database;
m_tableName = tableName.ToLower(); // Stupid MySQL hack.
}
/// <summary>
///
/// </summary>
/// <param name="fieldName"></param>
/// <returns></returns>
public string CreateParamName(string fieldName)
{
return m_database.CreateParamName(fieldName);
}
/// <summary>
///
/// </summary>
/// <param name="connection"></param>
/// <param name="fieldName"></param>
/// <param name="primaryKey"></param>
/// <returns></returns>
protected DbCommand CreateSelectCommand(DbConnection connection, string fieldName, object primaryKey)
{
return m_database.CreateSelectCommand(this, connection, fieldName, primaryKey);
}
/// <summary>
///
/// </summary>
/// <param name="command"></param>
/// <param name="fieldName"></param>
/// <param name="key"></param>
/// <returns></returns>
public string CreateCondition(DbCommand command, string fieldName, object key)
{
return m_database.CreateCondition(this, command, fieldName, key);
}
/// <summary>
///
/// </summary>
/// <param name="connection"></param>
/// <param name="obj"></param>
/// <returns></returns>
public DbCommand CreateInsertCommand(DbConnection connection, object obj)
{
return m_database.CreateInsertCommand(this, connection, obj);
}
/// <summary>
///
/// </summary>
/// <param name="connection"></param>
/// <param name="rowMapper"></param>
/// <param name="primaryKey"></param>
/// <returns></returns>
public DbCommand CreateUpdateCommand(DbConnection connection, object rowMapper, object primaryKey)
{
return m_database.CreateUpdateCommand(this, connection, rowMapper, primaryKey);
}
/// <summary>
///
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public object ConvertToDbType(object value)
{
return m_database.ConvertToDbType(value);
}
/// <summary>
///
/// </summary>
/// <param name="reader"></param>
/// <returns></returns>
protected virtual BaseDataReader CreateReader(IDataReader reader)
{
return m_database.CreateReader(reader);
}
}
/// <summary>
///
/// </summary>
/// <typeparam name="TRowMapper"></typeparam>
/// <typeparam name="TPrimaryKey"></typeparam>
public abstract class BaseTableMapper<TRowMapper, TPrimaryKey> : BaseTableMapper
{
/// <summary>
///
/// </summary>
/// <param name="database"></param>
/// <param name="tableName"></param>
public BaseTableMapper(BaseDatabaseConnector database, string tableName)
: base(database, tableName)
{
}
/// <summary>
/// HACK: This is a temporary function used by TryGetValue().
/// Due to a bug in mono 1.2.6, delegate blocks cannot contain
/// a using block. This has been fixed in SVN, so the next
/// mono release should work.
/// </summary>
/// <param name="connection"></param>
/// <param name="primaryKey"></param>
/// <param name="result"></param>
/// <param name="success"></param>
private void TryGetConnectionValue(DbConnection connection, TPrimaryKey primaryKey, ref TRowMapper result, ref bool success)
{
using (
DbCommand command =
CreateSelectCommand(connection, KeyFieldMapper.FieldName, primaryKey))
{
using (IDataReader reader = command.ExecuteReader())
{
if (reader.Read())
{
result = FromReader(CreateReader(reader));
success = true;
}
else
{
success = false;
}
}
}
}
/// <summary>
///
/// </summary>
/// <param name="primaryKey"></param>
/// <param name="value"></param>
/// <returns></returns>
public bool TryGetValue(TPrimaryKey primaryKey, out TRowMapper value)
{
TRowMapper result = default(TRowMapper);
bool success = false;
WithConnection(delegate(DbConnection connection)
{
TryGetConnectionValue(connection, primaryKey, ref result, ref success);
});
value = result;
return success;
}
/// <summary>
/// HACK: This is a temporary function used by Remove().
/// Due to a bug in mono 1.2.6, delegate blocks cannot contain
/// a using block. This has been fixed in SVN, so the next
/// mono release should work.
/// </summary>
/// <param name="connection"></param>
/// <param name="id"></param>
/// <param name="deleted"></param>
protected virtual void TryDelete(DbConnection connection, TPrimaryKey id, ref int deleted)
{
using (
DbCommand command =
CreateDeleteCommand(connection, KeyFieldMapper.FieldName, id))
{
deleted = command.ExecuteNonQuery();
}
}
/// <summary>
///
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public virtual bool Remove(TPrimaryKey id)
{
int deleted = 0;
WithConnection(delegate(DbConnection connection)
{
TryDelete(connection, id, ref deleted);
});
if (deleted == 1)
{
return true;
}
else
{
return false;
}
}
/// <summary>
///
/// </summary>
/// <param name="connection"></param>
/// <param name="fieldName"></param>
/// <param name="primaryKey"></param>
/// <returns></returns>
public DbCommand CreateDeleteCommand(DbConnection connection, string fieldName, TPrimaryKey primaryKey)
{
string table = TableName;
DbCommand command = connection.CreateCommand();
string conditionString = CreateCondition(command, fieldName, primaryKey);
string query =
String.Format("delete from {0} where {1}", table, conditionString);
command.CommandText = query;
command.CommandType = CommandType.Text;
return command;
}
/// <summary>
/// HACK: This is a temporary function used by Update().
/// Due to a bug in mono 1.2.6, delegate blocks cannot contain
/// a using block. This has been fixed in SVN, so the next
/// mono release should work.
/// </summary>
/// <param name="connection"></param>
/// <param name="primaryKey"></param>
/// <param name="value"></param>
/// <param name="updated"></param>
protected void TryUpdate(DbConnection connection, TPrimaryKey primaryKey, TRowMapper value, ref int updated)
{
using (DbCommand command = CreateUpdateCommand(connection, value, primaryKey))
{
updated = command.ExecuteNonQuery();
}
}
/// <summary>
///
/// </summary>
/// <param name="primaryKey"></param>
/// <param name="value"></param>
/// <returns></returns>
public virtual bool Update(TPrimaryKey primaryKey, TRowMapper value)
{
int updated = 0;
WithConnection(delegate(DbConnection connection)
{
TryUpdate(connection, primaryKey, value, ref updated);
});
if (updated == 1)
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// HACK: This is a temporary function used by Add().
/// Due to a bug in mono 1.2.6, delegate blocks cannot contain
/// a using block. This has been fixed in SVN, so the next
/// mono release should work.
/// </summary>
/// <param name="connection"></param>
/// <param name="value"></param>
/// <param name="added"></param>
protected void TryAdd(DbConnection connection, TRowMapper value, ref int added)
{
using (DbCommand command = CreateInsertCommand(connection, value))
{
added = command.ExecuteNonQuery();
}
}
/// <summary>
///
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public virtual bool Add(TRowMapper value)
{
int added = 0;
WithConnection(delegate(DbConnection connection)
{
TryAdd(connection, value, ref added);
});
if (added == 1)
{
return true;
}
else
{
return false;
}
}
public abstract TRowMapper FromReader(BaseDataReader reader);
}
}

View File

@ -1,67 +0,0 @@
/*
* 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.Reflection;
using System.Runtime.InteropServices;
using System.Security;
// General information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly : AssemblyTitle("OpenSim.Data.Base")]
[assembly : AssemblyDescription("Generic Database Abstraction Layer")]
[assembly : AssemblyConfiguration("")]
[assembly : AssemblyCompany("OpenSim Project (www.opensimulator.org)")]
[assembly: AssemblyProduct("OpenSim.Data.Base")]
[assembly: AssemblyCopyright("Copyright (c) 2007 OpenSim Project (www.opensimulator.org)")]
[assembly : AssemblyTrademark("")]
[assembly : AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly : ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly : Guid("9269f421-19d9-4eea-bfe3-c0ffe426fada")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly : AssemblyVersion("1.0.0.0")]
[assembly : AssemblyFileVersion("1.0.0.0")]
[assembly : AllowPartiallyTrustedCallers]

View File

@ -1,64 +0,0 @@
/*
* 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;
using System.Data.Common;
using System.Data.SqlClient;
namespace OpenSim.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 object ConvertToDbType(object value)
{
if (value is UInt32)
{
UInt32 tmpVal = (UInt32) value;
Int64 result = Convert.ToInt64(tmpVal);
return result;
}
return base.ConvertToDbType(value);
}
public override string CreateParamName(string fieldName)
{
return "@" + fieldName;
}
}
}

View File

@ -1,55 +0,0 @@
/*
* 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;
using OpenSim.Data.Base;
using OpenSim.Data.MSSQLMapper;
using OpenSim.Data.MySQLMapper;
namespace OpenSim.Data.MapperFactory
{
public class DataMapperFactory
{
public enum MAPPER_TYPE {
MySQL,
MSSQL,
};
static public BaseDatabaseConnector GetDataBaseMapper(MAPPER_TYPE type, string connectionString)
{
switch (type)
{
case MAPPER_TYPE.MySQL:
return new MySQLDatabaseMapper(connectionString);
case MAPPER_TYPE.MSSQL:
return new MSSQLDatabaseMapper(connectionString);
default:
throw new ArgumentException("Unknown Database Mapper type [" + type + "].");
}
}
}
}

View File

@ -1,38 +0,0 @@
/*
* 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;
namespace OpenSim.Data.MySQLMapper
{
public class MySQLDataReader : OpenSimDataReader
{
public MySQLDataReader(IDataReader source) : base(source)
{
}
}
}

View File

@ -1,58 +0,0 @@
/*
* 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;
using System.Data.Common;
using MySql.Data.MySqlClient;
using OpenSim.Data.Base;
namespace OpenSim.Data.MySQLMapper
{
public class MySQLDatabaseMapper : OpenSimDatabaseConnector
{
public MySQLDatabaseMapper(string connectionString)
: base(connectionString)
{
}
public override DbConnection GetNewConnection()
{
MySqlConnection connection = new MySqlConnection(m_connectionString);
return connection;
}
public override string CreateParamName(string fieldName)
{
return "?" + fieldName;
}
public override BaseDataReader CreateReader(IDataReader reader)
{
return new MySQLDataReader(reader);
}
}
}

View File

@ -1,63 +0,0 @@
/*
* 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;
using OpenMetaverse;
using OpenSim.Data.Base;
namespace OpenSim.Data
{
public class OpenSimDataReader : BaseDataReader
{
public OpenSimDataReader(IDataReader source) : base(source)
{
}
public Vector3 GetVector(string s)
{
float x = GetFloat(s + "X");
float y = GetFloat(s + "Y");
float z = GetFloat(s + "Z");
Vector3 vector = new Vector3(x, y, z);
return vector;
}
public Quaternion GetQuaternion(string s)
{
float x = GetFloat(s + "X");
float y = GetFloat(s + "Y");
float z = GetFloat(s + "Z");
float w = GetFloat(s + "W");
Quaternion quaternion = new Quaternion(x, y, z, w);
return quaternion;
}
}
}

View File

@ -1,55 +0,0 @@
/*
* 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;
using OpenMetaverse;
using OpenSim.Data.Base;
namespace OpenSim.Data
{
public abstract class OpenSimDatabaseConnector : BaseDatabaseConnector
{
public OpenSimDatabaseConnector(string connectionString) : base(connectionString)
{
}
public override object ConvertToDbType(object value)
{
if (value is UUID)
{
return ((UUID)value).ToString();
}
return base.ConvertToDbType(value);
}
public override BaseDataReader CreateReader(IDataReader reader)
{
return new OpenSimDataReader(reader);
}
}
}

View File

@ -1,100 +0,0 @@
/*
* 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;
using System.Collections.Generic;
using System.Data.Common;
using OpenMetaverse;
using OpenSim.Data.Base;
namespace OpenSim.Data
{
public class OpenSimObjectFieldMapper<TObject, TField> : ObjectField<TObject, TField>
{
public OpenSimObjectFieldMapper(BaseTableMapper tableMapper, string fieldName,
ObjectGetAccessor<TObject, TField> rowMapperGetAccessor,
ObjectSetAccessor<TObject, TField> rowMapperSetAccessor)
: base(tableMapper, fieldName, rowMapperGetAccessor, rowMapperSetAccessor)
{
}
public override void ExpandField<TObj>(TObj obj, DbCommand command, List<string> fieldNames)
{
string fieldName = FieldName;
object value = GetParamValue(obj);
if (ValueType == typeof(Vector3))
{
Vector3 vector = (Vector3)value;
RawAddParam(command, fieldNames, fieldName + "X", vector.X);
RawAddParam(command, fieldNames, fieldName + "Y", vector.Y);
RawAddParam(command, fieldNames, fieldName + "Z", vector.Z);
}
else if (ValueType == typeof(Quaternion))
{
Quaternion quaternion = (Quaternion)value;
RawAddParam(command, fieldNames, fieldName + "X", quaternion.X);
RawAddParam(command, fieldNames, fieldName + "Y", quaternion.Y);
RawAddParam(command, fieldNames, fieldName + "Z", quaternion.Z);
RawAddParam(command, fieldNames, fieldName + "W", quaternion.W);
}
else
{
base.ExpandField(obj, command, fieldNames);
}
}
protected override object GetValue(BaseDataReader reader)
{
object value;
OpenSimDataReader osreader = (OpenSimDataReader) reader;
if (ValueType == typeof(Vector3))
{
value = osreader.GetVector(FieldName);
}
else if (ValueType == typeof(Quaternion))
{
value = osreader.GetQuaternion(FieldName);
}
else if (ValueType == typeof(UUID))
{
Guid guid = reader.GetGuid(FieldName);
value = new UUID(guid);
}
else
{
value = base.GetValue(reader);
}
return value;
}
}
}

View File

@ -1,38 +0,0 @@
/*
* 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 OpenSim.Data.Base;
namespace OpenSim.Data
{
public abstract class OpenSimTableMapper<TRowMapper, TPrimaryKey> : BaseTableMapper<TRowMapper, TPrimaryKey>
{
public OpenSimTableMapper(BaseDatabaseConnector database, string tableName) : base(database, tableName)
{
}
}
}

View File

@ -1,170 +0,0 @@
/*
* 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;
using OpenMetaverse;
using OpenSim.Data.Base;
using OpenSim.Framework;
namespace OpenSim.Data
{
public class PrimitiveBaseShapeRowMapper : BaseRowMapper<PrimitiveBaseShape>
{
public Guid SceneObjectPartId;
public PrimitiveBaseShapeRowMapper(BaseSchema schema, PrimitiveBaseShape obj) : base(schema, obj)
{
}
}
public class PrimitiveBaseShapeTableMapper : OpenSimTableMapper<PrimitiveBaseShapeRowMapper, Guid>
{
public PrimitiveBaseShapeTableMapper(BaseDatabaseConnector connection, string tableName)
: base(connection, tableName)
{
BaseSchema<PrimitiveBaseShapeRowMapper> rowMapperSchema = new BaseSchema<PrimitiveBaseShapeRowMapper>(this);
m_schema = rowMapperSchema;
m_keyFieldMapper = rowMapperSchema.AddMapping<Guid>("SceneObjectPartId",
delegate(PrimitiveBaseShapeRowMapper shape) { return shape.SceneObjectPartId; },
delegate(PrimitiveBaseShapeRowMapper shape, Guid value) { shape.SceneObjectPartId = value; });
rowMapperSchema.AddMapping<byte>("PCode",
delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.PCode; },
delegate(PrimitiveBaseShapeRowMapper shape, byte value) { shape.Object.PCode = value; });
rowMapperSchema.AddMapping<ushort>("PathBegin",
delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.PathBegin; },
delegate(PrimitiveBaseShapeRowMapper shape, ushort value) { shape.Object.PathBegin = value; });
rowMapperSchema.AddMapping<ushort>("PathEnd",
delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.PathEnd; },
delegate(PrimitiveBaseShapeRowMapper shape, ushort value) { shape.Object.PathEnd = value; });
rowMapperSchema.AddMapping<byte>("PathScaleX",
delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.PathScaleX; },
delegate(PrimitiveBaseShapeRowMapper shape, byte value) { shape.Object.PathScaleX = value; });
rowMapperSchema.AddMapping<byte>("PathScaleY",
delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.PathScaleY; },
delegate(PrimitiveBaseShapeRowMapper shape, byte value) { shape.Object.PathScaleY = value; });
rowMapperSchema.AddMapping<byte>("PathShearX",
delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.PathShearX; },
delegate(PrimitiveBaseShapeRowMapper shape, byte value) { shape.Object.PathShearX = value; });
rowMapperSchema.AddMapping<byte>("PathShearY",
delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.PathShearY; },
delegate(PrimitiveBaseShapeRowMapper shape, byte value) { shape.Object.PathShearY = value; });
rowMapperSchema.AddMapping<ushort>("ProfileBegin",
delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.ProfileBegin; },
delegate(PrimitiveBaseShapeRowMapper shape, ushort value) { shape.Object.ProfileBegin = value; });
rowMapperSchema.AddMapping<ushort>("ProfileEnd",
delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.ProfileEnd; },
delegate(PrimitiveBaseShapeRowMapper shape, ushort value) { shape.Object.ProfileEnd = value; });
rowMapperSchema.AddMapping<Vector3>("Scale",
delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.Scale; },
delegate(PrimitiveBaseShapeRowMapper shape, Vector3 value) { shape.Object.Scale = value; });
rowMapperSchema.AddMapping<sbyte>("PathTaperX",
delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.PathTaperX; },
delegate(PrimitiveBaseShapeRowMapper shape, sbyte value) { shape.Object.PathTaperX = value; });
rowMapperSchema.AddMapping<sbyte>("PathTaperY",
delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.PathTaperY; },
delegate(PrimitiveBaseShapeRowMapper shape, sbyte value) { shape.Object.PathTaperY = value; });
rowMapperSchema.AddMapping<sbyte>("PathTwist",
delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.PathTwist; },
delegate(PrimitiveBaseShapeRowMapper shape, sbyte value) { shape.Object.PathTwist = value; });
rowMapperSchema.AddMapping<sbyte>("PathRadiusOffset",
delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.PathRadiusOffset; },
delegate(PrimitiveBaseShapeRowMapper shape, sbyte value) { shape.Object.PathRadiusOffset = value; });
rowMapperSchema.AddMapping<byte>("PathRevolutions",
delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.PathRevolutions; },
delegate(PrimitiveBaseShapeRowMapper shape, byte value) { shape.Object.PathRevolutions = value; });
rowMapperSchema.AddMapping<sbyte>("PathTwistBegin",
delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.PathTwistBegin; },
delegate(PrimitiveBaseShapeRowMapper shape, sbyte value) { shape.Object.PathTwistBegin = value; });
rowMapperSchema.AddMapping<byte>("PathCurve",
delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.PathCurve; },
delegate(PrimitiveBaseShapeRowMapper shape, byte value) { shape.Object.PathCurve = value; });
rowMapperSchema.AddMapping<byte>("ProfileCurve",
delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.ProfileCurve; },
delegate(PrimitiveBaseShapeRowMapper shape, byte value) { shape.Object.ProfileCurve = value; });
rowMapperSchema.AddMapping<ushort>("ProfileHollow",
delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.ProfileHollow; },
delegate(PrimitiveBaseShapeRowMapper shape, ushort value) { shape.Object.ProfileHollow = value; });
rowMapperSchema.AddMapping<byte[]>("TextureEntry",
delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.TextureEntry; },
delegate(PrimitiveBaseShapeRowMapper shape, byte[] value) { shape.Object.TextureEntry = value; });
rowMapperSchema.AddMapping<byte[]>("ExtraParams",
delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.ExtraParams; },
delegate(PrimitiveBaseShapeRowMapper shape, byte[] value) { shape.Object.ExtraParams = value; });
}
public override PrimitiveBaseShapeRowMapper FromReader(BaseDataReader reader)
{
PrimitiveBaseShape shape = new PrimitiveBaseShape();
PrimitiveBaseShapeRowMapper mapper = new PrimitiveBaseShapeRowMapper(m_schema, shape);
mapper.FiPrimitive(reader);
return mapper;
}
public bool Update(Guid sceneObjectPartId, PrimitiveBaseShape primitiveBaseShape)
{
PrimitiveBaseShapeRowMapper mapper = CreateRowMapper(sceneObjectPartId, primitiveBaseShape);
return Update(sceneObjectPartId, mapper);
}
public bool Add(Guid sceneObjectPartId, PrimitiveBaseShape primitiveBaseShape)
{
PrimitiveBaseShapeRowMapper mapper = CreateRowMapper(sceneObjectPartId, primitiveBaseShape);
return Add(mapper);
}
private PrimitiveBaseShapeRowMapper CreateRowMapper(Guid sceneObjectPartId, PrimitiveBaseShape primitiveBaseShape)
{
PrimitiveBaseShapeRowMapper mapper = new PrimitiveBaseShapeRowMapper(m_schema, primitiveBaseShape);
mapper.SceneObjectPartId = sceneObjectPartId;
return mapper;
}
}
}

View File

@ -128,29 +128,6 @@
</Files>
</Project>
<Project name="OpenSim.Data.Base" path="OpenSim/Data/Base" 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.Data"/>
<Reference name="OpenSim.Framework"/>
<!-- needed for LLUUID types -->
<Reference name="OpenMetaverseTypes.dll"/>
<Files>
<Match pattern="*.cs" recurse="true"/>
</Files>
</Project>
<Project name="OpenSim.Data" path="OpenSim/Data" type="Library">
<Configuration name="Debug">
<Options>
@ -180,90 +157,6 @@
</Files>
</Project>
<Project name="OpenSim.Data.MySQLMapper" path="OpenSim/Data/MySQLMapper" 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.Data"/>
<Reference name="OpenSim.Data.Base"/>
<Reference name="OpenMetaverseTypes.dll"/>
<Reference name="MySql.Data.dll"/>
<Reference name="OpenSim.Framework.Console"/>
<Reference name="log4net.dll"/>
<Files>
<Match pattern="*.cs" recurse="true"/>
</Files>
</Project>
<Project name="OpenSim.Data.MSSQLMapper" path="OpenSim/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.Data"/>
<Reference name="OpenSim.Data.Base"/>
<Reference name="OpenMetaverseTypes.dll"/>
<Reference name="OpenSim.Framework.Console"/>
<Reference name="log4net.dll"/>
<Files>
<Match pattern="*.cs" recurse="true"/>
</Files>
</Project>
<Project name="OpenSim.Data.MapperFactory" path="OpenSim/Data/MapperFactory" 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.Data"/>
<Reference name="OpenSim.Data.Base"/>
<Reference name="OpenSim.Data.MySQLMapper"/>
<Reference name="OpenSim.Data.MSSQLMapper"/>
<Files>
<Match pattern="*.cs" recurse="true"/>
</Files>
</Project>
<Project name="OpenSim.Framework.Configuration.XML" path="OpenSim/Framework/Configuration/XML" type="Library">
<Configuration name="Debug">
<Options>