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 | |
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 '')
-rw-r--r-- | OpenSim/Framework/Data.MySQL/MySQLDatabaseMapper.cs | 24 | ||||
-rw-r--r-- | OpenSim/Framework/Data/OpenSimDataReader.cs | 39 | ||||
-rw-r--r-- | OpenSim/Framework/Data/OpenSimDatabaseMapper.cs | 23 | ||||
-rw-r--r-- | OpenSim/Framework/Data/OpenSimObjectFieldMapper.cs | 73 | ||||
-rw-r--r-- | OpenSim/Framework/Data/PrimitiveBaseShapeTableMapper.cs | 143 |
5 files changed, 302 insertions, 0 deletions
diff --git a/OpenSim/Framework/Data.MySQL/MySQLDatabaseMapper.cs b/OpenSim/Framework/Data.MySQL/MySQLDatabaseMapper.cs new file mode 100644 index 0000000..1514f00 --- /dev/null +++ b/OpenSim/Framework/Data.MySQL/MySQLDatabaseMapper.cs | |||
@@ -0,0 +1,24 @@ | |||
1 | using System.Data.Common; | ||
2 | using MySql.Data.MySqlClient; | ||
3 | |||
4 | namespace OpenSim.Framework.Data.MySQL | ||
5 | { | ||
6 | public class MySQLDatabaseMapper : OpenSimDatabaseMapper | ||
7 | { | ||
8 | public MySQLDatabaseMapper(string connectionString) | ||
9 | : base(connectionString) | ||
10 | { | ||
11 | } | ||
12 | |||
13 | public override DbConnection GetNewConnection() | ||
14 | { | ||
15 | MySqlConnection connection = new MySqlConnection(m_connectionString); | ||
16 | return connection; | ||
17 | } | ||
18 | |||
19 | public override string CreateParamName(string fieldName) | ||
20 | { | ||
21 | return "?" + fieldName; | ||
22 | } | ||
23 | } | ||
24 | } | ||
diff --git a/OpenSim/Framework/Data/OpenSimDataReader.cs b/OpenSim/Framework/Data/OpenSimDataReader.cs new file mode 100644 index 0000000..225df60 --- /dev/null +++ b/OpenSim/Framework/Data/OpenSimDataReader.cs | |||
@@ -0,0 +1,39 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Data; | ||
4 | using System.Text; | ||
5 | using libsecondlife; | ||
6 | using TribalMedia.Framework.Data; | ||
7 | |||
8 | namespace OpenSim.Framework.Data | ||
9 | { | ||
10 | public class OpenSimDataReader : DataReader | ||
11 | { | ||
12 | public OpenSimDataReader(IDataReader source) : base(source) | ||
13 | { | ||
14 | } | ||
15 | |||
16 | public LLVector3 GetVector(string s) | ||
17 | { | ||
18 | float x = GetFloat(s + "X"); | ||
19 | float y = GetFloat(s + "Y"); | ||
20 | float z = GetFloat(s + "Z"); | ||
21 | |||
22 | LLVector3 vector = new LLVector3(x, y, z); | ||
23 | |||
24 | return vector; | ||
25 | } | ||
26 | |||
27 | public LLQuaternion GetQuaternion(string s) | ||
28 | { | ||
29 | float x = GetFloat(s + "X"); | ||
30 | float y = GetFloat(s + "Y"); | ||
31 | float z = GetFloat(s + "Z"); | ||
32 | float w = GetFloat(s + "W"); | ||
33 | |||
34 | LLQuaternion quaternion = new LLQuaternion(x, y, z, w); | ||
35 | |||
36 | return quaternion; | ||
37 | } | ||
38 | } | ||
39 | } | ||
diff --git a/OpenSim/Framework/Data/OpenSimDatabaseMapper.cs b/OpenSim/Framework/Data/OpenSimDatabaseMapper.cs new file mode 100644 index 0000000..2001110 --- /dev/null +++ b/OpenSim/Framework/Data/OpenSimDatabaseMapper.cs | |||
@@ -0,0 +1,23 @@ | |||
1 | using System.Data.Common; | ||
2 | using libsecondlife; | ||
3 | using TribalMedia.Framework.Data; | ||
4 | |||
5 | namespace OpenSim.Framework.Data | ||
6 | { | ||
7 | public abstract class OpenSimDatabaseMapper : DatabaseMapper | ||
8 | { | ||
9 | public OpenSimDatabaseMapper(string connectionString) : base(connectionString) | ||
10 | { | ||
11 | } | ||
12 | |||
13 | public override object ConvertToDbType(object value) | ||
14 | { | ||
15 | if (value is LLUUID) | ||
16 | { | ||
17 | return ((LLUUID) value).UUID.ToString(); | ||
18 | } | ||
19 | |||
20 | return base.ConvertToDbType(value); | ||
21 | } | ||
22 | } | ||
23 | } | ||
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 | } | ||
diff --git a/OpenSim/Framework/Data/PrimitiveBaseShapeTableMapper.cs b/OpenSim/Framework/Data/PrimitiveBaseShapeTableMapper.cs new file mode 100644 index 0000000..8026373 --- /dev/null +++ b/OpenSim/Framework/Data/PrimitiveBaseShapeTableMapper.cs | |||
@@ -0,0 +1,143 @@ | |||
1 | using System; | ||
2 | using OpenSim.Framework; | ||
3 | using TribalMedia.Framework.Data; | ||
4 | using libsecondlife; | ||
5 | |||
6 | namespace OpenSim.Framework.Data | ||
7 | { | ||
8 | public class PrimitiveBaseShapeRowMapper : RowMapper<PrimitiveBaseShape> | ||
9 | { | ||
10 | public Guid SceneObjectPartId; | ||
11 | |||
12 | public PrimitiveBaseShapeRowMapper(Schema schema, PrimitiveBaseShape obj) : base(schema, obj) | ||
13 | { | ||
14 | } | ||
15 | } | ||
16 | |||
17 | public class PrimitiveBaseShapeTableMapper : ObjectTableMapper<PrimitiveBaseShapeRowMapper, Guid> | ||
18 | { | ||
19 | public PrimitiveBaseShapeTableMapper(DatabaseMapper connection, string tableName) | ||
20 | : base(connection, tableName) | ||
21 | { | ||
22 | RowMapperSchema<PrimitiveBaseShapeRowMapper> rowMapperSchema = new RowMapperSchema<PrimitiveBaseShapeRowMapper>(this); | ||
23 | m_schema = rowMapperSchema; | ||
24 | |||
25 | m_keyFieldMapper = rowMapperSchema.AddMapping<Guid>("SceneObjectPartId", | ||
26 | delegate(PrimitiveBaseShapeRowMapper shape) { return shape.SceneObjectPartId; }, | ||
27 | delegate(PrimitiveBaseShapeRowMapper shape, Guid value) { shape.SceneObjectPartId = value; }); | ||
28 | |||
29 | rowMapperSchema.AddMapping<byte>("PCode", | ||
30 | delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.PCode; }, | ||
31 | delegate(PrimitiveBaseShapeRowMapper shape, byte value) { shape.Object.PCode = value; }); | ||
32 | |||
33 | rowMapperSchema.AddMapping<ushort>("PathBegin", | ||
34 | delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.PathBegin; }, | ||
35 | delegate(PrimitiveBaseShapeRowMapper shape, ushort value) { shape.Object.PathBegin = value; }); | ||
36 | |||
37 | rowMapperSchema.AddMapping<ushort>("PathEnd", | ||
38 | delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.PathEnd; }, | ||
39 | delegate(PrimitiveBaseShapeRowMapper shape, ushort value) { shape.Object.PathEnd = value; }); | ||
40 | |||
41 | rowMapperSchema.AddMapping<byte>("PathScaleX", | ||
42 | delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.PathScaleX; }, | ||
43 | delegate(PrimitiveBaseShapeRowMapper shape, byte value) { shape.Object.PathScaleX = value; }); | ||
44 | |||
45 | rowMapperSchema.AddMapping<byte>("PathScaleY", | ||
46 | delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.PathScaleY; }, | ||
47 | delegate(PrimitiveBaseShapeRowMapper shape, byte value) { shape.Object.PathScaleY = value; }); | ||
48 | |||
49 | rowMapperSchema.AddMapping<byte>("PathShearX", | ||
50 | delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.PathShearX; }, | ||
51 | delegate(PrimitiveBaseShapeRowMapper shape, byte value) { shape.Object.PathShearX = value; }); | ||
52 | |||
53 | rowMapperSchema.AddMapping<byte>("PathShearY", | ||
54 | delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.PathShearY; }, | ||
55 | delegate(PrimitiveBaseShapeRowMapper shape, byte value) { shape.Object.PathShearY = value; }); | ||
56 | |||
57 | rowMapperSchema.AddMapping<ushort>("ProfileBegin", | ||
58 | delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.ProfileBegin; }, | ||
59 | delegate(PrimitiveBaseShapeRowMapper shape, ushort value) { shape.Object.ProfileBegin = value; }); | ||
60 | |||
61 | rowMapperSchema.AddMapping<ushort>("ProfileEnd", | ||
62 | delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.ProfileEnd; }, | ||
63 | delegate(PrimitiveBaseShapeRowMapper shape, ushort value) { shape.Object.ProfileEnd = value; }); | ||
64 | |||
65 | rowMapperSchema.AddMapping<LLVector3>("Scale", | ||
66 | delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.Scale; }, | ||
67 | delegate(PrimitiveBaseShapeRowMapper shape, LLVector3 value) { shape.Object.Scale = value; }); | ||
68 | |||
69 | rowMapperSchema.AddMapping<sbyte>("PathTaperX", | ||
70 | delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.PathTaperX; }, | ||
71 | delegate(PrimitiveBaseShapeRowMapper shape, sbyte value) { shape.Object.PathTaperX = value; }); | ||
72 | |||
73 | rowMapperSchema.AddMapping<sbyte>("PathTaperY", | ||
74 | delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.PathTaperY; }, | ||
75 | delegate(PrimitiveBaseShapeRowMapper shape, sbyte value) { shape.Object.PathTaperY = value; }); | ||
76 | |||
77 | rowMapperSchema.AddMapping<sbyte>("PathTwist", | ||
78 | delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.PathTwist; }, | ||
79 | delegate(PrimitiveBaseShapeRowMapper shape, sbyte value) { shape.Object.PathTwist = value; }); | ||
80 | |||
81 | rowMapperSchema.AddMapping<sbyte>("PathRadiusOffset", | ||
82 | delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.PathRadiusOffset; }, | ||
83 | delegate(PrimitiveBaseShapeRowMapper shape, sbyte value) { shape.Object.PathRadiusOffset = value; }); | ||
84 | |||
85 | rowMapperSchema.AddMapping<byte>("PathRevolutions", | ||
86 | delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.PathRevolutions; }, | ||
87 | delegate(PrimitiveBaseShapeRowMapper shape, byte value) { shape.Object.PathRevolutions = value; }); | ||
88 | |||
89 | rowMapperSchema.AddMapping<sbyte>("PathTwistBegin", | ||
90 | delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.PathTwistBegin; }, | ||
91 | delegate(PrimitiveBaseShapeRowMapper shape, sbyte value) { shape.Object.PathTwistBegin = value; }); | ||
92 | |||
93 | rowMapperSchema.AddMapping<byte>("PathCurve", | ||
94 | delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.PathCurve; }, | ||
95 | delegate(PrimitiveBaseShapeRowMapper shape, byte value) { shape.Object.PathCurve = value; }); | ||
96 | |||
97 | rowMapperSchema.AddMapping<byte>("ProfileCurve", | ||
98 | delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.ProfileCurve; }, | ||
99 | delegate(PrimitiveBaseShapeRowMapper shape, byte value) { shape.Object.ProfileCurve = value; }); | ||
100 | |||
101 | rowMapperSchema.AddMapping<ushort>("ProfileHollow", | ||
102 | delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.ProfileHollow; }, | ||
103 | delegate(PrimitiveBaseShapeRowMapper shape, ushort value) { shape.Object.ProfileHollow = value; }); | ||
104 | |||
105 | rowMapperSchema.AddMapping<byte[]>("TextureEntry", | ||
106 | delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.TextureEntry; }, | ||
107 | delegate(PrimitiveBaseShapeRowMapper shape, byte[] value) { shape.Object.TextureEntry = value; }); | ||
108 | |||
109 | rowMapperSchema.AddMapping<byte[]>("ExtraParams", | ||
110 | delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.ExtraParams; }, | ||
111 | delegate(PrimitiveBaseShapeRowMapper shape, byte[] value) { shape.Object.ExtraParams = value; }); | ||
112 | } | ||
113 | |||
114 | public override PrimitiveBaseShapeRowMapper FromReader(DataReader reader) | ||
115 | { | ||
116 | PrimitiveBaseShape shape = new PrimitiveBaseShape(); | ||
117 | |||
118 | PrimitiveBaseShapeRowMapper mapper = new PrimitiveBaseShapeRowMapper(m_schema, shape); | ||
119 | mapper.FillObject( reader ); | ||
120 | |||
121 | return mapper; | ||
122 | } | ||
123 | |||
124 | public bool Update(Guid sceneObjectPartId, PrimitiveBaseShape primitiveBaseShape) | ||
125 | { | ||
126 | PrimitiveBaseShapeRowMapper mapper = CreateRowMapper(sceneObjectPartId, primitiveBaseShape); | ||
127 | return Update(sceneObjectPartId, mapper); | ||
128 | } | ||
129 | |||
130 | public bool Add(Guid sceneObjectPartId, PrimitiveBaseShape primitiveBaseShape) | ||
131 | { | ||
132 | PrimitiveBaseShapeRowMapper mapper = CreateRowMapper(sceneObjectPartId, primitiveBaseShape); | ||
133 | return Add(mapper); | ||
134 | } | ||
135 | |||
136 | private PrimitiveBaseShapeRowMapper CreateRowMapper(Guid sceneObjectPartId, PrimitiveBaseShape primitiveBaseShape) | ||
137 | { | ||
138 | PrimitiveBaseShapeRowMapper mapper = new PrimitiveBaseShapeRowMapper( m_schema, primitiveBaseShape ); | ||
139 | mapper.SceneObjectPartId = sceneObjectPartId; | ||
140 | return mapper; | ||
141 | } | ||
142 | } | ||
143 | } \ No newline at end of file | ||