diff options
author | lbsa71 | 2008-01-15 20:07:02 +0000 |
---|---|---|
committer | lbsa71 | 2008-01-15 20:07:02 +0000 |
commit | f5103b98be60cc8b1a69288328cdc20f78857835 (patch) | |
tree | b50381385478f57a05ed9fef7c5176397d76d2f2 /ThirdParty | |
parent | * Added some comments to the linkset positioning code (diff) | |
download | opensim-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 'ThirdParty')
-rw-r--r-- | ThirdParty/TribalMedia/TribalMedia.Framework.Data/BaseDataReader.cs (renamed from ThirdParty/TribalMedia/TribalMedia.Framework.Data/DataReader.cs) | 10 | ||||
-rw-r--r-- | ThirdParty/TribalMedia/TribalMedia.Framework.Data/BaseDatabaseConnector.cs (renamed from ThirdParty/TribalMedia/TribalMedia.Framework.Data/DatabaseMapper.cs) | 16 | ||||
-rw-r--r-- | ThirdParty/TribalMedia/TribalMedia.Framework.Data/BaseFieldMapper.cs (renamed from ThirdParty/TribalMedia/TribalMedia.Framework.Data/FieldMapper.cs) | 140 | ||||
-rw-r--r-- | ThirdParty/TribalMedia/TribalMedia.Framework.Data/BaseRowMapper.cs (renamed from ThirdParty/TribalMedia/TribalMedia.Framework.Data/RowMapper.cs) | 4 | ||||
-rw-r--r-- | ThirdParty/TribalMedia/TribalMedia.Framework.Data/BaseSchema.cs (renamed from ThirdParty/TribalMedia/TribalMedia.Framework.Data/Schema.cs) | 49 | ||||
-rw-r--r-- | ThirdParty/TribalMedia/TribalMedia.Framework.Data/BaseTableMapper.cs (renamed from ThirdParty/TribalMedia/TribalMedia.Framework.Data/ObjectTableMapper.cs) | 94 | ||||
-rw-r--r-- | ThirdParty/TribalMedia/TribalMedia.Framework.Data/TableMapper.cs | 118 | ||||
-rw-r--r-- | ThirdParty/TribalMedia/TribalMedia.Framework.Data/TribalMedia.Framework.Data.snk | bin | 0 -> 596 bytes |
8 files changed, 199 insertions, 232 deletions
diff --git a/ThirdParty/TribalMedia/TribalMedia.Framework.Data/DataReader.cs b/ThirdParty/TribalMedia/TribalMedia.Framework.Data/BaseDataReader.cs index 4792e9e..34f894c 100644 --- a/ThirdParty/TribalMedia/TribalMedia.Framework.Data/DataReader.cs +++ b/ThirdParty/TribalMedia/TribalMedia.Framework.Data/BaseDataReader.cs | |||
@@ -46,19 +46,19 @@ namespace TribalMedia.Framework.Data | |||
46 | 46 | ||
47 | public ushort GetUShort(string name) | 47 | public ushort GetUShort(string name) |
48 | { | 48 | { |
49 | return (ushort) m_source.GetInt32(m_source.GetOrdinal(name)); | 49 | return (ushort)m_source.GetInt32(m_source.GetOrdinal(name)); |
50 | } | 50 | } |
51 | 51 | ||
52 | public byte GetByte(string name) | 52 | public byte GetByte(string name) |
53 | { | 53 | { |
54 | int ordinal = m_source.GetOrdinal(name); | 54 | int ordinal = m_source.GetOrdinal(name); |
55 | byte value = (byte) m_source.GetInt16(ordinal); | 55 | byte value = (byte)m_source.GetInt16(ordinal); |
56 | return value; | 56 | return value; |
57 | } | 57 | } |
58 | 58 | ||
59 | public sbyte GetSByte(string name) | 59 | public sbyte GetSByte(string name) |
60 | { | 60 | { |
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 float GetFloat(string name) | 64 | public float GetFloat(string name) |
@@ -84,7 +84,7 @@ namespace TribalMedia.Framework.Data | |||
84 | int bytesRead; | 84 | int bytesRead; |
85 | do | 85 | do |
86 | { | 86 | { |
87 | bytesRead = (int) m_source.GetBytes(ordinal, totalRead, buffer, 0, buffer.Length); | 87 | bytesRead = (int)m_source.GetBytes(ordinal, totalRead, buffer, 0, buffer.Length); |
88 | totalRead += bytesRead; | 88 | totalRead += bytesRead; |
89 | 89 | ||
90 | memStream.Write(buffer, 0, bytesRead); | 90 | memStream.Write(buffer, 0, bytesRead); |
@@ -103,7 +103,7 @@ namespace TribalMedia.Framework.Data | |||
103 | return null; | 103 | return null; |
104 | } | 104 | } |
105 | 105 | ||
106 | return (string) value; | 106 | return (string)value; |
107 | } | 107 | } |
108 | 108 | ||
109 | public bool Read() | 109 | public bool Read() |
diff --git a/ThirdParty/TribalMedia/TribalMedia.Framework.Data/DatabaseMapper.cs b/ThirdParty/TribalMedia/TribalMedia.Framework.Data/BaseDatabaseConnector.cs index 63e59aa..ae70fc1 100644 --- a/ThirdParty/TribalMedia/TribalMedia.Framework.Data/DatabaseMapper.cs +++ b/ThirdParty/TribalMedia/TribalMedia.Framework.Data/BaseDatabaseConnector.cs | |||
@@ -31,11 +31,11 @@ using System.Data.Common; | |||
31 | 31 | ||
32 | namespace TribalMedia.Framework.Data | 32 | namespace TribalMedia.Framework.Data |
33 | { | 33 | { |
34 | public abstract class DatabaseMapper | 34 | public abstract class BaseDatabaseConnector |
35 | { | 35 | { |
36 | protected string m_connectionString; | 36 | protected string m_connectionString; |
37 | 37 | ||
38 | public DatabaseMapper(string connectionString) | 38 | public BaseDatabaseConnector(string connectionString) |
39 | { | 39 | { |
40 | m_connectionString = connectionString; | 40 | m_connectionString = connectionString; |
41 | } | 41 | } |
@@ -43,7 +43,7 @@ namespace TribalMedia.Framework.Data | |||
43 | public abstract DbConnection GetNewConnection(); | 43 | public abstract DbConnection GetNewConnection(); |
44 | public abstract string CreateParamName(string fieldName); | 44 | public abstract string CreateParamName(string fieldName); |
45 | 45 | ||
46 | public DbCommand CreateSelectCommand(TableMapper mapper, DbConnection connection, string fieldName, object key) | 46 | public DbCommand CreateSelectCommand(BaseTableMapper mapper, DbConnection connection, string fieldName, object key) |
47 | { | 47 | { |
48 | string table = mapper.TableName; | 48 | string table = mapper.TableName; |
49 | 49 | ||
@@ -60,7 +60,7 @@ namespace TribalMedia.Framework.Data | |||
60 | return command; | 60 | return command; |
61 | } | 61 | } |
62 | 62 | ||
63 | public string CreateCondition(TableMapper mapper, DbCommand command, string fieldName, object key) | 63 | public string CreateCondition(BaseTableMapper mapper, DbCommand command, string fieldName, object key) |
64 | { | 64 | { |
65 | string keyFieldParamName = mapper.CreateParamName(fieldName); | 65 | string keyFieldParamName = mapper.CreateParamName(fieldName); |
66 | 66 | ||
@@ -72,7 +72,7 @@ namespace TribalMedia.Framework.Data | |||
72 | return String.Format("{0}={1}", fieldName, keyFieldParamName); | 72 | return String.Format("{0}={1}", fieldName, keyFieldParamName); |
73 | } | 73 | } |
74 | 74 | ||
75 | public DbCommand CreateUpdateCommand(TableMapper mapper, DbConnection connection, object rowMapper, object primaryKey) | 75 | public DbCommand CreateUpdateCommand(BaseTableMapper mapper, DbConnection connection, object rowMapper, object primaryKey) |
76 | { | 76 | { |
77 | string table = mapper.TableName; | 77 | string table = mapper.TableName; |
78 | 78 | ||
@@ -80,7 +80,7 @@ namespace TribalMedia.Framework.Data | |||
80 | 80 | ||
81 | DbCommand command = connection.CreateCommand(); | 81 | DbCommand command = connection.CreateCommand(); |
82 | 82 | ||
83 | foreach (FieldMapper fieldMapper in mapper.Schema.Fields.Values) | 83 | foreach (BaseFieldMapper fieldMapper in mapper.Schema.Fields.Values) |
84 | { | 84 | { |
85 | if (fieldMapper != mapper.KeyFieldMapper) | 85 | if (fieldMapper != mapper.KeyFieldMapper) |
86 | { | 86 | { |
@@ -104,7 +104,7 @@ namespace TribalMedia.Framework.Data | |||
104 | return command; | 104 | return command; |
105 | } | 105 | } |
106 | 106 | ||
107 | public DbCommand CreateInsertCommand(TableMapper mapper, DbConnection connection, object obj) | 107 | public DbCommand CreateInsertCommand(BaseTableMapper mapper, DbConnection connection, object obj) |
108 | { | 108 | { |
109 | string table = mapper.TableName; | 109 | string table = mapper.TableName; |
110 | 110 | ||
@@ -112,7 +112,7 @@ namespace TribalMedia.Framework.Data | |||
112 | 112 | ||
113 | DbCommand command = connection.CreateCommand(); | 113 | DbCommand command = connection.CreateCommand(); |
114 | 114 | ||
115 | foreach (FieldMapper fieldMapper in mapper.Schema.Fields.Values) | 115 | foreach (BaseFieldMapper fieldMapper in mapper.Schema.Fields.Values) |
116 | { | 116 | { |
117 | fieldMapper.ExpandField(obj, command, fieldNames); | 117 | fieldMapper.ExpandField(obj, command, fieldNames); |
118 | } | 118 | } |
diff --git a/ThirdParty/TribalMedia/TribalMedia.Framework.Data/FieldMapper.cs b/ThirdParty/TribalMedia/TribalMedia.Framework.Data/BaseFieldMapper.cs index 89bc0f0..20d8cf1 100644 --- a/ThirdParty/TribalMedia/TribalMedia.Framework.Data/FieldMapper.cs +++ b/ThirdParty/TribalMedia/TribalMedia.Framework.Data/BaseFieldMapper.cs | |||
@@ -30,17 +30,15 @@ using System.Data.Common; | |||
30 | 30 | ||
31 | namespace TribalMedia.Framework.Data | 31 | namespace TribalMedia.Framework.Data |
32 | { | 32 | { |
33 | public delegate TField RowMapperGetAccessor<TRowMapper, TField>(TRowMapper rowMapper); | 33 | //public delegate TField RowMapperGetAccessor<TRowMapper, TField>(TRowMapper rowMapper); |
34 | 34 | //public delegate void RowMapperSetAccessor<TRowMapper, TField>(TRowMapper rowMapper, TField value); | |
35 | public delegate void RowMapperSetAccessor<TRowMapper, TField>(TRowMapper rowMapper, TField value); | ||
36 | 35 | ||
37 | public delegate TField ObjectGetAccessor<TObj, TField>(TObj obj); | 36 | public delegate TField ObjectGetAccessor<TObj, TField>(TObj obj); |
38 | |||
39 | public delegate void ObjectSetAccessor<TObj, TField>(TObj obj, TField value); | 37 | public delegate void ObjectSetAccessor<TObj, TField>(TObj obj, TField value); |
40 | 38 | ||
41 | public abstract class FieldMapper | 39 | public abstract class BaseFieldMapper |
42 | { | 40 | { |
43 | private readonly TableMapper m_tableMapper; | 41 | private readonly BaseTableMapper m_tableMapper; |
44 | private readonly string m_fieldName; | 42 | private readonly string m_fieldName; |
45 | 43 | ||
46 | public string FieldName | 44 | public string FieldName |
@@ -57,7 +55,7 @@ namespace TribalMedia.Framework.Data | |||
57 | 55 | ||
58 | public abstract object GetParamValue(object obj); | 56 | public abstract object GetParamValue(object obj); |
59 | 57 | ||
60 | public FieldMapper( TableMapper tableMapper, string fieldName, Type valueType) | 58 | public BaseFieldMapper(BaseTableMapper tableMapper, string fieldName, Type valueType) |
61 | { | 59 | { |
62 | m_fieldName = fieldName; | 60 | m_fieldName = fieldName; |
63 | m_valueType = valueType; | 61 | m_valueType = valueType; |
@@ -94,32 +92,32 @@ namespace TribalMedia.Framework.Data | |||
94 | { | 92 | { |
95 | value = reader.GetGuid(m_fieldName); | 93 | value = reader.GetGuid(m_fieldName); |
96 | } | 94 | } |
97 | else if (ValueType == typeof (bool)) | 95 | else if (ValueType == typeof(bool)) |
98 | { | 96 | { |
99 | uint boolVal = reader.GetUShort(m_fieldName); | 97 | uint boolVal = reader.GetUShort(m_fieldName); |
100 | value = (boolVal == 1); | 98 | value = (boolVal == 1); |
101 | } | 99 | } |
102 | else | ||
103 | if (ValueType == typeof (byte)) | ||
104 | { | ||
105 | value = reader.GetByte(m_fieldName); | ||
106 | } | ||
107 | else if (ValueType == typeof (sbyte)) | ||
108 | { | ||
109 | value = reader.GetSByte(m_fieldName); | ||
110 | } | ||
111 | else if (ValueType == typeof (ushort)) | ||
112 | { | ||
113 | value = reader.GetUShort(m_fieldName); | ||
114 | } | ||
115 | else if (ValueType == typeof (byte[])) | ||
116 | { | ||
117 | value = reader.GetBytes(m_fieldName); | ||
118 | } | ||
119 | else | 100 | else |
120 | { | 101 | if (ValueType == typeof(byte)) |
121 | value = reader.Get(m_fieldName); | 102 | { |
122 | } | 103 | value = reader.GetByte(m_fieldName); |
104 | } | ||
105 | else if (ValueType == typeof(sbyte)) | ||
106 | { | ||
107 | value = reader.GetSByte(m_fieldName); | ||
108 | } | ||
109 | else if (ValueType == typeof(ushort)) | ||
110 | { | ||
111 | value = reader.GetUShort(m_fieldName); | ||
112 | } | ||
113 | else if (ValueType == typeof(byte[])) | ||
114 | { | ||
115 | value = reader.GetBytes(m_fieldName); | ||
116 | } | ||
117 | else | ||
118 | { | ||
119 | value = reader.Get(m_fieldName); | ||
120 | } | ||
123 | 121 | ||
124 | if (value is DBNull) | 122 | if (value is DBNull) |
125 | { | 123 | { |
@@ -130,51 +128,51 @@ namespace TribalMedia.Framework.Data | |||
130 | } | 128 | } |
131 | } | 129 | } |
132 | 130 | ||
133 | public class RowMapperField<TRowMapper, TField> : FieldMapper | 131 | //public class RowMapperField<TRowMapper, TField> : FieldMapper |
134 | where TRowMapper : RowMapper | 132 | // where TRowMapper : RowMapper |
135 | { | 133 | //{ |
136 | private readonly RowMapperGetAccessor<TRowMapper, TField> m_fieldGetAccessor; | 134 | // private readonly RowMapperGetAccessor<TRowMapper, TField> m_fieldGetAccessor; |
137 | private readonly RowMapperSetAccessor<TRowMapper, TField> m_fieldSetAccessor; | 135 | // private readonly RowMapperSetAccessor<TRowMapper, TField> m_fieldSetAccessor; |
138 | 136 | ||
139 | public override object GetParamValue(object obj) | 137 | // public override object GetParamValue(object obj) |
140 | { | 138 | // { |
141 | return m_fieldGetAccessor((TRowMapper) obj); | 139 | // return m_fieldGetAccessor((TRowMapper) obj); |
142 | } | 140 | // } |
143 | 141 | ||
144 | public override void SetPropertyFromReader(object mapper, DataReader reader) | 142 | // public override void SetPropertyFromReader(object mapper, DataReader reader) |
145 | { | 143 | // { |
146 | object value; | 144 | // object value; |
147 | 145 | ||
148 | value = GetValue(reader); | 146 | // value = GetValue(reader); |
149 | 147 | ||
150 | if (value == null) | 148 | // if (value == null) |
151 | { | 149 | // { |
152 | m_fieldSetAccessor((TRowMapper) mapper, default(TField)); | 150 | // m_fieldSetAccessor((TRowMapper) mapper, default(TField)); |
153 | } | 151 | // } |
154 | else | 152 | // else |
155 | { | 153 | // { |
156 | m_fieldSetAccessor((TRowMapper) mapper, (TField) value); | 154 | // m_fieldSetAccessor((TRowMapper) mapper, (TField) value); |
157 | } | 155 | // } |
158 | } | 156 | // } |
159 | 157 | ||
160 | 158 | ||
161 | public RowMapperField(TableMapper tableMapper, string fieldName, RowMapperGetAccessor<TRowMapper, TField> rowMapperGetAccessor, | 159 | // public RowMapperField(TableMapper tableMapper, string fieldName, RowMapperGetAccessor<TRowMapper, TField> rowMapperGetAccessor, |
162 | RowMapperSetAccessor<TRowMapper, TField> rowMapperSetAccessor) | 160 | // RowMapperSetAccessor<TRowMapper, TField> rowMapperSetAccessor) |
163 | : base(tableMapper, fieldName, typeof(TField)) | 161 | // : base(tableMapper, fieldName, typeof(TField)) |
164 | { | 162 | // { |
165 | m_fieldGetAccessor = rowMapperGetAccessor; | 163 | // m_fieldGetAccessor = rowMapperGetAccessor; |
166 | m_fieldSetAccessor = rowMapperSetAccessor; | 164 | // m_fieldSetAccessor = rowMapperSetAccessor; |
167 | } | 165 | // } |
168 | } | 166 | //} |
169 | 167 | ||
170 | public class ObjectField<TObject, TField> : FieldMapper | 168 | public class ObjectField<TObject, TField> : BaseFieldMapper |
171 | { | 169 | { |
172 | private readonly ObjectGetAccessor<TObject, TField> m_fieldGetAccessor; | 170 | private readonly ObjectGetAccessor<TObject, TField> m_fieldGetAccessor; |
173 | private readonly ObjectSetAccessor<TObject, TField> m_fieldSetAccessor; | 171 | private readonly ObjectSetAccessor<TObject, TField> m_fieldSetAccessor; |
174 | 172 | ||
175 | public override object GetParamValue(object obj) | 173 | public override object GetParamValue(object obj) |
176 | { | 174 | { |
177 | return m_fieldGetAccessor((TObject) obj); | 175 | return m_fieldGetAccessor((TObject)obj); |
178 | } | 176 | } |
179 | 177 | ||
180 | public override void SetPropertyFromReader(object obj, DataReader reader) | 178 | public override void SetPropertyFromReader(object obj, DataReader reader) |
@@ -185,18 +183,18 @@ namespace TribalMedia.Framework.Data | |||
185 | 183 | ||
186 | if (value == null) | 184 | if (value == null) |
187 | { | 185 | { |
188 | m_fieldSetAccessor((TObject) obj, default(TField)); | 186 | m_fieldSetAccessor((TObject)obj, default(TField)); |
189 | } | 187 | } |
190 | else | 188 | else |
191 | { | 189 | { |
192 | m_fieldSetAccessor((TObject) obj, (TField) value); | 190 | m_fieldSetAccessor((TObject)obj, (TField)value); |
193 | } | 191 | } |
194 | } | 192 | } |
195 | 193 | ||
196 | 194 | ||
197 | public ObjectField(TableMapper tableMapper, string fieldName, ObjectGetAccessor<TObject, TField> rowMapperGetAccessor, | 195 | public ObjectField(BaseTableMapper tableMapper, string fieldName, ObjectGetAccessor<TObject, TField> rowMapperGetAccessor, |
198 | ObjectSetAccessor<TObject, TField> rowMapperSetAccessor) | 196 | ObjectSetAccessor<TObject, TField> rowMapperSetAccessor) |
199 | : base(tableMapper, fieldName, typeof (TField)) | 197 | : base(tableMapper, fieldName, typeof(TField)) |
200 | { | 198 | { |
201 | m_fieldGetAccessor = rowMapperGetAccessor; | 199 | m_fieldGetAccessor = rowMapperGetAccessor; |
202 | m_fieldSetAccessor = rowMapperSetAccessor; | 200 | m_fieldSetAccessor = rowMapperSetAccessor; |
diff --git a/ThirdParty/TribalMedia/TribalMedia.Framework.Data/RowMapper.cs b/ThirdParty/TribalMedia/TribalMedia.Framework.Data/BaseRowMapper.cs index 2771ec9..2ab8daf 100644 --- a/ThirdParty/TribalMedia/TribalMedia.Framework.Data/RowMapper.cs +++ b/ThirdParty/TribalMedia/TribalMedia.Framework.Data/BaseRowMapper.cs | |||
@@ -51,7 +51,7 @@ namespace TribalMedia.Framework.Data | |||
51 | 51 | ||
52 | public override void FillObject(DataReader reader) | 52 | public override void FillObject(DataReader reader) |
53 | { | 53 | { |
54 | foreach (FieldMapper fieldMapper in m_schema.Fields.Values) | 54 | foreach (BaseFieldMapper fieldMapper in m_schema.Fields.Values) |
55 | { | 55 | { |
56 | fieldMapper.SetPropertyFromReader(m_obj, reader); | 56 | fieldMapper.SetPropertyFromReader(m_obj, reader); |
57 | } | 57 | } |
@@ -76,7 +76,7 @@ namespace TribalMedia.Framework.Data | |||
76 | 76 | ||
77 | public override void FillObject(DataReader reader) | 77 | public override void FillObject(DataReader reader) |
78 | { | 78 | { |
79 | foreach (FieldMapper fieldMapper in m_schema.Fields.Values) | 79 | foreach (BaseFieldMapper fieldMapper in m_schema.Fields.Values) |
80 | { | 80 | { |
81 | fieldMapper.SetPropertyFromReader(this, reader); | 81 | fieldMapper.SetPropertyFromReader(this, reader); |
82 | } | 82 | } |
diff --git a/ThirdParty/TribalMedia/TribalMedia.Framework.Data/Schema.cs b/ThirdParty/TribalMedia/TribalMedia.Framework.Data/BaseSchema.cs index c6bf5d0..fc59f3b 100644 --- a/ThirdParty/TribalMedia/TribalMedia.Framework.Data/Schema.cs +++ b/ThirdParty/TribalMedia/TribalMedia.Framework.Data/BaseSchema.cs | |||
@@ -31,24 +31,25 @@ namespace TribalMedia.Framework.Data | |||
31 | { | 31 | { |
32 | public class Schema | 32 | public class Schema |
33 | { | 33 | { |
34 | protected TableMapper m_tableMapper; | 34 | protected BaseTableMapper m_tableMapper; |
35 | protected Dictionary<string, FieldMapper> m_mappings; | 35 | protected Dictionary<string, BaseFieldMapper> m_mappings; |
36 | 36 | ||
37 | public Dictionary<string, FieldMapper> Fields | 37 | public Dictionary<string, BaseFieldMapper> Fields |
38 | { | 38 | { |
39 | get { return m_mappings; } | 39 | get { return m_mappings; } |
40 | } | 40 | } |
41 | 41 | ||
42 | public Schema(TableMapper tableMapper) | 42 | public Schema(BaseTableMapper tableMapper) |
43 | { | 43 | { |
44 | m_mappings = new Dictionary<string, FieldMapper>(); | 44 | m_mappings = new Dictionary<string, BaseFieldMapper>(); |
45 | m_tableMapper = tableMapper; | 45 | m_tableMapper = tableMapper; |
46 | } | 46 | } |
47 | } | 47 | } |
48 | 48 | ||
49 | public class ObjectSchema<TObj> : Schema | 49 | public class ObjectSchema<TObj> : Schema |
50 | { | 50 | { |
51 | public ObjectSchema(TableMapper tableMapper) : base(tableMapper) | 51 | public ObjectSchema(BaseTableMapper tableMapper) |
52 | : base(tableMapper) | ||
52 | { | 53 | { |
53 | } | 54 | } |
54 | 55 | ||
@@ -65,25 +66,25 @@ namespace TribalMedia.Framework.Data | |||
65 | } | 66 | } |
66 | } | 67 | } |
67 | 68 | ||
68 | public class RowMapperSchema<TRowMapper> : Schema | 69 | //public class RowMapperSchema<TRowMapper> : Schema |
69 | where TRowMapper : RowMapper | 70 | // where TRowMapper : RowMapper |
70 | { | 71 | //{ |
71 | public RowMapperSchema(TableMapper tableMapper) : base(tableMapper) | 72 | // public RowMapperSchema(TableMapper tableMapper) : base(tableMapper) |
72 | { | 73 | // { |
73 | } | 74 | // } |
74 | 75 | ||
75 | public RowMapperField<TRowMapper, TField> AddMapping<TField>(string fieldName, | 76 | // public RowMapperField<TRowMapper, TField> AddMapping<TField>(string fieldName, |
76 | RowMapperGetAccessor<TRowMapper, TField> | 77 | // RowMapperGetAccessor<TRowMapper, TField> |
77 | rowMapperGetAccessor, | 78 | // rowMapperGetAccessor, |
78 | RowMapperSetAccessor<TRowMapper, TField> | 79 | // RowMapperSetAccessor<TRowMapper, TField> |
79 | rowMapperSetAccessor) | 80 | // rowMapperSetAccessor) |
80 | { | 81 | // { |
81 | RowMapperField<TRowMapper, TField> rowMapperField = | 82 | // RowMapperField<TRowMapper, TField> rowMapperField = |
82 | new RowMapperField<TRowMapper, TField>(m_tableMapper, fieldName, rowMapperGetAccessor, rowMapperSetAccessor); | 83 | // new RowMapperField<TRowMapper, TField>(m_tableMapper, fieldName, rowMapperGetAccessor, rowMapperSetAccessor); |
83 | 84 | ||
84 | m_mappings.Add(fieldName, rowMapperField); | 85 | // m_mappings.Add(fieldName, rowMapperField); |
85 | 86 | ||
86 | return rowMapperField; | 87 | // return rowMapperField; |
87 | } | 88 | // } |
88 | } | 89 | //} |
89 | } \ No newline at end of file | 90 | } \ No newline at end of file |
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 @@ | |||
27 | using System; | 27 | using System; |
28 | using System.Data; | 28 | using System.Data; |
29 | using System.Data.Common; | 29 | using System.Data.Common; |
30 | using TribalMedia.Framework.Data; | ||
30 | 31 | ||
31 | namespace TribalMedia.Framework.Data | 32 | namespace 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; |
diff --git a/ThirdParty/TribalMedia/TribalMedia.Framework.Data/TableMapper.cs b/ThirdParty/TribalMedia/TribalMedia.Framework.Data/TableMapper.cs deleted file mode 100644 index a2b0aa1..0000000 --- a/ThirdParty/TribalMedia/TribalMedia.Framework.Data/TableMapper.cs +++ /dev/null | |||
@@ -1,118 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Tribal Media AB, http://tribalmedia.se/ | ||
3 | * | ||
4 | * Redistribution and use in source and binary forms, with or without | ||
5 | * modification, are permitted provided that the following conditions are met: | ||
6 | * * Redistributions of source code must retain the above copyright | ||
7 | * notice, this list of conditions and the following disclaimer. | ||
8 | * * Redistributions in binary form must reproduce the above copyright | ||
9 | * notice, this list of conditions and the following disclaimer in the | ||
10 | * documentation and/or other materials provided with the distribution. | ||
11 | * * The name of Tribal Media AB may not be used to endorse or promote products | ||
12 | * derived from this software without specific prior written permission. | ||
13 | * | ||
14 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
15 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
16 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
17 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
18 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
19 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
20 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
21 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
23 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
24 | * | ||
25 | */ | ||
26 | |||
27 | using System; | ||
28 | using System.Data; | ||
29 | using System.Data.Common; | ||
30 | using TribalMedia.Framework.Data; | ||
31 | |||
32 | namespace TribalMedia.Framework.Data | ||
33 | { | ||
34 | public abstract class TableMapper | ||
35 | { | ||
36 | private readonly DatabaseMapper 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 FieldMapper m_keyFieldMapper; | ||
72 | public FieldMapper KeyFieldMapper | ||
73 | { | ||
74 | get { return m_keyFieldMapper; } | ||
75 | } | ||
76 | |||
77 | public TableMapper(DatabaseMapper 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 | } \ No newline at end of file | ||
diff --git a/ThirdParty/TribalMedia/TribalMedia.Framework.Data/TribalMedia.Framework.Data.snk b/ThirdParty/TribalMedia/TribalMedia.Framework.Data/TribalMedia.Framework.Data.snk new file mode 100644 index 0000000..fc71027 --- /dev/null +++ b/ThirdParty/TribalMedia/TribalMedia.Framework.Data/TribalMedia.Framework.Data.snk | |||
Binary files differ | |||