aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Data/OpenSimObjectFieldMapper.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Framework/Data/OpenSimObjectFieldMapper.cs')
-rw-r--r--OpenSim/Framework/Data/OpenSimObjectFieldMapper.cs73
1 files changed, 73 insertions, 0 deletions
diff --git a/OpenSim/Framework/Data/OpenSimObjectFieldMapper.cs b/OpenSim/Framework/Data/OpenSimObjectFieldMapper.cs
new file mode 100644
index 0000000..2b20a79
--- /dev/null
+++ b/OpenSim/Framework/Data/OpenSimObjectFieldMapper.cs
@@ -0,0 +1,73 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4using libsecondlife;
5using TribalMedia.Framework.Data;
6
7namespace OpenSim.Framework.Data
8{
9 public class OpenSimObjectFieldMapper<TObject, TField> : ObjectField<TObject, TField>
10 {
11 public OpenSimObjectFieldMapper(TableMapper tableMapper, string fieldName,
12 ObjectGetAccessor<TObject, TField> rowMapperGetAccessor,
13 ObjectSetAccessor<TObject, TField> rowMapperSetAccessor)
14 : base(tableMapper, fieldName, rowMapperGetAccessor, rowMapperSetAccessor)
15 {
16 }
17
18 public override void ExpandField<TObj>(TObj obj, System.Data.Common.DbCommand command, List<string> fieldNames)
19 {
20 string fieldName = FieldName;
21 object value = GetParamValue(obj);
22
23 if (ValueType == typeof(LLVector3))
24 {
25 LLVector3 vector = (LLVector3)value;
26
27 RawAddParam(command, fieldNames, fieldName + "X", vector.X);
28 RawAddParam(command, fieldNames, fieldName + "Y", vector.Y);
29 RawAddParam(command, fieldNames, fieldName + "Z", vector.Z);
30 }
31 else if (ValueType == typeof(LLQuaternion))
32 {
33 LLQuaternion quaternion = (LLQuaternion)value;
34
35 RawAddParam(command, fieldNames, fieldName + "X", quaternion.X);
36 RawAddParam(command, fieldNames, fieldName + "Y", quaternion.Y);
37 RawAddParam(command, fieldNames, fieldName + "Z", quaternion.Z);
38 RawAddParam(command, fieldNames, fieldName + "W", quaternion.W);
39 }
40 else
41 {
42 base.ExpandField<TObj>(obj, command, fieldNames);
43 }
44 }
45
46 protected override object GetValue(DataReader reader)
47 {
48 object value;
49
50 OpenSimDataReader osreader = (OpenSimDataReader) reader;
51
52 if (ValueType == typeof(LLVector3))
53 {
54 value = osreader.GetVector(FieldName);
55 }
56 else if (ValueType == typeof(LLQuaternion))
57 {
58 value = osreader.GetQuaternion(FieldName);
59 }
60 else if (ValueType == typeof(LLUUID))
61 {
62 Guid guid = reader.GetGuid(FieldName);
63 value = new LLUUID(guid);
64 }
65 else
66 {
67 value = base.GetValue(reader);
68 }
69
70 return value;
71 }
72 }
73}