diff options
Diffstat (limited to 'OpenSim/Data/Base')
-rw-r--r-- | OpenSim/Data/Base/BaseDataReader.cs | 205 | ||||
-rw-r--r-- | OpenSim/Data/Base/BaseDatabaseConnector.cs | 185 | ||||
-rw-r--r-- | OpenSim/Data/Base/BaseFieldMapper.cs | 214 | ||||
-rw-r--r-- | OpenSim/Data/Base/BaseRowMapper.cs | 78 | ||||
-rw-r--r-- | OpenSim/Data/Base/BaseSchema.cs | 94 | ||||
-rw-r--r-- | OpenSim/Data/Base/BaseTableMapper.cs | 399 | ||||
-rw-r--r-- | OpenSim/Data/Base/OpenSim.Data.Base.snk | bin | 596 -> 0 bytes | |||
-rw-r--r-- | OpenSim/Data/Base/Properties/AssemblyInfo.cs | 67 |
8 files changed, 0 insertions, 1242 deletions
diff --git a/OpenSim/Data/Base/BaseDataReader.cs b/OpenSim/Data/Base/BaseDataReader.cs deleted file mode 100644 index 23f03e5..0000000 --- a/OpenSim/Data/Base/BaseDataReader.cs +++ /dev/null | |||
@@ -1,205 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Data; | ||
30 | using System.IO; | ||
31 | |||
32 | namespace OpenSim.Data.Base | ||
33 | { | ||
34 | /// <summary> | ||
35 | /// | ||
36 | /// </summary> | ||
37 | public abstract class BaseDataReader | ||
38 | { | ||
39 | private readonly IDataReader m_source; | ||
40 | |||
41 | /// <summary> | ||
42 | /// | ||
43 | /// </summary> | ||
44 | /// <param name="source"></param> | ||
45 | public BaseDataReader(IDataReader source) | ||
46 | { | ||
47 | m_source = source; | ||
48 | } | ||
49 | |||
50 | /// <summary> | ||
51 | /// | ||
52 | /// </summary> | ||
53 | /// <param name="name"></param> | ||
54 | /// <returns></returns> | ||
55 | public object Get(string name) | ||
56 | { | ||
57 | return m_source[name]; | ||
58 | } | ||
59 | |||
60 | /// <summary> | ||
61 | /// | ||
62 | /// </summary> | ||
63 | /// <param name="name"></param> | ||
64 | /// <returns></returns> | ||
65 | public ushort GetUShort(string name) | ||
66 | { | ||
67 | return (ushort)m_source.GetInt32(m_source.GetOrdinal(name)); | ||
68 | } | ||
69 | |||
70 | /// <summary> | ||
71 | /// | ||
72 | /// </summary> | ||
73 | /// <param name="name"></param> | ||
74 | /// <returns></returns> | ||
75 | public byte GetByte(string name) | ||
76 | { | ||
77 | int ordinal = m_source.GetOrdinal(name); | ||
78 | byte value = (byte)m_source.GetInt16(ordinal); | ||
79 | return value; | ||
80 | } | ||
81 | |||
82 | /// <summary> | ||
83 | /// | ||
84 | /// </summary> | ||
85 | /// <param name="name"></param> | ||
86 | /// <returns></returns> | ||
87 | public sbyte GetSByte(string name) | ||
88 | { | ||
89 | return (sbyte)m_source.GetInt16(m_source.GetOrdinal(name)); | ||
90 | } | ||
91 | |||
92 | /// <summary> | ||
93 | /// | ||
94 | /// </summary> | ||
95 | /// <param name="name"></param> | ||
96 | /// <returns></returns> | ||
97 | public float GetFloat(string name) | ||
98 | { | ||
99 | return m_source.GetFloat(m_source.GetOrdinal(name)); | ||
100 | } | ||
101 | |||
102 | /// <summary> | ||
103 | /// | ||
104 | /// </summary> | ||
105 | /// <param name="name"></param> | ||
106 | /// <returns></returns> | ||
107 | public byte[] GetBytes(string name) | ||
108 | { | ||
109 | int ordinal = m_source.GetOrdinal(name); | ||
110 | |||
111 | if (m_source.GetValue(ordinal) == DBNull.Value) | ||
112 | { | ||
113 | return null; | ||
114 | } | ||
115 | |||
116 | byte[] buffer = new byte[16384]; | ||
117 | |||
118 | MemoryStream memStream = new MemoryStream(); | ||
119 | |||
120 | long totalRead = 0; | ||
121 | |||
122 | int bytesRead; | ||
123 | do | ||
124 | { | ||
125 | bytesRead = (int)m_source.GetBytes(ordinal, totalRead, buffer, 0, buffer.Length); | ||
126 | totalRead += bytesRead; | ||
127 | |||
128 | memStream.Write(buffer, 0, bytesRead); | ||
129 | } while (bytesRead == buffer.Length); | ||
130 | |||
131 | return memStream.ToArray(); | ||
132 | } | ||
133 | |||
134 | /// <summary> | ||
135 | /// | ||
136 | /// </summary> | ||
137 | /// <param name="name"></param> | ||
138 | /// <returns></returns> | ||
139 | public string GetString(string name) | ||
140 | { | ||
141 | int ordinal = m_source.GetOrdinal(name); | ||
142 | object value = m_source.GetValue(ordinal); | ||
143 | |||
144 | if (value is DBNull) | ||
145 | { | ||
146 | return null; | ||
147 | } | ||
148 | |||
149 | return (string)value; | ||
150 | } | ||
151 | |||
152 | /// <summary> | ||
153 | /// | ||
154 | /// </summary> | ||
155 | /// <returns></returns> | ||
156 | public bool Read() | ||
157 | { | ||
158 | return m_source.Read(); | ||
159 | } | ||
160 | |||
161 | /// <summary> | ||
162 | /// | ||
163 | /// </summary> | ||
164 | /// <param name="name"></param> | ||
165 | /// <returns></returns> | ||
166 | public virtual Guid GetGuid(string name) | ||
167 | { | ||
168 | return m_source.GetGuid(m_source.GetOrdinal(name)); | ||
169 | } | ||
170 | |||
171 | /// <summary> | ||
172 | /// | ||
173 | /// </summary> | ||
174 | /// <param name="name"></param> | ||
175 | /// <returns></returns> | ||
176 | public UInt32 GetUInt32(string name) | ||
177 | { | ||
178 | return (UInt32)GetInt32(name); | ||
179 | } | ||
180 | |||
181 | /// <summary> | ||
182 | /// | ||
183 | /// </summary> | ||
184 | /// <param name="name"></param> | ||
185 | /// <returns></returns> | ||
186 | private Int32 GetInt32(string name) | ||
187 | { | ||
188 | int ordinal = m_source.GetOrdinal(name); | ||
189 | int int32 = m_source.GetInt32(ordinal); | ||
190 | return int32; | ||
191 | } | ||
192 | |||
193 | /// <summary> | ||
194 | /// | ||
195 | /// </summary> | ||
196 | /// <param name="name"></param> | ||
197 | /// <returns></returns> | ||
198 | public Int64 GetInt64(string name) | ||
199 | { | ||
200 | int ordinal = m_source.GetOrdinal(name); | ||
201 | long int64 = m_source.GetInt64(ordinal); | ||
202 | return int64; | ||
203 | } | ||
204 | } | ||
205 | } | ||
diff --git a/OpenSim/Data/Base/BaseDatabaseConnector.cs b/OpenSim/Data/Base/BaseDatabaseConnector.cs deleted file mode 100644 index 542004c..0000000 --- a/OpenSim/Data/Base/BaseDatabaseConnector.cs +++ /dev/null | |||
@@ -1,185 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Data; | ||
31 | using System.Data.Common; | ||
32 | |||
33 | namespace OpenSim.Data.Base | ||
34 | { | ||
35 | /// <summary> | ||
36 | /// | ||
37 | /// </summary> | ||
38 | public abstract class BaseDatabaseConnector | ||
39 | { | ||
40 | protected string m_connectionString; | ||
41 | |||
42 | /// <summary> | ||
43 | /// | ||
44 | /// </summary> | ||
45 | /// <param name="connectionString"></param> | ||
46 | public BaseDatabaseConnector(string connectionString) | ||
47 | { | ||
48 | m_connectionString = connectionString; | ||
49 | } | ||
50 | |||
51 | public abstract DbConnection GetNewConnection(); | ||
52 | public abstract string CreateParamName(string fieldName); | ||
53 | |||
54 | /// <summary> | ||
55 | /// | ||
56 | /// </summary> | ||
57 | /// <param name="mapper"></param> | ||
58 | /// <param name="connection"></param> | ||
59 | /// <param name="fieldName"></param> | ||
60 | /// <param name="key"></param> | ||
61 | /// <returns></returns> | ||
62 | public DbCommand CreateSelectCommand(BaseTableMapper mapper, DbConnection connection, string fieldName, object key) | ||
63 | { | ||
64 | string table = mapper.TableName; | ||
65 | |||
66 | DbCommand command = connection.CreateCommand(); | ||
67 | |||
68 | string conditionString = CreateCondition(mapper, command, fieldName, key); | ||
69 | |||
70 | string query = | ||
71 | String.Format("select * from {0} where {1}", table, conditionString); | ||
72 | |||
73 | command.CommandText = query; | ||
74 | command.CommandType = CommandType.Text; | ||
75 | |||
76 | return command; | ||
77 | } | ||
78 | |||
79 | /// <summary> | ||
80 | /// | ||
81 | /// </summary> | ||
82 | /// <param name="mapper"></param> | ||
83 | /// <param name="command"></param> | ||
84 | /// <param name="fieldName"></param> | ||
85 | /// <param name="key"></param> | ||
86 | /// <returns></returns> | ||
87 | public string CreateCondition(BaseTableMapper mapper, DbCommand command, string fieldName, object key) | ||
88 | { | ||
89 | string keyFieldParamName = mapper.CreateParamName(fieldName); | ||
90 | |||
91 | DbParameter param = command.CreateParameter(); | ||
92 | param.ParameterName = keyFieldParamName; | ||
93 | param.Value = ConvertToDbType(key); | ||
94 | command.Parameters.Add(param); | ||
95 | |||
96 | return String.Format("{0}={1}", fieldName, keyFieldParamName); | ||
97 | } | ||
98 | |||
99 | /// <summary> | ||
100 | /// | ||
101 | /// </summary> | ||
102 | /// <param name="mapper"></param> | ||
103 | /// <param name="connection"></param> | ||
104 | /// <param name="rowMapper"></param> | ||
105 | /// <param name="primaryKey"></param> | ||
106 | /// <returns></returns> | ||
107 | public DbCommand CreateUpdateCommand(BaseTableMapper mapper, DbConnection connection, object rowMapper, object primaryKey) | ||
108 | { | ||
109 | string table = mapper.TableName; | ||
110 | |||
111 | List<string> fieldNames = new List<string>(); | ||
112 | |||
113 | DbCommand command = connection.CreateCommand(); | ||
114 | |||
115 | foreach (BaseFieldMapper fieldMapper in mapper.Schema.Fields.Values) | ||
116 | { | ||
117 | if (fieldMapper != mapper.KeyFieldMapper) | ||
118 | { | ||
119 | fieldMapper.ExpandField(rowMapper, command, fieldNames); | ||
120 | } | ||
121 | } | ||
122 | |||
123 | List<string> assignments = new List<string>(); | ||
124 | |||
125 | foreach (string field in fieldNames) | ||
126 | { | ||
127 | assignments.Add(String.Format("{0}={1}", field, mapper.CreateParamName(field))); | ||
128 | } | ||
129 | |||
130 | string conditionString = mapper.CreateCondition(command, mapper.KeyFieldMapper.FieldName, primaryKey); | ||
131 | |||
132 | command.CommandText = | ||
133 | String.Format("update {0} set {1} where {2}", table, String.Join(", ", assignments.ToArray()), | ||
134 | conditionString); | ||
135 | |||
136 | return command; | ||
137 | } | ||
138 | |||
139 | /// <summary> | ||
140 | /// | ||
141 | /// </summary> | ||
142 | /// <param name="mapper"></param> | ||
143 | /// <param name="connection"></param> | ||
144 | /// <param name="obj"></param> | ||
145 | /// <returns></returns> | ||
146 | public DbCommand CreateInsertCommand(BaseTableMapper mapper, DbConnection connection, object obj) | ||
147 | { | ||
148 | string table = mapper.TableName; | ||
149 | |||
150 | List<string> fieldNames = new List<string>(); | ||
151 | |||
152 | DbCommand command = connection.CreateCommand(); | ||
153 | |||
154 | foreach (BaseFieldMapper fieldMapper in mapper.Schema.Fields.Values) | ||
155 | { | ||
156 | fieldMapper.ExpandField(obj, command, fieldNames); | ||
157 | } | ||
158 | |||
159 | List<string> paramNames = new List<string>(); | ||
160 | |||
161 | foreach (string field in fieldNames) | ||
162 | { | ||
163 | paramNames.Add(mapper.CreateParamName(field)); | ||
164 | } | ||
165 | |||
166 | command.CommandText = | ||
167 | String.Format("insert into {0} ({1}) values ({2})", table, String.Join(", ", fieldNames.ToArray()), | ||
168 | String.Join(", ", paramNames.ToArray())); | ||
169 | |||
170 | return command; | ||
171 | } | ||
172 | |||
173 | /// <summary> | ||
174 | /// | ||
175 | /// </summary> | ||
176 | /// <param name="value"></param> | ||
177 | /// <returns></returns> | ||
178 | public virtual object ConvertToDbType(object value) | ||
179 | { | ||
180 | return value; | ||
181 | } | ||
182 | |||
183 | public abstract BaseDataReader CreateReader(IDataReader reader); | ||
184 | } | ||
185 | } | ||
diff --git a/OpenSim/Data/Base/BaseFieldMapper.cs b/OpenSim/Data/Base/BaseFieldMapper.cs deleted file mode 100644 index c7d6bc9..0000000 --- a/OpenSim/Data/Base/BaseFieldMapper.cs +++ /dev/null | |||
@@ -1,214 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Data.Common; | ||
31 | |||
32 | namespace OpenSim.Data.Base | ||
33 | { | ||
34 | public delegate TField ObjectGetAccessor<TObj, TField>(TObj obj); | ||
35 | public delegate void ObjectSetAccessor<TObj, TField>(TObj obj, TField value); | ||
36 | |||
37 | /// <summary> | ||
38 | /// | ||
39 | /// </summary> | ||
40 | public abstract class BaseFieldMapper | ||
41 | { | ||
42 | private readonly BaseTableMapper m_tableMapper; | ||
43 | private readonly string m_fieldName; | ||
44 | |||
45 | /// <summary> | ||
46 | /// | ||
47 | /// </summary> | ||
48 | public string FieldName | ||
49 | { | ||
50 | get { return m_fieldName; } | ||
51 | } | ||
52 | |||
53 | protected Type m_valueType; | ||
54 | |||
55 | /// <summary> | ||
56 | /// | ||
57 | /// </summary> | ||
58 | public Type ValueType | ||
59 | { | ||
60 | get { return m_valueType; } | ||
61 | } | ||
62 | |||
63 | public abstract object GetParamValue(object obj); | ||
64 | |||
65 | /// <summary> | ||
66 | /// | ||
67 | /// </summary> | ||
68 | /// <param name="tableMapper"></param> | ||
69 | /// <param name="fieldName"></param> | ||
70 | /// <param name="valueType"></param> | ||
71 | public BaseFieldMapper(BaseTableMapper tableMapper, string fieldName, Type valueType) | ||
72 | { | ||
73 | m_fieldName = fieldName; | ||
74 | m_valueType = valueType; | ||
75 | m_tableMapper = tableMapper; | ||
76 | } | ||
77 | |||
78 | public abstract void SetPropertyFromReader(object mapper, BaseDataReader reader); | ||
79 | |||
80 | /// <summary> | ||
81 | /// | ||
82 | /// </summary> | ||
83 | /// <param name="command"></param> | ||
84 | /// <param name="fieldNames"></param> | ||
85 | /// <param name="fieldName"></param> | ||
86 | /// <param name="value"></param> | ||
87 | public void RawAddParam(DbCommand command, List<string> fieldNames, string fieldName, object value) | ||
88 | { | ||
89 | string paramName = m_tableMapper.CreateParamName(fieldName); | ||
90 | fieldNames.Add(fieldName); | ||
91 | |||
92 | DbParameter param = command.CreateParameter(); | ||
93 | param.ParameterName = paramName; | ||
94 | param.Value = value; | ||
95 | |||
96 | command.Parameters.Add(param); | ||
97 | } | ||
98 | |||
99 | /// <summary> | ||
100 | /// | ||
101 | /// </summary> | ||
102 | /// <typeparam name="TObj"></typeparam> | ||
103 | /// <param name="obj"></param> | ||
104 | /// <param name="command"></param> | ||
105 | /// <param name="fieldNames"></param> | ||
106 | public virtual void ExpandField<TObj>(TObj obj, DbCommand command, List<string> fieldNames) | ||
107 | { | ||
108 | string fieldName = FieldName; | ||
109 | object value = GetParamValue(obj); | ||
110 | |||
111 | RawAddParam(command, fieldNames, fieldName, m_tableMapper.ConvertToDbType(value)); | ||
112 | } | ||
113 | |||
114 | /// <summary> | ||
115 | /// | ||
116 | /// </summary> | ||
117 | /// <param name="reader"></param> | ||
118 | /// <returns></returns> | ||
119 | protected virtual object GetValue(BaseDataReader reader) | ||
120 | { | ||
121 | object value; | ||
122 | |||
123 | if (ValueType == typeof(Guid)) | ||
124 | { | ||
125 | value = reader.GetGuid(m_fieldName); | ||
126 | } | ||
127 | else if (ValueType == typeof(bool)) | ||
128 | { | ||
129 | uint boolVal = reader.GetUShort(m_fieldName); | ||
130 | value = (boolVal == 1); | ||
131 | } | ||
132 | else | ||
133 | if (ValueType == typeof(byte)) | ||
134 | { | ||
135 | value = reader.GetByte(m_fieldName); | ||
136 | } | ||
137 | else if (ValueType == typeof(sbyte)) | ||
138 | { | ||
139 | value = reader.GetSByte(m_fieldName); | ||
140 | } | ||
141 | else if (ValueType == typeof(ushort)) | ||
142 | { | ||
143 | value = reader.GetUShort(m_fieldName); | ||
144 | } | ||
145 | else if (ValueType == typeof(uint)) | ||
146 | { | ||
147 | value = reader.GetUInt32(m_fieldName); | ||
148 | } | ||
149 | else if (ValueType == typeof(byte[])) | ||
150 | { | ||
151 | value = reader.GetBytes(m_fieldName); | ||
152 | } | ||
153 | else | ||
154 | { | ||
155 | value = reader.Get(m_fieldName); | ||
156 | } | ||
157 | |||
158 | if (value is DBNull) | ||
159 | { | ||
160 | value = default(ValueType); | ||
161 | } | ||
162 | |||
163 | return value; | ||
164 | } | ||
165 | } | ||
166 | |||
167 | /// <summary> | ||
168 | /// | ||
169 | /// </summary> | ||
170 | /// <typeparam name="TObject"></typeparam> | ||
171 | /// <typeparam name="TField"></typeparam> | ||
172 | public class ObjectField<TObject, TField> : BaseFieldMapper | ||
173 | { | ||
174 | private readonly ObjectGetAccessor<TObject, TField> m_fieldGetAccessor; | ||
175 | private readonly ObjectSetAccessor<TObject, TField> m_fieldSetAccessor; | ||
176 | |||
177 | public override object GetParamValue(object obj) | ||
178 | { | ||
179 | return m_fieldGetAccessor((TObject)obj); | ||
180 | } | ||
181 | |||
182 | public override void SetPropertyFromReader(object obj, BaseDataReader reader) | ||
183 | { | ||
184 | object value; | ||
185 | |||
186 | value = GetValue(reader); | ||
187 | |||
188 | if (value == null) | ||
189 | { | ||
190 | m_fieldSetAccessor((TObject)obj, default(TField)); | ||
191 | } | ||
192 | else | ||
193 | { | ||
194 | m_fieldSetAccessor((TObject)obj, (TField)value); | ||
195 | } | ||
196 | } | ||
197 | |||
198 | |||
199 | /// <summary> | ||
200 | /// | ||
201 | /// </summary> | ||
202 | /// <param name="tableMapper"></param> | ||
203 | /// <param name="fieldName"></param> | ||
204 | /// <param name="rowMapperGetAccessor"></param> | ||
205 | /// <param name="rowMapperSetAccessor"></param> | ||
206 | public ObjectField(BaseTableMapper tableMapper, string fieldName, ObjectGetAccessor<TObject, TField> rowMapperGetAccessor, | ||
207 | ObjectSetAccessor<TObject, TField> rowMapperSetAccessor) | ||
208 | : base(tableMapper, fieldName, typeof(TField)) | ||
209 | { | ||
210 | m_fieldGetAccessor = rowMapperGetAccessor; | ||
211 | m_fieldSetAccessor = rowMapperSetAccessor; | ||
212 | } | ||
213 | } | ||
214 | } | ||
diff --git a/OpenSim/Data/Base/BaseRowMapper.cs b/OpenSim/Data/Base/BaseRowMapper.cs deleted file mode 100644 index d0e545b..0000000 --- a/OpenSim/Data/Base/BaseRowMapper.cs +++ /dev/null | |||
@@ -1,78 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | namespace OpenSim.Data.Base | ||
29 | { | ||
30 | /// <summary> | ||
31 | /// | ||
32 | /// </summary> | ||
33 | public abstract class BaseRowMapper | ||
34 | { | ||
35 | public abstract void FiPrimitive(BaseDataReader reader); | ||
36 | } | ||
37 | |||
38 | /// <summary> | ||
39 | /// | ||
40 | /// </summary> | ||
41 | /// <typeparam name="TObj"></typeparam> | ||
42 | public class BaseRowMapper<TObj> : BaseRowMapper | ||
43 | { | ||
44 | private readonly BaseSchema m_schema; | ||
45 | private readonly TObj m_obj; | ||
46 | |||
47 | /// <summary> | ||
48 | /// | ||
49 | /// </summary> | ||
50 | public TObj Object | ||
51 | { | ||
52 | get { return m_obj; } | ||
53 | } | ||
54 | |||
55 | /// <summary> | ||
56 | /// | ||
57 | /// </summary> | ||
58 | /// <param name="schema"></param> | ||
59 | /// <param name="obj"></param> | ||
60 | public BaseRowMapper(BaseSchema schema, TObj obj) | ||
61 | { | ||
62 | m_schema = schema; | ||
63 | m_obj = obj; | ||
64 | } | ||
65 | |||
66 | /// <summary> | ||
67 | /// | ||
68 | /// </summary> | ||
69 | /// <param name="reader"></param> | ||
70 | public override void FiPrimitive(BaseDataReader reader) | ||
71 | { | ||
72 | foreach (BaseFieldMapper fieldMapper in m_schema.Fields.Values) | ||
73 | { | ||
74 | fieldMapper.SetPropertyFromReader(this, reader); | ||
75 | } | ||
76 | } | ||
77 | } | ||
78 | } | ||
diff --git a/OpenSim/Data/Base/BaseSchema.cs b/OpenSim/Data/Base/BaseSchema.cs deleted file mode 100644 index 9d69a40..0000000 --- a/OpenSim/Data/Base/BaseSchema.cs +++ /dev/null | |||
@@ -1,94 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System.Collections.Generic; | ||
29 | |||
30 | namespace OpenSim.Data.Base | ||
31 | { | ||
32 | /// <summary> | ||
33 | /// | ||
34 | /// </summary> | ||
35 | public class BaseSchema | ||
36 | { | ||
37 | protected BaseTableMapper m_tableMapper; | ||
38 | protected Dictionary<string, BaseFieldMapper> m_mappings; | ||
39 | |||
40 | /// <summary> | ||
41 | /// | ||
42 | /// </summary> | ||
43 | public Dictionary<string, BaseFieldMapper> Fields | ||
44 | { | ||
45 | get { return m_mappings; } | ||
46 | } | ||
47 | |||
48 | /// <summary> | ||
49 | /// | ||
50 | /// </summary> | ||
51 | /// <param name="tableMapper"></param> | ||
52 | public BaseSchema(BaseTableMapper tableMapper) | ||
53 | { | ||
54 | m_mappings = new Dictionary<string, BaseFieldMapper>(); | ||
55 | m_tableMapper = tableMapper; | ||
56 | } | ||
57 | } | ||
58 | |||
59 | /// <summary> | ||
60 | /// | ||
61 | /// </summary> | ||
62 | /// <typeparam name="TObj"></typeparam> | ||
63 | public class BaseSchema<TObj> : BaseSchema | ||
64 | { | ||
65 | /// <summary> | ||
66 | /// | ||
67 | /// </summary> | ||
68 | /// <param name="tableMapper"></param> | ||
69 | public BaseSchema(BaseTableMapper tableMapper) | ||
70 | : base(tableMapper) | ||
71 | { | ||
72 | } | ||
73 | |||
74 | /// <summary> | ||
75 | /// | ||
76 | /// </summary> | ||
77 | /// <typeparam name="TField"></typeparam> | ||
78 | /// <param name="fieldName"></param> | ||
79 | /// <param name="rowMapperGetAccessor"></param> | ||
80 | /// <param name="rowMapperSetAccessor"></param> | ||
81 | /// <returns></returns> | ||
82 | public ObjectField<TObj, TField> AddMapping<TField>(string fieldName, | ||
83 | ObjectGetAccessor<TObj, TField> rowMapperGetAccessor, | ||
84 | ObjectSetAccessor<TObj, TField> rowMapperSetAccessor) | ||
85 | { | ||
86 | ObjectField<TObj, TField> rowMapperField = | ||
87 | new ObjectField<TObj, TField>(m_tableMapper, fieldName, rowMapperGetAccessor, rowMapperSetAccessor); | ||
88 | |||
89 | m_mappings.Add(fieldName, rowMapperField); | ||
90 | |||
91 | return rowMapperField; | ||
92 | } | ||
93 | } | ||
94 | } | ||
diff --git a/OpenSim/Data/Base/BaseTableMapper.cs b/OpenSim/Data/Base/BaseTableMapper.cs deleted file mode 100644 index 28b7ac8..0000000 --- a/OpenSim/Data/Base/BaseTableMapper.cs +++ /dev/null | |||
@@ -1,399 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Data; | ||
30 | using System.Data.Common; | ||
31 | |||
32 | namespace OpenSim.Data.Base | ||
33 | { | ||
34 | /// <summary> | ||
35 | /// | ||
36 | /// </summary> | ||
37 | public abstract class BaseTableMapper | ||
38 | { | ||
39 | private readonly BaseDatabaseConnector m_database; | ||
40 | private readonly object m_syncRoot = new object(); | ||
41 | |||
42 | /// <summary> | ||
43 | /// | ||
44 | /// </summary> | ||
45 | /// <param name="action"></param> | ||
46 | protected void WithConnection(Action<DbConnection> action) | ||
47 | { | ||
48 | lock (m_syncRoot) | ||
49 | { | ||
50 | DbConnection m_connection = m_database.GetNewConnection(); | ||
51 | |||
52 | if (m_connection.State != ConnectionState.Open) | ||
53 | { | ||
54 | m_connection.Open(); | ||
55 | } | ||
56 | |||
57 | action(m_connection); | ||
58 | |||
59 | if (m_connection.State == ConnectionState.Open) | ||
60 | { | ||
61 | m_connection.Close(); | ||
62 | } | ||
63 | } | ||
64 | } | ||
65 | |||
66 | private readonly string m_tableName; | ||
67 | public string TableName | ||
68 | { | ||
69 | get { return m_tableName; } | ||
70 | } | ||
71 | |||
72 | protected BaseSchema m_schema; | ||
73 | public BaseSchema Schema | ||
74 | { | ||
75 | get { return m_schema; } | ||
76 | } | ||
77 | |||
78 | protected BaseFieldMapper m_keyFieldMapper; | ||
79 | public BaseFieldMapper KeyFieldMapper | ||
80 | { | ||
81 | get { return m_keyFieldMapper; } | ||
82 | } | ||
83 | |||
84 | /// <summary> | ||
85 | /// | ||
86 | /// </summary> | ||
87 | /// <param name="database"></param> | ||
88 | /// <param name="tableName"></param> | ||
89 | public BaseTableMapper(BaseDatabaseConnector database, string tableName) | ||
90 | { | ||
91 | m_database = database; | ||
92 | m_tableName = tableName.ToLower(); // Stupid MySQL hack. | ||
93 | } | ||
94 | |||
95 | /// <summary> | ||
96 | /// | ||
97 | /// </summary> | ||
98 | /// <param name="fieldName"></param> | ||
99 | /// <returns></returns> | ||
100 | public string CreateParamName(string fieldName) | ||
101 | { | ||
102 | return m_database.CreateParamName(fieldName); | ||
103 | } | ||
104 | |||
105 | /// <summary> | ||
106 | /// | ||
107 | /// </summary> | ||
108 | /// <param name="connection"></param> | ||
109 | /// <param name="fieldName"></param> | ||
110 | /// <param name="primaryKey"></param> | ||
111 | /// <returns></returns> | ||
112 | protected DbCommand CreateSelectCommand(DbConnection connection, string fieldName, object primaryKey) | ||
113 | { | ||
114 | return m_database.CreateSelectCommand(this, connection, fieldName, primaryKey); | ||
115 | } | ||
116 | |||
117 | /// <summary> | ||
118 | /// | ||
119 | /// </summary> | ||
120 | /// <param name="command"></param> | ||
121 | /// <param name="fieldName"></param> | ||
122 | /// <param name="key"></param> | ||
123 | /// <returns></returns> | ||
124 | public string CreateCondition(DbCommand command, string fieldName, object key) | ||
125 | { | ||
126 | return m_database.CreateCondition(this, command, fieldName, key); | ||
127 | } | ||
128 | |||
129 | /// <summary> | ||
130 | /// | ||
131 | /// </summary> | ||
132 | /// <param name="connection"></param> | ||
133 | /// <param name="obj"></param> | ||
134 | /// <returns></returns> | ||
135 | public DbCommand CreateInsertCommand(DbConnection connection, object obj) | ||
136 | { | ||
137 | return m_database.CreateInsertCommand(this, connection, obj); | ||
138 | } | ||
139 | |||
140 | /// <summary> | ||
141 | /// | ||
142 | /// </summary> | ||
143 | /// <param name="connection"></param> | ||
144 | /// <param name="rowMapper"></param> | ||
145 | /// <param name="primaryKey"></param> | ||
146 | /// <returns></returns> | ||
147 | public DbCommand CreateUpdateCommand(DbConnection connection, object rowMapper, object primaryKey) | ||
148 | { | ||
149 | return m_database.CreateUpdateCommand(this, connection, rowMapper, primaryKey); | ||
150 | } | ||
151 | |||
152 | /// <summary> | ||
153 | /// | ||
154 | /// </summary> | ||
155 | /// <param name="value"></param> | ||
156 | /// <returns></returns> | ||
157 | public object ConvertToDbType(object value) | ||
158 | { | ||
159 | return m_database.ConvertToDbType(value); | ||
160 | } | ||
161 | |||
162 | /// <summary> | ||
163 | /// | ||
164 | /// </summary> | ||
165 | /// <param name="reader"></param> | ||
166 | /// <returns></returns> | ||
167 | protected virtual BaseDataReader CreateReader(IDataReader reader) | ||
168 | { | ||
169 | return m_database.CreateReader(reader); | ||
170 | } | ||
171 | } | ||
172 | |||
173 | /// <summary> | ||
174 | /// | ||
175 | /// </summary> | ||
176 | /// <typeparam name="TRowMapper"></typeparam> | ||
177 | /// <typeparam name="TPrimaryKey"></typeparam> | ||
178 | public abstract class BaseTableMapper<TRowMapper, TPrimaryKey> : BaseTableMapper | ||
179 | { | ||
180 | /// <summary> | ||
181 | /// | ||
182 | /// </summary> | ||
183 | /// <param name="database"></param> | ||
184 | /// <param name="tableName"></param> | ||
185 | public BaseTableMapper(BaseDatabaseConnector database, string tableName) | ||
186 | : base(database, tableName) | ||
187 | { | ||
188 | } | ||
189 | |||
190 | |||
191 | |||
192 | /// <summary> | ||
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> | ||
202 | private void TryGetConnectionValue(DbConnection connection, TPrimaryKey primaryKey, ref TRowMapper result, ref bool success) | ||
203 | { | ||
204 | using ( | ||
205 | DbCommand command = | ||
206 | CreateSelectCommand(connection, KeyFieldMapper.FieldName, primaryKey)) | ||
207 | { | ||
208 | using (IDataReader reader = command.ExecuteReader()) | ||
209 | { | ||
210 | if (reader.Read()) | ||
211 | { | ||
212 | result = FromReader(CreateReader(reader)); | ||
213 | success = true; | ||
214 | } | ||
215 | else | ||
216 | { | ||
217 | success = false; | ||
218 | } | ||
219 | } | ||
220 | } | ||
221 | } | ||
222 | |||
223 | /// <summary> | ||
224 | /// | ||
225 | /// </summary> | ||
226 | /// <param name="primaryKey"></param> | ||
227 | /// <param name="value"></param> | ||
228 | /// <returns></returns> | ||
229 | public bool TryGetValue(TPrimaryKey primaryKey, out TRowMapper value) | ||
230 | { | ||
231 | TRowMapper result = default(TRowMapper); | ||
232 | bool success = false; | ||
233 | |||
234 | WithConnection(delegate(DbConnection connection) | ||
235 | { | ||
236 | TryGetConnectionValue(connection, primaryKey, ref result, ref success); | ||
237 | }); | ||
238 | |||
239 | value = result; | ||
240 | |||
241 | return success; | ||
242 | } | ||
243 | |||
244 | /// <summary> | ||
245 | /// HACK: This is a temporary function used by Remove(). | ||
246 | /// Due to a bug in mono 1.2.6, delegate blocks cannot contain | ||
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> | ||
253 | protected virtual void TryDelete(DbConnection connection, TPrimaryKey id, ref int deleted) | ||
254 | { | ||
255 | using ( | ||
256 | DbCommand command = | ||
257 | CreateDeleteCommand(connection, KeyFieldMapper.FieldName, id)) | ||
258 | { | ||
259 | deleted = command.ExecuteNonQuery(); | ||
260 | } | ||
261 | } | ||
262 | |||
263 | /// <summary> | ||
264 | /// | ||
265 | /// </summary> | ||
266 | /// <param name="id"></param> | ||
267 | /// <returns></returns> | ||
268 | public virtual bool Remove(TPrimaryKey id) | ||
269 | { | ||
270 | int deleted = 0; | ||
271 | |||
272 | WithConnection(delegate(DbConnection connection) | ||
273 | { | ||
274 | TryDelete(connection, id, ref deleted); | ||
275 | }); | ||
276 | |||
277 | if (deleted == 1) | ||
278 | { | ||
279 | return true; | ||
280 | } | ||
281 | else | ||
282 | { | ||
283 | return false; | ||
284 | } | ||
285 | } | ||
286 | |||
287 | /// <summary> | ||
288 | /// | ||
289 | /// </summary> | ||
290 | /// <param name="connection"></param> | ||
291 | /// <param name="fieldName"></param> | ||
292 | /// <param name="primaryKey"></param> | ||
293 | /// <returns></returns> | ||
294 | public DbCommand CreateDeleteCommand(DbConnection connection, string fieldName, TPrimaryKey primaryKey) | ||
295 | { | ||
296 | string table = TableName; | ||
297 | |||
298 | DbCommand command = connection.CreateCommand(); | ||
299 | |||
300 | string conditionString = CreateCondition(command, fieldName, primaryKey); | ||
301 | |||
302 | string query = | ||
303 | String.Format("delete from {0} where {1}", table, conditionString); | ||
304 | |||
305 | command.CommandText = query; | ||
306 | command.CommandType = CommandType.Text; | ||
307 | |||
308 | return command; | ||
309 | } | ||
310 | |||
311 | |||
312 | |||
313 | /// <summary> | ||
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> | ||
323 | protected void TryUpdate(DbConnection connection, TPrimaryKey primaryKey, TRowMapper value, ref int updated) | ||
324 | { | ||
325 | using (DbCommand command = CreateUpdateCommand(connection, value, primaryKey)) | ||
326 | { | ||
327 | updated = command.ExecuteNonQuery(); | ||
328 | } | ||
329 | } | ||
330 | |||
331 | /// <summary> | ||
332 | /// | ||
333 | /// </summary> | ||
334 | /// <param name="primaryKey"></param> | ||
335 | /// <param name="value"></param> | ||
336 | /// <returns></returns> | ||
337 | public virtual bool Update(TPrimaryKey primaryKey, TRowMapper value) | ||
338 | { | ||
339 | int updated = 0; | ||
340 | |||
341 | WithConnection(delegate(DbConnection connection) | ||
342 | { | ||
343 | TryUpdate(connection, primaryKey, value, ref updated); | ||
344 | }); | ||
345 | |||
346 | if (updated == 1) | ||
347 | { | ||
348 | return true; | ||
349 | } | ||
350 | else | ||
351 | { | ||
352 | return false; | ||
353 | } | ||
354 | } | ||
355 | |||
356 | /// <summary> | ||
357 | /// HACK: This is a temporary function used by Add(). | ||
358 | /// Due to a bug in mono 1.2.6, delegate blocks cannot contain | ||
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> | ||
365 | protected void TryAdd(DbConnection connection, TRowMapper value, ref int added) | ||
366 | { | ||
367 | using (DbCommand command = CreateInsertCommand(connection, value)) | ||
368 | { | ||
369 | added = command.ExecuteNonQuery(); | ||
370 | } | ||
371 | } | ||
372 | |||
373 | /// <summary> | ||
374 | /// | ||
375 | /// </summary> | ||
376 | /// <param name="value"></param> | ||
377 | /// <returns></returns> | ||
378 | public virtual bool Add(TRowMapper value) | ||
379 | { | ||
380 | int added = 0; | ||
381 | |||
382 | WithConnection(delegate(DbConnection connection) | ||
383 | { | ||
384 | TryAdd(connection, value, ref added); | ||
385 | }); | ||
386 | |||
387 | if (added == 1) | ||
388 | { | ||
389 | return true; | ||
390 | } | ||
391 | else | ||
392 | { | ||
393 | return false; | ||
394 | } | ||
395 | } | ||
396 | |||
397 | public abstract TRowMapper FromReader(BaseDataReader reader); | ||
398 | } | ||
399 | } | ||
diff --git a/OpenSim/Data/Base/OpenSim.Data.Base.snk b/OpenSim/Data/Base/OpenSim.Data.Base.snk deleted file mode 100644 index fc71027..0000000 --- a/OpenSim/Data/Base/OpenSim.Data.Base.snk +++ /dev/null | |||
Binary files differ | |||
diff --git a/OpenSim/Data/Base/Properties/AssemblyInfo.cs b/OpenSim/Data/Base/Properties/AssemblyInfo.cs deleted file mode 100644 index f165434..0000000 --- a/OpenSim/Data/Base/Properties/AssemblyInfo.cs +++ /dev/null | |||
@@ -1,67 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System.Reflection; | ||
29 | using System.Runtime.InteropServices; | ||
30 | using System.Security; | ||
31 | |||
32 | // General information about an assembly is controlled through the following | ||
33 | // set of attributes. Change these attribute values to modify the information | ||
34 | // associated with an assembly. | ||
35 | |||
36 | [assembly : AssemblyTitle("OpenSim.Data.Base")] | ||
37 | [assembly : AssemblyDescription("Generic Database Abstraction Layer")] | ||
38 | [assembly : AssemblyConfiguration("")] | ||
39 | [assembly : AssemblyCompany("OpenSim Project (www.opensimulator.org)")] | ||
40 | [assembly: AssemblyProduct("OpenSim.Data.Base")] | ||
41 | [assembly: AssemblyCopyright("Copyright (c) 2007 OpenSim Project (www.opensimulator.org)")] | ||
42 | [assembly : AssemblyTrademark("")] | ||
43 | [assembly : AssemblyCulture("")] | ||
44 | |||
45 | // Setting ComVisible to false makes the types in this assembly not visible | ||
46 | // to COM components. If you need to access a type in this assembly from | ||
47 | // COM, set the ComVisible attribute to true on that type. | ||
48 | |||
49 | [assembly : ComVisible(false)] | ||
50 | |||
51 | // The following GUID is for the ID of the typelib if this project is exposed to COM | ||
52 | |||
53 | [assembly : Guid("9269f421-19d9-4eea-bfe3-c0ffe426fada")] | ||
54 | |||
55 | // Version information for an assembly consists of the following four values: | ||
56 | // | ||
57 | // Major Version | ||
58 | // Minor Version | ||
59 | // Build Number | ||
60 | // Revision | ||
61 | // | ||
62 | // You can specify all the values or you can default the Revision and Build Numbers | ||
63 | // by using the '*' as shown below: | ||
64 | |||
65 | [assembly : AssemblyVersion("1.0.0.0")] | ||
66 | [assembly : AssemblyFileVersion("1.0.0.0")] | ||
67 | [assembly : AllowPartiallyTrustedCallers] | ||