diff options
author | Jeff Ames | 2008-06-26 20:20:30 +0000 |
---|---|---|
committer | Jeff Ames | 2008-06-26 20:20:30 +0000 |
commit | d96caaa14e9e869e85eecc6b760221ad0579f68e (patch) | |
tree | ccb720f2b7df128d9db0285c58ee6cc63a291ba8 /OpenSim/Data/Base/BaseTableMapper.cs | |
parent | Apply patch from bug #1605 -- Documentation for Data/SQLite. Thanks kerunix_... (diff) | |
download | opensim-SC-d96caaa14e9e869e85eecc6b760221ad0579f68e.zip opensim-SC-d96caaa14e9e869e85eecc6b760221ad0579f68e.tar.gz opensim-SC-d96caaa14e9e869e85eecc6b760221ad0579f68e.tar.bz2 opensim-SC-d96caaa14e9e869e85eecc6b760221ad0579f68e.tar.xz |
Apply patch from bug #1606 -- Documentation for Data/Null, Data/Base. Thanks kerunix_Flan!
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Data/Base/BaseTableMapper.cs | 151 |
1 files changed, 135 insertions, 16 deletions
diff --git a/OpenSim/Data/Base/BaseTableMapper.cs b/OpenSim/Data/Base/BaseTableMapper.cs index 649b228..28b7ac8 100644 --- a/OpenSim/Data/Base/BaseTableMapper.cs +++ b/OpenSim/Data/Base/BaseTableMapper.cs | |||
@@ -31,11 +31,18 @@ using System.Data.Common; | |||
31 | 31 | ||
32 | namespace OpenSim.Data.Base | 32 | namespace OpenSim.Data.Base |
33 | { | 33 | { |
34 | /// <summary> | ||
35 | /// | ||
36 | /// </summary> | ||
34 | public abstract class BaseTableMapper | 37 | public abstract class BaseTableMapper |
35 | { | 38 | { |
36 | private readonly BaseDatabaseConnector m_database; | 39 | private readonly BaseDatabaseConnector m_database; |
37 | private readonly object m_syncRoot = new object(); | 40 | private readonly object m_syncRoot = new object(); |
38 | 41 | ||
42 | /// <summary> | ||
43 | /// | ||
44 | /// </summary> | ||
45 | /// <param name="action"></param> | ||
39 | protected void WithConnection(Action<DbConnection> action) | 46 | protected void WithConnection(Action<DbConnection> action) |
40 | { | 47 | { |
41 | lock (m_syncRoot) | 48 | lock (m_syncRoot) |
@@ -74,59 +81,124 @@ namespace OpenSim.Data.Base | |||
74 | get { return m_keyFieldMapper; } | 81 | get { return m_keyFieldMapper; } |
75 | } | 82 | } |
76 | 83 | ||
84 | /// <summary> | ||
85 | /// | ||
86 | /// </summary> | ||
87 | /// <param name="database"></param> | ||
88 | /// <param name="tableName"></param> | ||
77 | public BaseTableMapper(BaseDatabaseConnector database, string tableName) | 89 | public BaseTableMapper(BaseDatabaseConnector database, string tableName) |
78 | { | 90 | { |
79 | m_database = database; | 91 | m_database = database; |
80 | m_tableName = tableName.ToLower(); // Stupid MySQL hack. | 92 | m_tableName = tableName.ToLower(); // Stupid MySQL hack. |
81 | } | 93 | } |
82 | 94 | ||
95 | /// <summary> | ||
96 | /// | ||
97 | /// </summary> | ||
98 | /// <param name="fieldName"></param> | ||
99 | /// <returns></returns> | ||
83 | public string CreateParamName(string fieldName) | 100 | public string CreateParamName(string fieldName) |
84 | { | 101 | { |
85 | return m_database.CreateParamName(fieldName); | 102 | return m_database.CreateParamName(fieldName); |
86 | } | 103 | } |
87 | 104 | ||
105 | /// <summary> | ||
106 | /// | ||
107 | /// </summary> | ||
108 | /// <param name="connection"></param> | ||
109 | /// <param name="fieldName"></param> | ||
110 | /// <param name="primaryKey"></param> | ||
111 | /// <returns></returns> | ||
88 | protected DbCommand CreateSelectCommand(DbConnection connection, string fieldName, object primaryKey) | 112 | protected DbCommand CreateSelectCommand(DbConnection connection, string fieldName, object primaryKey) |
89 | { | 113 | { |
90 | return m_database.CreateSelectCommand(this, connection, fieldName, primaryKey); | 114 | return m_database.CreateSelectCommand(this, connection, fieldName, primaryKey); |
91 | } | 115 | } |
92 | 116 | ||
117 | /// <summary> | ||
118 | /// | ||
119 | /// </summary> | ||
120 | /// <param name="command"></param> | ||
121 | /// <param name="fieldName"></param> | ||
122 | /// <param name="key"></param> | ||
123 | /// <returns></returns> | ||
93 | public string CreateCondition(DbCommand command, string fieldName, object key) | 124 | public string CreateCondition(DbCommand command, string fieldName, object key) |
94 | { | 125 | { |
95 | return m_database.CreateCondition(this, command, fieldName, key); | 126 | return m_database.CreateCondition(this, command, fieldName, key); |
96 | } | 127 | } |
97 | 128 | ||
129 | /// <summary> | ||
130 | /// | ||
131 | /// </summary> | ||
132 | /// <param name="connection"></param> | ||
133 | /// <param name="obj"></param> | ||
134 | /// <returns></returns> | ||
98 | public DbCommand CreateInsertCommand(DbConnection connection, object obj) | 135 | public DbCommand CreateInsertCommand(DbConnection connection, object obj) |
99 | { | 136 | { |
100 | return m_database.CreateInsertCommand(this, connection, obj); | 137 | return m_database.CreateInsertCommand(this, connection, obj); |
101 | } | 138 | } |
102 | 139 | ||
140 | /// <summary> | ||
141 | /// | ||
142 | /// </summary> | ||
143 | /// <param name="connection"></param> | ||
144 | /// <param name="rowMapper"></param> | ||
145 | /// <param name="primaryKey"></param> | ||
146 | /// <returns></returns> | ||
103 | public DbCommand CreateUpdateCommand(DbConnection connection, object rowMapper, object primaryKey) | 147 | public DbCommand CreateUpdateCommand(DbConnection connection, object rowMapper, object primaryKey) |
104 | { | 148 | { |
105 | return m_database.CreateUpdateCommand(this, connection, rowMapper, primaryKey); | 149 | return m_database.CreateUpdateCommand(this, connection, rowMapper, primaryKey); |
106 | } | 150 | } |
107 | 151 | ||
152 | /// <summary> | ||
153 | /// | ||
154 | /// </summary> | ||
155 | /// <param name="value"></param> | ||
156 | /// <returns></returns> | ||
108 | public object ConvertToDbType(object value) | 157 | public object ConvertToDbType(object value) |
109 | { | 158 | { |
110 | return m_database.ConvertToDbType(value); | 159 | return m_database.ConvertToDbType(value); |
111 | } | 160 | } |
112 | 161 | ||
162 | /// <summary> | ||
163 | /// | ||
164 | /// </summary> | ||
165 | /// <param name="reader"></param> | ||
166 | /// <returns></returns> | ||
113 | protected virtual BaseDataReader CreateReader(IDataReader reader) | 167 | protected virtual BaseDataReader CreateReader(IDataReader reader) |
114 | { | 168 | { |
115 | return m_database.CreateReader(reader); | 169 | return m_database.CreateReader(reader); |
116 | } | 170 | } |
117 | } | 171 | } |
118 | 172 | ||
173 | /// <summary> | ||
174 | /// | ||
175 | /// </summary> | ||
176 | /// <typeparam name="TRowMapper"></typeparam> | ||
177 | /// <typeparam name="TPrimaryKey"></typeparam> | ||
119 | public abstract class BaseTableMapper<TRowMapper, TPrimaryKey> : BaseTableMapper | 178 | public abstract class BaseTableMapper<TRowMapper, TPrimaryKey> : BaseTableMapper |
120 | { | 179 | { |
180 | /// <summary> | ||
181 | /// | ||
182 | /// </summary> | ||
183 | /// <param name="database"></param> | ||
184 | /// <param name="tableName"></param> | ||
121 | public BaseTableMapper(BaseDatabaseConnector database, string tableName) | 185 | public BaseTableMapper(BaseDatabaseConnector database, string tableName) |
122 | : base(database, tableName) | 186 | : base(database, tableName) |
123 | { | 187 | { |
124 | } | 188 | } |
125 | 189 | ||
126 | // HACK: This is a temporary function used by TryGetValue(). | 190 | |
127 | // Due to a bug in mono 1.2.6, delegate blocks cannot contain | 191 | |
128 | // a using block. This has been fixed in SVN, so the next | 192 | /// <summary> |
129 | // mono release should work. | 193 | /// HACK: This is a temporary function used by TryGetValue(). |
194 | /// Due to a bug in mono 1.2.6, delegate blocks cannot contain | ||
195 | /// a using block. This has been fixed in SVN, so the next | ||
196 | /// mono release should work. | ||
197 | /// </summary> | ||
198 | /// <param name="connection"></param> | ||
199 | /// <param name="primaryKey"></param> | ||
200 | /// <param name="result"></param> | ||
201 | /// <param name="success"></param> | ||
130 | private void TryGetConnectionValue(DbConnection connection, TPrimaryKey primaryKey, ref TRowMapper result, ref bool success) | 202 | private void TryGetConnectionValue(DbConnection connection, TPrimaryKey primaryKey, ref TRowMapper result, ref bool success) |
131 | { | 203 | { |
132 | using ( | 204 | using ( |
@@ -148,6 +220,12 @@ namespace OpenSim.Data.Base | |||
148 | } | 220 | } |
149 | } | 221 | } |
150 | 222 | ||
223 | /// <summary> | ||
224 | /// | ||
225 | /// </summary> | ||
226 | /// <param name="primaryKey"></param> | ||
227 | /// <param name="value"></param> | ||
228 | /// <returns></returns> | ||
151 | public bool TryGetValue(TPrimaryKey primaryKey, out TRowMapper value) | 229 | public bool TryGetValue(TPrimaryKey primaryKey, out TRowMapper value) |
152 | { | 230 | { |
153 | TRowMapper result = default(TRowMapper); | 231 | TRowMapper result = default(TRowMapper); |
@@ -163,10 +241,15 @@ namespace OpenSim.Data.Base | |||
163 | return success; | 241 | return success; |
164 | } | 242 | } |
165 | 243 | ||
166 | // HACK: This is a temporary function used by Remove(). | 244 | /// <summary> |
167 | // Due to a bug in mono 1.2.6, delegate blocks cannot contain | 245 | /// HACK: This is a temporary function used by Remove(). |
168 | // a using block. This has been fixed in SVN, so the next | 246 | /// Due to a bug in mono 1.2.6, delegate blocks cannot contain |
169 | // mono release should work. | 247 | /// a using block. This has been fixed in SVN, so the next |
248 | /// mono release should work. | ||
249 | /// </summary> | ||
250 | /// <param name="connection"></param> | ||
251 | /// <param name="id"></param> | ||
252 | /// <param name="deleted"></param> | ||
170 | protected virtual void TryDelete(DbConnection connection, TPrimaryKey id, ref int deleted) | 253 | protected virtual void TryDelete(DbConnection connection, TPrimaryKey id, ref int deleted) |
171 | { | 254 | { |
172 | using ( | 255 | using ( |
@@ -177,6 +260,11 @@ namespace OpenSim.Data.Base | |||
177 | } | 260 | } |
178 | } | 261 | } |
179 | 262 | ||
263 | /// <summary> | ||
264 | /// | ||
265 | /// </summary> | ||
266 | /// <param name="id"></param> | ||
267 | /// <returns></returns> | ||
180 | public virtual bool Remove(TPrimaryKey id) | 268 | public virtual bool Remove(TPrimaryKey id) |
181 | { | 269 | { |
182 | int deleted = 0; | 270 | int deleted = 0; |
@@ -196,6 +284,13 @@ namespace OpenSim.Data.Base | |||
196 | } | 284 | } |
197 | } | 285 | } |
198 | 286 | ||
287 | /// <summary> | ||
288 | /// | ||
289 | /// </summary> | ||
290 | /// <param name="connection"></param> | ||
291 | /// <param name="fieldName"></param> | ||
292 | /// <param name="primaryKey"></param> | ||
293 | /// <returns></returns> | ||
199 | public DbCommand CreateDeleteCommand(DbConnection connection, string fieldName, TPrimaryKey primaryKey) | 294 | public DbCommand CreateDeleteCommand(DbConnection connection, string fieldName, TPrimaryKey primaryKey) |
200 | { | 295 | { |
201 | string table = TableName; | 296 | string table = TableName; |
@@ -213,10 +308,18 @@ namespace OpenSim.Data.Base | |||
213 | return command; | 308 | return command; |
214 | } | 309 | } |
215 | 310 | ||
216 | // HACK: This is a temporary function used by Update(). | 311 | |
217 | // Due to a bug in mono 1.2.6, delegate blocks cannot contain | 312 | |
218 | // a using block. This has been fixed in SVN, so the next | 313 | /// <summary> |
219 | // mono release should work. | 314 | /// HACK: This is a temporary function used by Update(). |
315 | /// Due to a bug in mono 1.2.6, delegate blocks cannot contain | ||
316 | /// a using block. This has been fixed in SVN, so the next | ||
317 | /// mono release should work. | ||
318 | /// </summary> | ||
319 | /// <param name="connection"></param> | ||
320 | /// <param name="primaryKey"></param> | ||
321 | /// <param name="value"></param> | ||
322 | /// <param name="updated"></param> | ||
220 | protected void TryUpdate(DbConnection connection, TPrimaryKey primaryKey, TRowMapper value, ref int updated) | 323 | protected void TryUpdate(DbConnection connection, TPrimaryKey primaryKey, TRowMapper value, ref int updated) |
221 | { | 324 | { |
222 | using (DbCommand command = CreateUpdateCommand(connection, value, primaryKey)) | 325 | using (DbCommand command = CreateUpdateCommand(connection, value, primaryKey)) |
@@ -225,6 +328,12 @@ namespace OpenSim.Data.Base | |||
225 | } | 328 | } |
226 | } | 329 | } |
227 | 330 | ||
331 | /// <summary> | ||
332 | /// | ||
333 | /// </summary> | ||
334 | /// <param name="primaryKey"></param> | ||
335 | /// <param name="value"></param> | ||
336 | /// <returns></returns> | ||
228 | public virtual bool Update(TPrimaryKey primaryKey, TRowMapper value) | 337 | public virtual bool Update(TPrimaryKey primaryKey, TRowMapper value) |
229 | { | 338 | { |
230 | int updated = 0; | 339 | int updated = 0; |
@@ -244,10 +353,15 @@ namespace OpenSim.Data.Base | |||
244 | } | 353 | } |
245 | } | 354 | } |
246 | 355 | ||
247 | // HACK: This is a temporary function used by Add(). | 356 | /// <summary> |
248 | // Due to a bug in mono 1.2.6, delegate blocks cannot contain | 357 | /// HACK: This is a temporary function used by Add(). |
249 | // a using block. This has been fixed in SVN, so the next | 358 | /// Due to a bug in mono 1.2.6, delegate blocks cannot contain |
250 | // mono release should work. | 359 | /// a using block. This has been fixed in SVN, so the next |
360 | /// mono release should work. | ||
361 | /// </summary> | ||
362 | /// <param name="connection"></param> | ||
363 | /// <param name="value"></param> | ||
364 | /// <param name="added"></param> | ||
251 | protected void TryAdd(DbConnection connection, TRowMapper value, ref int added) | 365 | protected void TryAdd(DbConnection connection, TRowMapper value, ref int added) |
252 | { | 366 | { |
253 | using (DbCommand command = CreateInsertCommand(connection, value)) | 367 | using (DbCommand command = CreateInsertCommand(connection, value)) |
@@ -256,6 +370,11 @@ namespace OpenSim.Data.Base | |||
256 | } | 370 | } |
257 | } | 371 | } |
258 | 372 | ||
373 | /// <summary> | ||
374 | /// | ||
375 | /// </summary> | ||
376 | /// <param name="value"></param> | ||
377 | /// <returns></returns> | ||
259 | public virtual bool Add(TRowMapper value) | 378 | public virtual bool Add(TRowMapper value) |
260 | { | 379 | { |
261 | int added = 0; | 380 | int added = 0; |