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
|
|
using System;
|
29
|
|
using System.Data;
|
30
|
|
using System.Collections;
|
31
|
|
using System.Xml.Serialization;
|
32
|
|
using System.Reflection;
|
33
|
|
|
34
|
|
using IBatisNet.Common.Exceptions;
|
35
|
|
using IBatisNet.Common.Utilities.TypesResolver;
|
36
|
|
|
37
|
|
using IBatisNet.DataMapper.Configuration.Alias;
|
38
|
|
using IBatisNet.DataMapper.TypeHandlers;
|
39
|
|
using IBatisNet.DataMapper.Configuration.ResultMapping;
|
40
|
|
using IBatisNet.DataMapper.Configuration.ParameterMapping;
|
41
|
|
using IBatisNet.DataMapper.Configuration.Cache;
|
42
|
|
using IBatisNet.DataMapper.Configuration.Sql;
|
43
|
|
using IBatisNet.DataMapper.Exceptions;
|
44
|
|
using IBatisNet.DataMapper.Scope;
|
45
|
|
#endregion
|
46
|
|
|
47
|
|
namespace IBatisNet.DataMapper.Configuration.Statements
|
48
|
|
{
|
49
|
|
|
50
|
|
|
51
|
|
|
52
|
|
[Serializable]
|
53
|
|
[XmlRoot("statement")]
|
54
|
|
public class Statement : IStatement
|
55
|
|
{
|
56
|
|
#region Constants
|
57
|
|
private const string DOT = ".";
|
58
|
|
#endregion
|
59
|
|
|
60
|
|
#region Fields
|
61
|
|
|
62
|
|
[NonSerialized]
|
63
|
|
private string _id = string.Empty;
|
64
|
|
|
65
|
|
[NonSerialized]
|
66
|
|
private string _resultMapName = string.Empty;
|
67
|
|
[NonSerialized]
|
68
|
|
private ResultMap _resultMap = null;
|
69
|
|
|
70
|
|
[NonSerialized]
|
71
|
|
private string _parameterMapName = string.Empty;
|
72
|
|
[NonSerialized]
|
73
|
|
private ParameterMap _parameterMap = null;
|
74
|
|
|
75
|
|
[NonSerialized]
|
76
|
|
private string _resultClassName = string.Empty;
|
77
|
|
[NonSerialized]
|
78
|
|
private Type _resultClass = null;
|
79
|
|
|
80
|
|
[NonSerialized]
|
81
|
|
private string _parameterClassName = string.Empty;
|
82
|
|
[NonSerialized]
|
83
|
|
private Type _parameterClass = null;
|
84
|
|
|
85
|
|
[NonSerialized]
|
86
|
|
private string _listClassName = string.Empty;
|
87
|
|
[NonSerialized]
|
88
|
|
private Type _listClass = null;
|
89
|
|
|
90
|
|
[NonSerialized]
|
91
|
|
private string _cacheModelName = string.Empty;
|
92
|
|
[NonSerialized]
|
93
|
|
private CacheModel _cacheModel = null;
|
94
|
|
[NonSerialized]
|
95
|
|
private ISql _sql = null;
|
96
|
|
[NonSerialized]
|
97
|
|
private string _extendStatement = string.Empty;
|
98
|
|
#endregion
|
99
|
|
|
100
|
|
#region Properties
|
101
|
|
|
102
|
|
|
103
|
|
|
104
|
|
|
105
|
|
[XmlAttribute("extends")]
|
106
|
|
public virtual string ExtendSatement
|
107
|
|
{
|
108
|
22780
|
get { return _extendStatement; }
|
109
|
510
|
set { _extendStatement = value; }
|
110
|
|
}
|
111
|
|
|
112
|
|
|
113
|
|
|
114
|
|
|
115
|
|
[XmlAttribute("cacheModel")]
|
116
|
|
public string CacheModelName
|
117
|
|
{
|
118
|
53210
|
get { return _cacheModelName; }
|
119
|
26180
|
set { _cacheModelName = value; }
|
120
|
|
}
|
121
|
|
|
122
|
|
|
123
|
|
|
124
|
|
|
125
|
0
|
[XmlIgnoreAttribute]
|
126
|
|
public bool HasCacheModel
|
127
|
|
{
|
128
|
|
get{ return _cacheModelName.Length >0;}
|
129
|
|
}
|
130
|
|
|
131
|
|
|
132
|
|
|
133
|
|
|
134
|
|
[XmlIgnoreAttribute]
|
135
|
|
public CacheModel CacheModel
|
136
|
|
{
|
137
|
258
|
get { return _cacheModel; }
|
138
|
510
|
set { _cacheModel = value; }
|
139
|
|
}
|
140
|
|
|
141
|
|
|
142
|
|
|
143
|
|
|
144
|
|
[XmlAttribute("listClass")]
|
145
|
|
public string ListClassName
|
146
|
|
{
|
147
|
0
|
get { return _listClassName; }
|
148
|
340
|
set { _listClassName = value; }
|
149
|
|
}
|
150
|
|
|
151
|
|
|
152
|
|
|
153
|
|
|
154
|
|
|
155
|
|
[XmlIgnoreAttribute]
|
156
|
|
public Type ListClass
|
157
|
|
{
|
158
|
89
|
get { return _listClass; }
|
159
|
|
}
|
160
|
|
|
161
|
|
|
162
|
|
|
163
|
|
|
164
|
|
[XmlAttribute("resultClass")]
|
165
|
|
public string ResultClassName
|
166
|
|
{
|
167
|
0
|
get { return _resultClassName; }
|
168
|
12580
|
set { _resultClassName = value; }
|
169
|
|
}
|
170
|
|
|
171
|
|
|
172
|
|
|
173
|
|
|
174
|
|
[XmlIgnoreAttribute]
|
175
|
|
public Type ResultClass
|
176
|
|
{
|
177
|
431
|
get { return _resultClass; }
|
178
|
|
}
|
179
|
|
|
180
|
|
|
181
|
|
|
182
|
|
|
183
|
|
[XmlAttribute("parameterClass")]
|
184
|
|
public string ParameterClassName
|
185
|
|
{
|
186
|
0
|
get { return _parameterClassName; }
|
187
|
17170
|
set { _parameterClassName = value; }
|
188
|
|
}
|
189
|
|
|
190
|
|
|
191
|
|
|
192
|
|
|
193
|
|
[XmlIgnoreAttribute]
|
194
|
|
public Type ParameterClass
|
195
|
|
{
|
196
|
17850
|
get { return _parameterClass; }
|
197
|
|
}
|
198
|
|
|
199
|
|
|
200
|
|
|
201
|
|
|
202
|
|
[XmlAttribute("id")]
|
203
|
|
public string Id
|
204
|
|
{
|
205
|
67125
|
get { return _id; }
|
206
|
26520
|
set
|
207
|
|
{
|
208
|
26520
|
if ((value == null) || (value.Length < 1))
|
209
|
0
|
throw new DataMapperException("The id attribute is required in a statement tag.");
|
210
|
|
|
211
|
26520
|
_id= value;
|
212
|
|
}
|
213
|
|
}
|
214
|
|
|
215
|
|
|
216
|
|
|
217
|
|
|
218
|
|
|
219
|
|
[XmlIgnoreAttribute]
|
220
|
|
public ISql Sql
|
221
|
|
{
|
222
|
309
|
get { return _sql; }
|
223
|
26520
|
set
|
224
|
|
{
|
225
|
26520
|
if (value == null)
|
226
|
0
|
throw new DataMapperException("The sql statement query text is required in the statement tag "+_id);
|
227
|
|
|
228
|
26520
|
_sql = value;
|
229
|
|
}
|
230
|
|
}
|
231
|
|
|
232
|
|
|
233
|
|
|
234
|
|
|
235
|
|
|
236
|
|
[XmlAttribute("resultMap")]
|
237
|
|
public string ResultMapName
|
238
|
|
{
|
239
|
25670
|
get { return _resultMapName; }
|
240
|
34510
|
set { _resultMapName = value; }
|
241
|
|
}
|
242
|
|
|
243
|
|
|
244
|
|
|
245
|
|
|
246
|
|
[XmlAttribute("parameterMap")]
|
247
|
|
public string ParameterMapName
|
248
|
|
{
|
249
|
25670
|
get { return _parameterMapName; }
|
250
|
29240
|
set { _parameterMapName = value; }
|
251
|
|
}
|
252
|
|
|
253
|
|
|
254
|
|
|
255
|
|
|
256
|
|
[XmlIgnoreAttribute]
|
257
|
|
public ResultMap ResultMap
|
258
|
|
{
|
259
|
309
|
get { return _resultMap; }
|
260
|
|
}
|
261
|
|
|
262
|
|
|
263
|
|
|
264
|
|
|
265
|
|
[XmlIgnoreAttribute]
|
266
|
|
public ParameterMap ParameterMap
|
267
|
|
{
|
268
|
44972
|
get { return _parameterMap; }
|
269
|
13600
|
set { _parameterMap = value; }
|
270
|
|
}
|
271
|
|
|
272
|
|
|
273
|
|
|
274
|
|
|
275
|
|
|
276
|
|
|
277
|
|
|
278
|
|
[XmlIgnoreAttribute]
|
279
|
|
public virtual CommandType CommandType
|
280
|
|
{
|
281
|
52932
|
get { return CommandType.Text; }
|
282
|
|
}
|
283
|
|
#endregion
|
284
|
|
|
285
|
|
#region Constructor (s) / Destructor
|
286
|
|
|
287
|
|
|
288
|
|
|
289
|
27370
|
[Obsolete("This public constructor with no parameter is not really obsolete, but is reserved for serialization.", false)]
|
290
|
|
public Statement() {}
|
291
|
|
#endregion
|
292
|
|
|
293
|
|
#region Methods
|
294
|
|
|
295
|
|
|
296
|
|
|
297
|
|
|
298
|
26520
|
internal virtual void Initialize(ConfigurationScope configurationScope)
|
299
|
|
{
|
300
|
26520
|
if (_resultMapName != string.Empty )
|
301
|
|
{
|
302
|
8840
|
_resultMap = configurationScope.SqlMapper.GetResultMap( _resultMapName);
|
303
|
|
}
|
304
|
26520
|
if (_parameterMapName != string.Empty )
|
305
|
|
{
|
306
|
3570
|
_parameterMap = configurationScope.SqlMapper.GetParameterMap( _parameterMapName);
|
307
|
|
}
|
308
|
26520
|
if (_resultClassName != string.Empty )
|
309
|
|
{
|
310
|
12580
|
_resultClass = configurationScope.SqlMapper.GetType(_resultClassName);
|
311
|
|
}
|
312
|
26520
|
if (_parameterClassName != string.Empty )
|
313
|
|
{
|
314
|
17170
|
_parameterClass = configurationScope.SqlMapper.GetType(_parameterClassName);
|
315
|
|
}
|
316
|
26520
|
if (_listClassName != string.Empty )
|
317
|
|
{
|
318
|
340
|
_listClass = configurationScope.SqlMapper.GetType(_listClassName);
|
319
|
|
}
|
320
|
|
}
|
321
|
|
|
322
|
|
|
323
|
|
|
324
|
|
|
325
|
|
|
326
|
|
|
327
|
192
|
public object CreateInstanceOfResultClass()
|
328
|
|
{
|
329
|
192
|
if (_resultClass.IsPrimitive || _resultClass == typeof (string) )
|
330
|
|
{
|
331
|
26
|
TypeCode typeCode = Type.GetTypeCode(_resultClass);
|
332
|
26
|
return TypeAliasResolver.InstantiatePrimitiveType(typeCode);
|
333
|
|
}
|
334
|
|
else
|
335
|
|
{
|
336
|
166
|
if (_resultClass == typeof (Guid))
|
337
|
|
{
|
338
|
1
|
return Guid.Empty;
|
339
|
|
}
|
340
|
165
|
else if (_resultClass == typeof (TimeSpan))
|
341
|
|
{
|
342
|
0
|
return new TimeSpan(0);
|
343
|
|
}
|
344
|
|
else
|
345
|
|
{
|
346
|
165
|
return Activator.CreateInstance(_resultClass);
|
347
|
|
}
|
348
|
|
}
|
349
|
|
}
|
350
|
|
|
351
|
|
|
352
|
|
|
353
|
|
|
354
|
|
|
355
|
|
|
356
|
3
|
public IList CreateInstanceOfListClass()
|
357
|
|
{
|
358
|
3
|
return (IList)Activator.CreateInstance(_listClass);
|
359
|
|
}
|
360
|
|
#endregion
|
361
|
|
|
362
|
|
}
|
363
|
|
}
|
364
|
|
|