mirror of
https://github.com/opensim/opensim.git
synced 2026-07-14 11:45:35 +08:00
* Added specialization of DatabaseMapper, DataReader and ObjectFieldMapper to support LLVector3, LLQuaternion and LLUUID
* Added PrimitiveBaseShapeTableMapper to show how it's done NOTE: Nothing actually works yet - this code should be considered more of educational value until it's all wired together
This commit is contained in:
73
OpenSim/Framework/Data/OpenSimObjectFieldMapper.cs
Normal file
73
OpenSim/Framework/Data/OpenSimObjectFieldMapper.cs
Normal file
@@ -0,0 +1,73 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using libsecondlife;
|
||||
using TribalMedia.Framework.Data;
|
||||
|
||||
namespace OpenSim.Framework.Data
|
||||
{
|
||||
public class OpenSimObjectFieldMapper<TObject, TField> : ObjectField<TObject, TField>
|
||||
{
|
||||
public OpenSimObjectFieldMapper(TableMapper tableMapper, string fieldName,
|
||||
ObjectGetAccessor<TObject, TField> rowMapperGetAccessor,
|
||||
ObjectSetAccessor<TObject, TField> rowMapperSetAccessor)
|
||||
: base(tableMapper, fieldName, rowMapperGetAccessor, rowMapperSetAccessor)
|
||||
{
|
||||
}
|
||||
|
||||
public override void ExpandField<TObj>(TObj obj, System.Data.Common.DbCommand command, List<string> fieldNames)
|
||||
{
|
||||
string fieldName = FieldName;
|
||||
object value = GetParamValue(obj);
|
||||
|
||||
if (ValueType == typeof(LLVector3))
|
||||
{
|
||||
LLVector3 vector = (LLVector3)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(LLQuaternion))
|
||||
{
|
||||
LLQuaternion quaternion = (LLQuaternion)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<TObj>(obj, command, fieldNames);
|
||||
}
|
||||
}
|
||||
|
||||
protected override object GetValue(DataReader reader)
|
||||
{
|
||||
object value;
|
||||
|
||||
OpenSimDataReader osreader = (OpenSimDataReader) reader;
|
||||
|
||||
if (ValueType == typeof(LLVector3))
|
||||
{
|
||||
value = osreader.GetVector(FieldName);
|
||||
}
|
||||
else if (ValueType == typeof(LLQuaternion))
|
||||
{
|
||||
value = osreader.GetQuaternion(FieldName);
|
||||
}
|
||||
else if (ValueType == typeof(LLUUID))
|
||||
{
|
||||
Guid guid = reader.GetGuid(FieldName);
|
||||
value = new LLUUID(guid);
|
||||
}
|
||||
else
|
||||
{
|
||||
value = base.GetValue(reader);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user