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 /ThirdParty/TribalMedia/TribalMedia.Framework.Data | |
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 'ThirdParty/TribalMedia/TribalMedia.Framework.Data')
5 files changed, 18 insertions, 78 deletions
diff --git a/ThirdParty/TribalMedia/TribalMedia.Framework.Data/DataReader.cs b/ThirdParty/TribalMedia/TribalMedia.Framework.Data/DataReader.cs index 6f84d43..4792e9e 100644 --- a/ThirdParty/TribalMedia/TribalMedia.Framework.Data/DataReader.cs +++ b/ThirdParty/TribalMedia/TribalMedia.Framework.Data/DataReader.cs | |||
@@ -61,29 +61,6 @@ namespace TribalMedia.Framework.Data | |||
61 | return (sbyte) m_source.GetInt16(m_source.GetOrdinal(name)); | 61 | return (sbyte) m_source.GetInt16(m_source.GetOrdinal(name)); |
62 | } | 62 | } |
63 | 63 | ||
64 | //public Vector3 GetVector(string s) | ||
65 | //{ | ||
66 | // float x = GetFloat(s + "X"); | ||
67 | // float y = GetFloat(s + "Y"); | ||
68 | // float z = GetFloat(s + "Z"); | ||
69 | |||
70 | // Vector3 vector = new Vector3(x, y, z); | ||
71 | |||
72 | // return vector; | ||
73 | //} | ||
74 | |||
75 | //public Quaternion GetQuaternion(string s) | ||
76 | //{ | ||
77 | // float x = GetFloat(s + "X"); | ||
78 | // float y = GetFloat(s + "Y"); | ||
79 | // float z = GetFloat(s + "Z"); | ||
80 | // float w = GetFloat(s + "W"); | ||
81 | |||
82 | // Quaternion quaternion = new Quaternion(x, y, z, w); | ||
83 | |||
84 | // return quaternion; | ||
85 | //} | ||
86 | |||
87 | public float GetFloat(string name) | 64 | public float GetFloat(string name) |
88 | { | 65 | { |
89 | return m_source.GetFloat(m_source.GetOrdinal(name)); | 66 | return m_source.GetFloat(m_source.GetOrdinal(name)); |
@@ -134,7 +111,7 @@ namespace TribalMedia.Framework.Data | |||
134 | return m_source.Read(); | 111 | return m_source.Read(); |
135 | } | 112 | } |
136 | 113 | ||
137 | internal Guid GetGuid(string name) | 114 | public Guid GetGuid(string name) |
138 | { | 115 | { |
139 | string guidString = GetString(name); | 116 | string guidString = GetString(name); |
140 | if (String.IsNullOrEmpty(guidString)) | 117 | if (String.IsNullOrEmpty(guidString)) |
diff --git a/ThirdParty/TribalMedia/TribalMedia.Framework.Data/DatabaseMapper.cs b/ThirdParty/TribalMedia/TribalMedia.Framework.Data/DatabaseMapper.cs index 0b9d16d..63e59aa 100644 --- a/ThirdParty/TribalMedia/TribalMedia.Framework.Data/DatabaseMapper.cs +++ b/ThirdParty/TribalMedia/TribalMedia.Framework.Data/DatabaseMapper.cs | |||
@@ -41,7 +41,6 @@ namespace TribalMedia.Framework.Data | |||
41 | } | 41 | } |
42 | 42 | ||
43 | public abstract DbConnection GetNewConnection(); | 43 | public abstract DbConnection GetNewConnection(); |
44 | |||
45 | public abstract string CreateParamName(string fieldName); | 44 | public abstract string CreateParamName(string fieldName); |
46 | 45 | ||
47 | public DbCommand CreateSelectCommand(TableMapper mapper, DbConnection connection, string fieldName, object key) | 46 | public DbCommand CreateSelectCommand(TableMapper mapper, DbConnection connection, string fieldName, object key) |
@@ -67,7 +66,7 @@ namespace TribalMedia.Framework.Data | |||
67 | 66 | ||
68 | DbParameter param = command.CreateParameter(); | 67 | DbParameter param = command.CreateParameter(); |
69 | param.ParameterName = keyFieldParamName; | 68 | param.ParameterName = keyFieldParamName; |
70 | param.Value = FieldMapper.ConvertToDbType(key); | 69 | param.Value = ConvertToDbType(key); |
71 | command.Parameters.Add(param); | 70 | command.Parameters.Add(param); |
72 | 71 | ||
73 | return String.Format("{0}={1}", fieldName, keyFieldParamName); | 72 | return String.Format("{0}={1}", fieldName, keyFieldParamName); |
@@ -131,5 +130,10 @@ namespace TribalMedia.Framework.Data | |||
131 | 130 | ||
132 | return command; | 131 | return command; |
133 | } | 132 | } |
133 | |||
134 | public virtual object ConvertToDbType(object value) | ||
135 | { | ||
136 | return value; | ||
137 | } | ||
134 | } | 138 | } |
135 | } \ No newline at end of file | 139 | } \ No newline at end of file |
diff --git a/ThirdParty/TribalMedia/TribalMedia.Framework.Data/FieldMapper.cs b/ThirdParty/TribalMedia/TribalMedia.Framework.Data/FieldMapper.cs index a1fafbe..89bc0f0 100644 --- a/ThirdParty/TribalMedia/TribalMedia.Framework.Data/FieldMapper.cs +++ b/ThirdParty/TribalMedia/TribalMedia.Framework.Data/FieldMapper.cs | |||
@@ -78,52 +78,18 @@ namespace TribalMedia.Framework.Data | |||
78 | command.Parameters.Add(param); | 78 | command.Parameters.Add(param); |
79 | } | 79 | } |
80 | 80 | ||
81 | public void ExpandField<TObj>(TObj obj, DbCommand command, List<string> fieldNames) | 81 | public virtual void ExpandField<TObj>(TObj obj, DbCommand command, List<string> fieldNames) |
82 | { | 82 | { |
83 | string fieldName = FieldName; | 83 | string fieldName = FieldName; |
84 | object value = GetParamValue(obj); | 84 | object value = GetParamValue(obj); |
85 | 85 | ||
86 | //if (ValueType == typeof (Vector3)) | 86 | RawAddParam(command, fieldNames, fieldName, m_tableMapper.ConvertToDbType(value)); |
87 | //{ | ||
88 | // Vector3 vector = (Vector3) value; | ||
89 | |||
90 | // RawAddParam(command, fieldNames, fieldName + "X", vector.X); | ||
91 | // RawAddParam(command, fieldNames, fieldName + "Y", vector.Y); | ||
92 | // RawAddParam(command, fieldNames, fieldName + "Z", vector.Z); | ||
93 | //} | ||
94 | //else if (ValueType == typeof (Quaternion)) | ||
95 | //{ | ||
96 | // Quaternion quaternion = (Quaternion) value; | ||
97 | |||
98 | // RawAddParam(command, fieldNames, fieldName + "X", quaternion.X); | ||
99 | // RawAddParam(command, fieldNames, fieldName + "Y", quaternion.Y); | ||
100 | // RawAddParam(command, fieldNames, fieldName + "Z", quaternion.Z); | ||
101 | // RawAddParam(command, fieldNames, fieldName + "W", quaternion.W); | ||
102 | //} | ||
103 | //else | ||
104 | //{ | ||
105 | RawAddParam(command, fieldNames, fieldName, ConvertToDbType(value)); | ||
106 | //} | ||
107 | } | 87 | } |
108 | 88 | ||
109 | protected object GetValue(DataReader reader) | 89 | protected virtual object GetValue(DataReader reader) |
110 | { | 90 | { |
111 | object value; | 91 | object value; |
112 | //if (ValueType == typeof (Vector3)) | 92 | |
113 | //{ | ||
114 | // value = reader.GetVector(m_fieldName); | ||
115 | //} | ||
116 | //else if (ValueType == typeof (Quaternion)) | ||
117 | //{ | ||
118 | // value = reader.GetQuaternion(m_fieldName); | ||
119 | //} | ||
120 | //else | ||
121 | //if (ValueType == typeof(UID)) | ||
122 | //{ | ||
123 | // Guid guid = reader.GetGuid(m_fieldName); | ||
124 | // value = new UID(guid); | ||
125 | //} | ||
126 | //else | ||
127 | if (ValueType == typeof(Guid)) | 93 | if (ValueType == typeof(Guid)) |
128 | { | 94 | { |
129 | value = reader.GetGuid(m_fieldName); | 95 | value = reader.GetGuid(m_fieldName); |
@@ -162,16 +128,6 @@ namespace TribalMedia.Framework.Data | |||
162 | 128 | ||
163 | return value; | 129 | return value; |
164 | } | 130 | } |
165 | |||
166 | public static object ConvertToDbType(object value) | ||
167 | { | ||
168 | //if (value is UID) | ||
169 | //{ | ||
170 | // return (value as UID).UUID.ToString(); | ||
171 | //} | ||
172 | |||
173 | return value; | ||
174 | } | ||
175 | } | 131 | } |
176 | 132 | ||
177 | public class RowMapperField<TRowMapper, TField> : FieldMapper | 133 | public class RowMapperField<TRowMapper, TField> : FieldMapper |
diff --git a/ThirdParty/TribalMedia/TribalMedia.Framework.Data/ObjectTableMapper.cs b/ThirdParty/TribalMedia/TribalMedia.Framework.Data/ObjectTableMapper.cs index 44a6542..818c530 100644 --- a/ThirdParty/TribalMedia/TribalMedia.Framework.Data/ObjectTableMapper.cs +++ b/ThirdParty/TribalMedia/TribalMedia.Framework.Data/ObjectTableMapper.cs | |||
@@ -25,10 +25,8 @@ | |||
25 | */ | 25 | */ |
26 | 26 | ||
27 | using System; | 27 | using System; |
28 | using System.Collections.Generic; | ||
29 | using System.Data; | 28 | using System.Data; |
30 | using System.Data.Common; | 29 | using System.Data.Common; |
31 | using TribalMedia.Framework.Data; | ||
32 | 30 | ||
33 | namespace TribalMedia.Framework.Data | 31 | namespace TribalMedia.Framework.Data |
34 | { | 32 | { |
diff --git a/ThirdParty/TribalMedia/TribalMedia.Framework.Data/TableMapper.cs b/ThirdParty/TribalMedia/TribalMedia.Framework.Data/TableMapper.cs index 15005f8..480a015 100644 --- a/ThirdParty/TribalMedia/TribalMedia.Framework.Data/TableMapper.cs +++ b/ThirdParty/TribalMedia/TribalMedia.Framework.Data/TableMapper.cs | |||
@@ -62,13 +62,13 @@ namespace TribalMedia.Framework.Data | |||
62 | get { return m_tableName; } | 62 | get { return m_tableName; } |
63 | } | 63 | } |
64 | 64 | ||
65 | private Schema m_schema; | 65 | protected Schema m_schema; |
66 | public Schema Schema | 66 | public Schema Schema |
67 | { | 67 | { |
68 | get { return m_schema; } | 68 | get { return m_schema; } |
69 | } | 69 | } |
70 | 70 | ||
71 | private FieldMapper m_keyFieldMapper; | 71 | protected FieldMapper m_keyFieldMapper; |
72 | public FieldMapper KeyFieldMapper | 72 | public FieldMapper KeyFieldMapper |
73 | { | 73 | { |
74 | get { return m_keyFieldMapper; } | 74 | get { return m_keyFieldMapper; } |
@@ -104,5 +104,10 @@ namespace TribalMedia.Framework.Data | |||
104 | { | 104 | { |
105 | return m_connectionPool.CreateUpdateCommand(this, connection, rowMapper, primaryKey); | 105 | return m_connectionPool.CreateUpdateCommand(this, connection, rowMapper, primaryKey); |
106 | } | 106 | } |
107 | |||
108 | public object ConvertToDbType(object value) | ||
109 | { | ||
110 | return m_connectionPool.ConvertToDbType(value); | ||
111 | } | ||
107 | } | 112 | } |
108 | } \ No newline at end of file | 113 | } \ No newline at end of file |