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.Data;
|
31
|
|
using System.Xml.Serialization;
|
32
|
|
using IBatisNet.Common.Exceptions;
|
33
|
|
using IBatisNet.Common.Utilities;
|
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("parameter")]
|
47
|
|
public class ParameterProperty
|
48
|
|
{
|
49
|
|
|
50
|
|
#region Fields
|
51
|
|
[NonSerialized]
|
52
|
|
private string _nullValue = string.Empty;
|
53
|
|
[NonSerialized]
|
54
|
|
private string _property = string.Empty;
|
55
|
|
[NonSerialized]
|
56
|
|
private ParameterDirection _direction = ParameterDirection.Input;
|
57
|
|
[NonSerialized]
|
58
|
|
private string _directionAttribute = string.Empty;
|
59
|
|
[NonSerialized]
|
60
|
|
private string _dbType = null;
|
61
|
|
[NonSerialized]
|
62
|
|
private int _size = -1;
|
63
|
|
[NonSerialized]
|
64
|
|
private byte _scale= 0;
|
65
|
|
[NonSerialized]
|
66
|
|
private byte _precision = 0;
|
67
|
|
[NonSerialized]
|
68
|
|
private string _columnName = string.Empty;
|
69
|
|
[NonSerialized]
|
70
|
|
private ITypeHandler _typeHandler = null;
|
71
|
|
[NonSerialized]
|
72
|
|
private string _clrType = string.Empty;
|
73
|
|
[NonSerialized]
|
74
|
|
private string _callBackName= string.Empty;
|
75
|
|
#endregion
|
76
|
|
|
77
|
|
#region Properties
|
78
|
|
|
79
|
|
|
80
|
|
|
81
|
|
|
82
|
|
|
83
|
|
[XmlAttribute("typeHandler")]
|
84
|
|
public string CallBackName
|
85
|
|
{
|
86
|
25160
|
get { return _callBackName; }
|
87
|
340
|
set { _callBackName = value; }
|
88
|
|
}
|
89
|
|
|
90
|
|
|
91
|
|
|
92
|
|
|
93
|
|
|
94
|
|
|
95
|
|
|
96
|
|
|
97
|
|
|
98
|
|
[XmlAttribute("type")]
|
99
|
|
public string CLRType
|
100
|
|
{
|
101
|
58334
|
get { return _clrType; }
|
102
|
170
|
set { _clrType = value; }
|
103
|
|
}
|
104
|
|
|
105
|
|
|
106
|
|
|
107
|
|
|
108
|
|
[XmlIgnore]
|
109
|
|
public ITypeHandler TypeHandler
|
110
|
|
{
|
111
|
510
|
get { return _typeHandler; }
|
112
|
46094
|
set { _typeHandler = value; }
|
113
|
|
}
|
114
|
|
|
115
|
|
|
116
|
|
|
117
|
|
|
118
|
|
|
119
|
|
[XmlAttribute("column")]
|
120
|
|
public string ColumnName
|
121
|
|
{
|
122
|
2215
|
get { return _columnName; }
|
123
|
3910
|
set { _columnName = value; }
|
124
|
|
}
|
125
|
|
|
126
|
|
|
127
|
|
|
128
|
|
|
129
|
|
[XmlAttribute("size")]
|
130
|
|
public int Size
|
131
|
|
{
|
132
|
32184
|
get { return _size; }
|
133
|
0
|
set { _size = value; }
|
134
|
|
}
|
135
|
|
|
136
|
|
|
137
|
|
|
138
|
|
|
139
|
|
[XmlAttribute("scale")]
|
140
|
|
public byte Scale
|
141
|
|
{
|
142
|
32184
|
get { return _scale; }
|
143
|
0
|
set { _scale = value; }
|
144
|
|
}
|
145
|
|
|
146
|
|
|
147
|
|
|
148
|
|
|
149
|
|
[XmlAttribute("precision")]
|
150
|
|
public byte Precision
|
151
|
|
{
|
152
|
32184
|
get { return _precision; }
|
153
|
0
|
set { _precision = value; }
|
154
|
|
}
|
155
|
|
|
156
|
|
|
157
|
|
|
158
|
|
|
159
|
|
|
160
|
|
|
161
|
|
|
162
|
|
|
163
|
|
[XmlAttribute("dbType")]
|
164
|
|
public string DbType
|
165
|
|
{
|
166
|
40985
|
get { return _dbType; }
|
167
|
5950
|
set { _dbType = value; }
|
168
|
|
}
|
169
|
|
|
170
|
|
|
171
|
|
|
172
|
|
|
173
|
|
|
174
|
|
[XmlAttribute("direction")]
|
175
|
|
public string DirectionAttribute
|
176
|
|
{
|
177
|
24
|
get { return _directionAttribute; }
|
178
|
0
|
set { _directionAttribute = value; }
|
179
|
|
}
|
180
|
|
|
181
|
|
|
182
|
|
|
183
|
|
|
184
|
|
|
185
|
|
[XmlIgnore]
|
186
|
|
public ParameterDirection Direction
|
187
|
|
{
|
188
|
33206
|
get { return _direction; }
|
189
|
21
|
set
|
190
|
|
{
|
191
|
21
|
_direction = value;
|
192
|
21
|
_directionAttribute = _direction.ToString();
|
193
|
|
}
|
194
|
|
}
|
195
|
|
|
196
|
|
|
197
|
|
|
198
|
|
|
199
|
|
|
200
|
|
[XmlAttribute("property")]
|
201
|
|
public string PropertyName
|
202
|
|
{
|
203
|
406025
|
get { return _property; }
|
204
|
58504
|
set
|
205
|
|
{
|
206
|
58504
|
if ((value == null) || (value.Length < 1))
|
207
|
0
|
throw new ArgumentNullException("The property attribute is mandatory in a paremeter property.");
|
208
|
|
|
209
|
58504
|
_property = value;
|
210
|
|
}
|
211
|
|
}
|
212
|
|
|
213
|
|
|
214
|
|
|
215
|
|
|
216
|
|
[XmlIgnore]
|
217
|
|
public bool HasNullValue
|
218
|
|
{
|
219
|
499
|
get { return (_nullValue.Length>0); }
|
220
|
|
}
|
221
|
|
|
222
|
|
|
223
|
|
|
224
|
|
|
225
|
|
|
226
|
|
[XmlAttribute("nullValue")]
|
227
|
|
public string NullValue
|
228
|
|
{
|
229
|
39
|
get { return _nullValue; }
|
230
|
2210
|
set { _nullValue = value; }
|
231
|
|
}
|
232
|
|
#endregion
|
233
|
|
|
234
|
|
#region Constructor (s) / Destructor
|
235
|
|
|
236
|
|
|
237
|
|
|
238
|
|
|
239
|
58504
|
public ParameterProperty()
|
240
|
|
{
|
241
|
|
}
|
242
|
|
#endregion
|
243
|
|
|
244
|
|
#region Methods
|
245
|
|
|
246
|
|
|
247
|
|
|
248
|
|
|
249
|
12410
|
public void Initialize(ConfigurationScope configScope)
|
250
|
|
{
|
251
|
12410
|
if(_directionAttribute.Length >0)
|
252
|
|
{
|
253
|
0
|
_direction = (ParameterDirection)Enum.Parse( typeof(ParameterDirection), _directionAttribute, true );
|
254
|
|
}
|
255
|
|
|
256
|
12410
|
configScope.ErrorContext.MoreInfo = "Check the parameter mapping typeHandler attribute '" + this.CallBackName + "' (must be a ITypeHandlerCallback implementation).";
|
257
|
12410
|
if (this.CallBackName.Length >0)
|
258
|
|
{
|
259
|
340
|
try
|
260
|
|
{
|
261
|
340
|
Type type = configScope.SqlMapper.GetType(this.CallBackName);
|
262
|
340
|
ITypeHandlerCallback typeHandlerCallback = (ITypeHandlerCallback) Activator.CreateInstance( type );
|
263
|
340
|
_typeHandler = new CustomTypeHandler(typeHandlerCallback);
|
264
|
|
}
|
265
|
|
catch (Exception e)
|
266
|
|
{
|
267
|
0
|
throw new ConfigurationException("Error occurred during custom type handler configuration. Cause: " + e.Message, e);
|
268
|
|
}
|
269
|
|
}
|
270
|
|
else
|
271
|
|
{
|
272
|
12070
|
if (this.CLRType.Length == 0 )
|
273
|
|
{
|
274
|
11900
|
_typeHandler = configScope.TypeHandlerFactory.GetUnkownTypeHandler();
|
275
|
|
}
|
276
|
|
else
|
277
|
|
{
|
278
|
170
|
Type type = Resources.TypeForName(this.CLRType);
|
279
|
|
|
280
|
170
|
if (configScope.TypeHandlerFactory.IsSimpleType(type))
|
281
|
|
{
|
282
|
|
|
283
|
170
|
_typeHandler = configScope.TypeHandlerFactory.GetTypeHandler(type, _dbType);
|
284
|
|
}
|
285
|
|
else
|
286
|
|
{
|
287
|
|
|
288
|
0
|
type = ObjectProbe.GetPropertyTypeForGetter(type, this.PropertyName);
|
289
|
0
|
_typeHandler = configScope.TypeHandlerFactory.GetTypeHandler(type, _dbType);
|
290
|
|
}
|
291
|
|
}
|
292
|
|
}
|
293
|
|
}
|
294
|
|
|
295
|
|
|
296
|
|
|
297
|
|
|
298
|
|
|
299
|
|
|
300
|
|
|
301
|
46094
|
internal void Initialize(TypeHandlerFactory typeHandlerFactory, ErrorContext errorContext)
|
302
|
|
{
|
303
|
46094
|
if(_directionAttribute.Length >0)
|
304
|
|
{
|
305
|
0
|
_direction = (ParameterDirection)Enum.Parse( typeof(ParameterDirection), _directionAttribute, true );
|
306
|
|
}
|
307
|
|
|
308
|
46094
|
errorContext.MoreInfo = "Initialize an inline parameter property '" + this.PropertyName + "' .";
|
309
|
46094
|
if (this.CLRType.Length == 0 )
|
310
|
|
{
|
311
|
46094
|
_typeHandler = typeHandlerFactory.GetUnkownTypeHandler();
|
312
|
|
}
|
313
|
|
else
|
314
|
|
{
|
315
|
0
|
Type type = Resources.TypeForName(this.CLRType);
|
316
|
|
|
317
|
0
|
if (typeHandlerFactory.IsSimpleType(type))
|
318
|
|
{
|
319
|
|
|
320
|
|
_typeHandler = typeHandlerFactory.GetTypeHandler(type);
|
321
|
|
}
|
322
|
|
else
|
323
|
|
{
|
324
|
|
|
325
|
|
type = ObjectProbe.GetPropertyTypeForGetter(type, this.PropertyName);
|
326
|
|
_typeHandler = typeHandlerFactory.GetTypeHandler(type);
|
327
|
|
}
|
328
|
|
}
|
329
|
|
}
|
330
|
|
|
331
|
|
|
332
|
|
|
333
|
|
|
334
|
|
|
335
|
|
|
336
|
|
|
337
|
143845
|
public override bool Equals(object obj)
|
338
|
|
{
|
339
|
|
|
340
|
0
|
if (obj == null || GetType() != obj.GetType()) return false;
|
341
|
143845
|
ParameterProperty p = (ParameterProperty)obj;
|
342
|
143845
|
return (this.PropertyName == p.PropertyName);
|
343
|
|
}
|
344
|
|
|
345
|
|
|
346
|
|
|
347
|
|
|
348
|
|
|
349
|
6800
|
public override int GetHashCode()
|
350
|
|
{
|
351
|
6800
|
return _property.GetHashCode();
|
352
|
|
}
|
353
|
|
#endregion
|
354
|
|
|
355
|
|
}
|
356
|
|
}
|
357
|
|
|