1
|
|
|
2
|
|
#region Apache Notice
|
3
|
|
|
4
|
|
|
5
|
|
|
6
|
|
|
7
|
|
|
8
|
|
|
9
|
|
|
10
|
|
|
11
|
|
|
12
|
|
|
13
|
|
|
14
|
|
|
15
|
|
|
16
|
|
|
17
|
|
|
18
|
|
|
19
|
|
|
20
|
|
|
21
|
|
|
22
|
|
|
23
|
|
|
24
|
|
|
25
|
|
#endregion
|
26
|
|
|
27
|
|
#region Using
|
28
|
|
|
29
|
|
using System;
|
30
|
|
using System.Collections;
|
31
|
|
using System.Data;
|
32
|
|
using System.Xml;
|
33
|
|
using System.Xml.Serialization;
|
34
|
|
using IBatisNet.Common.Utilities.Objects;
|
35
|
|
using IBatisNet.DataMapper.Scope;
|
36
|
|
using IBatisNet.DataMapper.TypeHandlers;
|
37
|
|
|
38
|
|
#endregion
|
39
|
|
|
40
|
|
namespace IBatisNet.DataMapper.Configuration.ParameterMapping
|
41
|
|
{
|
42
|
|
|
43
|
|
|
44
|
|
|
45
|
|
[Serializable]
|
46
|
|
[XmlRoot("parameterMap")]
|
47
|
|
public class ParameterMap
|
48
|
|
{
|
49
|
|
|
50
|
|
#region private
|
51
|
|
[NonSerialized]
|
52
|
|
private string _id = string.Empty;
|
53
|
|
[NonSerialized]
|
54
|
|
|
55
|
|
private ArrayList _properties = new ArrayList();
|
56
|
|
|
57
|
|
[NonSerialized]
|
58
|
|
private ArrayList _propertiesList = new ArrayList();
|
59
|
|
|
60
|
|
[NonSerialized]
|
61
|
|
private Hashtable _propertiesMap = new Hashtable();
|
62
|
|
[NonSerialized]
|
63
|
|
private string _extendMap = string.Empty;
|
64
|
|
[NonSerialized]
|
65
|
|
private bool _usePositionalParameters =false;
|
66
|
|
|
67
|
|
|
68
|
|
#endregion
|
69
|
|
|
70
|
|
#region Properties
|
71
|
|
|
72
|
|
|
73
|
|
|
74
|
|
[XmlAttribute("id")]
|
75
|
|
public string Id
|
76
|
|
{
|
77
|
10200
|
get { return _id; }
|
78
|
20279
|
set { _id = value; }
|
79
|
|
}
|
80
|
|
|
81
|
|
|
82
|
|
|
83
|
|
|
84
|
|
|
85
|
|
[XmlIgnore]
|
86
|
|
public ArrayList Properties
|
87
|
|
{
|
88
|
32699
|
get
|
89
|
|
{
|
90
|
|
|
91
|
|
|
92
|
|
|
93
|
|
|
94
|
|
|
95
|
|
|
96
|
|
|
97
|
|
|
98
|
32699
|
return _properties;
|
99
|
|
}
|
100
|
|
}
|
101
|
|
|
102
|
|
|
103
|
|
|
104
|
|
|
105
|
|
[XmlIgnore]
|
106
|
|
public ArrayList PropertiesList
|
107
|
|
{
|
108
|
19830
|
get { return _propertiesList; }
|
109
|
|
}
|
110
|
|
|
111
|
|
|
112
|
|
|
113
|
|
|
114
|
|
|
115
|
|
[XmlAttribute("extends")]
|
116
|
|
public string ExtendMap
|
117
|
|
{
|
118
|
11220
|
get { return _extendMap; }
|
119
|
3910
|
set { _extendMap = value; }
|
120
|
|
}
|
121
|
|
#endregion
|
122
|
|
|
123
|
|
#region Constructor (s) / Destructor
|
124
|
|
|
125
|
|
|
126
|
|
|
127
|
|
|
128
|
3400
|
public ParameterMap()
|
129
|
|
{}
|
130
|
|
|
131
|
|
|
132
|
|
|
133
|
|
|
134
|
|
|
135
|
13479
|
public ParameterMap(bool usePositionalParameters)
|
136
|
|
{
|
137
|
13479
|
_usePositionalParameters = usePositionalParameters;
|
138
|
|
|
139
|
|
}
|
140
|
|
#endregion
|
141
|
|
|
142
|
|
#region Methods
|
143
|
|
|
144
|
|
|
145
|
|
|
146
|
|
|
147
|
|
|
148
|
1508
|
public ParameterProperty GetProperty(int index)
|
149
|
|
{
|
150
|
1508
|
if (_usePositionalParameters)
|
151
|
|
{
|
152
|
0
|
return (ParameterProperty)_properties[index];
|
153
|
|
}
|
154
|
|
else
|
155
|
|
{
|
156
|
1508
|
return (ParameterProperty)_propertiesList[index];
|
157
|
|
}
|
158
|
|
|
159
|
|
}
|
160
|
|
|
161
|
|
|
162
|
|
|
163
|
|
|
164
|
|
|
165
|
|
|
166
|
2380
|
public ParameterProperty GetProperty(string name)
|
167
|
|
{
|
168
|
2380
|
return (ParameterProperty)_propertiesMap[name];
|
169
|
|
}
|
170
|
|
|
171
|
|
|
172
|
|
|
173
|
|
|
174
|
|
|
175
|
|
|
176
|
33379
|
public void AddParameterProperty(ParameterProperty property)
|
177
|
|
{
|
178
|
|
|
179
|
|
|
180
|
33379
|
_propertiesMap[property.PropertyName] = property;
|
181
|
33379
|
_properties.Add( property );
|
182
|
|
|
183
|
33379
|
if (_propertiesList.Contains(property) == false)
|
184
|
|
{
|
185
|
32524
|
_propertiesList.Add( property );
|
186
|
|
}
|
187
|
|
}
|
188
|
|
|
189
|
|
|
190
|
|
|
191
|
|
|
192
|
|
|
193
|
|
|
194
|
|
|
195
|
|
|
196
|
2380
|
public void InsertParameterProperty(int index, ParameterProperty property)
|
197
|
|
{
|
198
|
|
|
199
|
|
|
200
|
2380
|
_propertiesMap[property.PropertyName] = property;
|
201
|
2380
|
_properties.Insert( index, property );
|
202
|
|
|
203
|
2380
|
if (_propertiesList.Contains(property) == false)
|
204
|
|
{
|
205
|
2380
|
_propertiesList.Insert( index, property );
|
206
|
|
}
|
207
|
|
}
|
208
|
|
|
209
|
|
|
210
|
|
|
211
|
|
|
212
|
|
|
213
|
|
|
214
|
0
|
public int GetParameterIndex(string propertyName)
|
215
|
|
{
|
216
|
|
int idx = -1;
|
217
|
|
|
218
|
|
idx = Convert.ToInt32(propertyName.Replace("[","").Replace("]",""));
|
219
|
|
return idx;
|
220
|
|
}
|
221
|
|
|
222
|
|
|
223
|
|
|
224
|
|
|
225
|
|
|
226
|
|
|
227
|
511
|
public string[] GetPropertyNameArray()
|
228
|
|
{
|
229
|
511
|
string[] propertyNameArray = new string[_propertiesMap.Count];
|
230
|
|
|
231
|
511
|
IEnumerator myEnumerator = _propertiesList.GetEnumerator();
|
232
|
511
|
int index =0;
|
233
|
2892
|
while ( myEnumerator.MoveNext() )
|
234
|
|
{
|
235
|
2381
|
propertyNameArray[index] = ((ParameterProperty)myEnumerator.Current).PropertyName;
|
236
|
2381
|
index++;
|
237
|
|
}
|
238
|
|
|
239
|
511
|
return (propertyNameArray);
|
240
|
|
}
|
241
|
|
|
242
|
|
|
243
|
|
|
244
|
|
|
245
|
|
|
246
|
|
|
247
|
|
|
248
|
|
|
249
|
500
|
public void SetParameter(ParameterProperty mapping, IDataParameter dataParameter, object parameterValue)
|
250
|
|
{
|
251
|
500
|
object value = parameterValue;
|
252
|
500
|
ITypeHandler typeHandler = mapping.TypeHandler;
|
253
|
|
|
254
|
|
|
255
|
|
|
256
|
|
|
257
|
500
|
if (parameterValue.GetType() != typeof(string) &&
|
258
|
|
parameterValue.GetType() != typeof(Guid) &&
|
259
|
|
parameterValue.GetType() != typeof(Decimal) &&
|
260
|
|
parameterValue.GetType() != typeof(DateTime) &&
|
261
|
|
!parameterValue.GetType().IsPrimitive)
|
262
|
|
{
|
263
|
392
|
value = ObjectProbe.GetPropertyValue(value, mapping.PropertyName);
|
264
|
|
|
265
|
|
|
266
|
|
|
267
|
|
|
268
|
|
|
269
|
|
|
270
|
|
|
271
|
|
|
272
|
|
|
273
|
|
|
274
|
|
}
|
275
|
|
|
276
|
|
|
277
|
499
|
if (mapping.HasNullValue)
|
278
|
|
{
|
279
|
39
|
if (typeHandler.Equals(value, mapping.NullValue))
|
280
|
|
{
|
281
|
27
|
value = null;
|
282
|
|
}
|
283
|
|
}
|
284
|
|
|
285
|
|
|
286
|
499
|
if (value != null)
|
287
|
|
{
|
288
|
470
|
typeHandler.SetParameter(dataParameter, value, mapping.DbType);
|
289
|
|
}
|
290
|
29
|
else if(typeHandler is CustomTypeHandler)
|
291
|
|
{
|
292
|
0
|
typeHandler.SetParameter(dataParameter, value, mapping.DbType);
|
293
|
|
}
|
294
|
|
else
|
295
|
|
{
|
296
|
|
|
297
|
|
|
298
|
29
|
dataParameter.Value = DBNull.Value;
|
299
|
|
}
|
300
|
|
}
|
301
|
|
|
302
|
|
#region Configuration
|
303
|
|
|
304
|
|
|
305
|
|
|
306
|
|
|
307
|
3400
|
public void Initialize(ConfigurationScope configScope)
|
308
|
|
{
|
309
|
3400
|
_usePositionalParameters = configScope.DataSource.Provider.UsePositionalParameters;
|
310
|
3400
|
GetProperties( configScope );
|
311
|
|
}
|
312
|
|
|
313
|
|
|
314
|
|
|
315
|
|
|
316
|
|
|
317
|
|
|
318
|
3400
|
private void GetProperties(ConfigurationScope configScope)
|
319
|
|
{
|
320
|
3400
|
XmlSerializer serializer = null;
|
321
|
3400
|
ParameterProperty property = null;
|
322
|
|
|
323
|
3400
|
serializer = new XmlSerializer(typeof(ParameterProperty));
|
324
|
3400
|
foreach ( XmlNode parameterNode in configScope.NodeContext.SelectNodes("parameter") )
|
325
|
|
{
|
326
|
12410
|
property = (ParameterProperty) serializer.Deserialize(new XmlNodeReader(parameterNode));
|
327
|
12410
|
property.Initialize( configScope );
|
328
|
|
|
329
|
12410
|
AddParameterProperty(property);
|
330
|
|
}
|
331
|
|
}
|
332
|
|
#endregion
|
333
|
|
|
334
|
|
#endregion
|
335
|
|
|
336
|
|
}
|
337
|
|
}
|
338
|
|
|