diff options
author | lbsa71 | 2008-01-14 22:34:19 +0000 |
---|---|---|
committer | lbsa71 | 2008-01-14 22:34:19 +0000 |
commit | 6d751411b7f996c486052c8cbbdbe1e186cebd9f (patch) | |
tree | eb7a0a101695e85cefb3a8f0ed540d402caedc63 /OpenSim/Framework/Data/OpenSimObjectFieldMapper.cs | |
parent | my Exists check was slow and wrong. This fixes issues people (diff) | |
download | opensim-SC-6d751411b7f996c486052c8cbbdbe1e186cebd9f.zip opensim-SC-6d751411b7f996c486052c8cbbdbe1e186cebd9f.tar.gz opensim-SC-6d751411b7f996c486052c8cbbdbe1e186cebd9f.tar.bz2 opensim-SC-6d751411b7f996c486052c8cbbdbe1e186cebd9f.tar.xz |
* 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
Diffstat (limited to 'OpenSim/Framework/Data/OpenSimObjectFieldMapper.cs')
-rw-r--r-- | OpenSim/Framework/Data/OpenSimObjectFieldMapper.cs | 73 |
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 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Text; | ||
4 | using libsecondlife; | ||
5 | using TribalMedia.Framework.Data; | ||
6 | |||
7 | namespace 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 | } | ||