aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/ThirdParty/TribalMedia/TribalMedia.Framework.Data/BaseTableMapper.cs
diff options
context:
space:
mode:
authorlbsa712008-01-15 20:07:02 +0000
committerlbsa712008-01-15 20:07:02 +0000
commitf5103b98be60cc8b1a69288328cdc20f78857835 (patch)
treeb50381385478f57a05ed9fef7c5176397d76d2f2 /ThirdParty/TribalMedia/TribalMedia.Framework.Data/BaseTableMapper.cs
parent* Added some comments to the linkset positioning code (diff)
downloadopensim-SC-f5103b98be60cc8b1a69288328cdc20f78857835.zip
opensim-SC-f5103b98be60cc8b1a69288328cdc20f78857835.tar.gz
opensim-SC-f5103b98be60cc8b1a69288328cdc20f78857835.tar.bz2
opensim-SC-f5103b98be60cc8b1a69288328cdc20f78857835.tar.xz
* Renamed a bunch of Data baseclasses for clarity and readability
(Slowly getting there)
Diffstat (limited to '')
-rw-r--r--ThirdParty/TribalMedia/TribalMedia.Framework.Data/BaseTableMapper.cs (renamed from ThirdParty/TribalMedia/TribalMedia.Framework.Data/ObjectTableMapper.cs)94
1 files changed, 90 insertions, 4 deletions
diff --git a/ThirdParty/TribalMedia/TribalMedia.Framework.Data/ObjectTableMapper.cs b/ThirdParty/TribalMedia/TribalMedia.Framework.Data/BaseTableMapper.cs
index f2ee4f8..e4fe0fd 100644
--- a/ThirdParty/TribalMedia/TribalMedia.Framework.Data/ObjectTableMapper.cs
+++ b/ThirdParty/TribalMedia/TribalMedia.Framework.Data/BaseTableMapper.cs
@@ -27,12 +27,98 @@
27using System; 27using System;
28using System.Data; 28using System.Data;
29using System.Data.Common; 29using System.Data.Common;
30using TribalMedia.Framework.Data;
30 31
31namespace TribalMedia.Framework.Data 32namespace TribalMedia.Framework.Data
32{ 33{
33 public abstract class ObjectTableMapper<TRowMapper, TPrimaryKey> : TableMapper 34 public abstract class BaseTableMapper
34 { 35 {
35 public ObjectTableMapper(DatabaseMapper database, string tableName) 36 private readonly BaseDatabaseConnector m_database;
37 private readonly object m_syncRoot = new object();
38
39 protected void WithConnection(Action<DbConnection> action)
40 {
41 lock (m_syncRoot)
42 {
43 DbConnection m_connection = m_database.GetNewConnection();
44
45 if (m_connection.State != ConnectionState.Open)
46 {
47 m_connection.Open();
48 }
49
50 action(m_connection);
51
52 if (m_connection.State == ConnectionState.Open)
53 {
54 m_connection.Close();
55 }
56 }
57 }
58
59 private readonly string m_tableName;
60 public string TableName
61 {
62 get { return m_tableName; }
63 }
64
65 protected Schema m_schema;
66 public Schema Schema
67 {
68 get { return m_schema; }
69 }
70
71 protected BaseFieldMapper m_keyFieldMapper;
72 public BaseFieldMapper KeyFieldMapper
73 {
74 get { return m_keyFieldMapper; }
75 }
76
77 public BaseTableMapper(BaseDatabaseConnector database, string tableName)
78 {
79 m_database = database;
80 m_tableName = tableName.ToLower(); // Stupid MySQL hack.
81 }
82
83 public string CreateParamName(string fieldName)
84 {
85 return m_database.CreateParamName(fieldName);
86 }
87
88 protected DbCommand CreateSelectCommand(DbConnection connection, string fieldName, object primaryKey)
89 {
90 return m_database.CreateSelectCommand(this, connection, fieldName, primaryKey);
91 }
92
93 public string CreateCondition(DbCommand command, string fieldName, object key)
94 {
95 return m_database.CreateCondition(this, command, fieldName, key);
96 }
97
98 public DbCommand CreateInsertCommand(DbConnection connection, object obj)
99 {
100 return m_database.CreateInsertCommand(this, connection, obj);
101 }
102
103 public DbCommand CreateUpdateCommand(DbConnection connection, object rowMapper, object primaryKey)
104 {
105 return m_database.CreateUpdateCommand(this, connection, rowMapper, primaryKey);
106 }
107
108 public object ConvertToDbType(object value)
109 {
110 return m_database.ConvertToDbType(value);
111 }
112
113 protected virtual DataReader CreateReader(IDataReader reader)
114 {
115 return new DataReader(reader);
116 }
117 }
118
119 public abstract class BaseTableMapper<TRowMapper, TPrimaryKey> : BaseTableMapper
120 {
121 public BaseTableMapper(BaseDatabaseConnector database, string tableName)
36 : base(database, tableName) 122 : base(database, tableName)
37 { 123 {
38 } 124 }
@@ -52,7 +138,7 @@ namespace TribalMedia.Framework.Data
52 { 138 {
53 if (reader.Read()) 139 if (reader.Read())
54 { 140 {
55 result = FromReader( CreateReader(reader)); 141 result = FromReader(CreateReader(reader));
56 success = true; 142 success = true;
57 } 143 }
58 else 144 else
@@ -67,7 +153,7 @@ namespace TribalMedia.Framework.Data
67 153
68 return success; 154 return success;
69 } 155 }
70 156
71 public virtual bool Remove(TPrimaryKey id) 157 public virtual bool Remove(TPrimaryKey id)
72 { 158 {
73 int deleted = 0; 159 int deleted = 0;