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.Collections.Specialized;
|
32
|
|
using System.Configuration;
|
33
|
|
using System.Xml;
|
34
|
|
using IBatisNet.Common;
|
35
|
|
using IBatisNet.Common.Utilities;
|
36
|
|
using IBatisNet.Common.Utilities.Objects;
|
37
|
|
using IBatisNet.DataMapper.TypeHandlers;
|
38
|
|
|
39
|
|
#endregion
|
40
|
|
|
41
|
|
namespace IBatisNet.DataMapper.Scope
|
42
|
|
{
|
43
|
|
|
44
|
|
|
45
|
|
|
46
|
|
public class ConfigurationScope
|
47
|
|
{
|
48
|
|
#region Fields
|
49
|
|
|
50
|
|
private ErrorContext _errorContext = null;
|
51
|
|
private HybridDictionary _providers = new HybridDictionary();
|
52
|
|
private NameValueCollection _properties = new NameValueCollection();
|
53
|
|
|
54
|
|
private XmlDocument _sqlMapConfigDocument = null;
|
55
|
|
private XmlDocument _sqlMapDocument = null;
|
56
|
|
private XmlNode _nodeContext = null;
|
57
|
|
|
58
|
|
private bool _useConfigFileWatcher = false;
|
59
|
|
private bool _useStatementNamespaces = false;
|
60
|
|
private bool _isCacheModelsEnabled = false;
|
61
|
|
private bool _useEmbedStatementParams = false;
|
62
|
|
private bool _validateSqlMap = false;
|
63
|
|
private bool _isCallFromDao = false;
|
64
|
|
|
65
|
|
private SqlMapper _sqlMapper = null;
|
66
|
|
private string _sqlMapNamespace = null;
|
67
|
|
private DataSource _dataSource = null;
|
68
|
|
private bool _isXmlValid = true;
|
69
|
|
|
70
|
|
#endregion
|
71
|
|
|
72
|
|
#region Constructors
|
73
|
|
|
74
|
|
|
75
|
|
|
76
|
|
|
77
|
170
|
public ConfigurationScope()
|
78
|
|
{
|
79
|
170
|
_errorContext = new ErrorContext();
|
80
|
|
|
81
|
170
|
_providers.Clear();
|
82
|
|
}
|
83
|
|
#endregion
|
84
|
|
|
85
|
|
#region Properties
|
86
|
|
|
87
|
|
|
88
|
|
|
89
|
|
|
90
|
|
public bool ValidateSqlMap
|
91
|
|
{
|
92
|
170
|
set
|
93
|
|
{
|
94
|
170
|
_validateSqlMap = value;
|
95
|
|
}
|
96
|
1870
|
get
|
97
|
|
{
|
98
|
1870
|
return _validateSqlMap;
|
99
|
|
}
|
100
|
|
}
|
101
|
|
|
102
|
|
|
103
|
|
|
104
|
|
|
105
|
|
public bool IsXmlValid
|
106
|
|
{
|
107
|
0
|
set
|
108
|
|
{
|
109
|
|
_isXmlValid = value;
|
110
|
|
}
|
111
|
170
|
get
|
112
|
|
{
|
113
|
170
|
return _isXmlValid;
|
114
|
|
}
|
115
|
|
}
|
116
|
|
|
117
|
|
|
118
|
|
|
119
|
|
|
120
|
|
|
121
|
|
public string SqlMapNamespace
|
122
|
|
{
|
123
|
1870
|
set
|
124
|
|
{
|
125
|
1870
|
_sqlMapNamespace = value;
|
126
|
|
}
|
127
|
107270
|
get
|
128
|
|
{
|
129
|
107270
|
return _sqlMapNamespace;
|
130
|
|
}
|
131
|
|
}
|
132
|
|
|
133
|
|
|
134
|
|
|
135
|
|
|
136
|
|
public SqlMapper SqlMapper
|
137
|
|
{
|
138
|
170
|
set
|
139
|
|
{
|
140
|
170
|
_sqlMapper = value;
|
141
|
|
}
|
142
|
147390
|
get
|
143
|
|
{
|
144
|
147390
|
return _sqlMapper;
|
145
|
|
}
|
146
|
|
}
|
147
|
|
|
148
|
|
|
149
|
|
|
150
|
|
|
151
|
|
internal TypeHandlerFactory TypeHandlerFactory
|
152
|
|
{
|
153
|
134300
|
get
|
154
|
|
{
|
155
|
134300
|
return _sqlMapper.TypeHandlerFactory;
|
156
|
|
}
|
157
|
|
}
|
158
|
|
|
159
|
|
|
160
|
|
|
161
|
|
|
162
|
|
public bool IsCallFromDao
|
163
|
|
{
|
164
|
170
|
set
|
165
|
|
{
|
166
|
170
|
_isCallFromDao = value;
|
167
|
|
}
|
168
|
680
|
get
|
169
|
|
{
|
170
|
680
|
return _isCallFromDao;
|
171
|
|
}
|
172
|
|
}
|
173
|
|
|
174
|
|
|
175
|
|
|
176
|
|
|
177
|
|
public bool IsCacheModelsEnabled
|
178
|
|
{
|
179
|
170
|
set
|
180
|
|
{
|
181
|
170
|
_isCacheModelsEnabled = value;
|
182
|
|
}
|
183
|
2210
|
get
|
184
|
|
{
|
185
|
2210
|
return _isCacheModelsEnabled;
|
186
|
|
}
|
187
|
|
}
|
188
|
|
|
189
|
|
|
190
|
|
|
191
|
|
|
192
|
|
|
193
|
|
public DataSource DataSource
|
194
|
|
{
|
195
|
340
|
set
|
196
|
|
{
|
197
|
340
|
_dataSource = value;
|
198
|
|
}
|
199
|
41820
|
get
|
200
|
|
{
|
201
|
41820
|
return _dataSource;
|
202
|
|
}
|
203
|
|
}
|
204
|
|
|
205
|
|
|
206
|
|
|
207
|
|
|
208
|
|
public XmlNode NodeContext
|
209
|
|
{
|
210
|
39610
|
set
|
211
|
|
{
|
212
|
39610
|
_nodeContext = value;
|
213
|
|
}
|
214
|
58480
|
get
|
215
|
|
{
|
216
|
58480
|
return _nodeContext;
|
217
|
|
}
|
218
|
|
}
|
219
|
|
|
220
|
|
|
221
|
|
|
222
|
|
|
223
|
|
public XmlDocument SqlMapConfigDocument
|
224
|
|
{
|
225
|
170
|
set
|
226
|
|
{
|
227
|
170
|
_sqlMapConfigDocument = value;
|
228
|
|
}
|
229
|
1190
|
get
|
230
|
|
{
|
231
|
1190
|
return _sqlMapConfigDocument;
|
232
|
|
}
|
233
|
|
}
|
234
|
|
|
235
|
|
|
236
|
|
|
237
|
|
|
238
|
|
public XmlDocument SqlMapDocument
|
239
|
|
{
|
240
|
1870
|
set
|
241
|
|
{
|
242
|
1870
|
_sqlMapDocument = value;
|
243
|
|
}
|
244
|
21250
|
get
|
245
|
|
{
|
246
|
21250
|
return _sqlMapDocument;
|
247
|
|
}
|
248
|
|
}
|
249
|
|
|
250
|
|
|
251
|
|
|
252
|
|
|
253
|
|
public bool UseConfigFileWatcher
|
254
|
|
{
|
255
|
170
|
set
|
256
|
|
{
|
257
|
170
|
_useConfigFileWatcher = value;
|
258
|
|
}
|
259
|
1870
|
get
|
260
|
|
{
|
261
|
1870
|
return _useConfigFileWatcher;
|
262
|
|
}
|
263
|
|
}
|
264
|
|
|
265
|
|
|
266
|
|
|
267
|
|
|
268
|
|
public bool UseStatementNamespaces
|
269
|
|
{
|
270
|
170
|
set
|
271
|
|
{
|
272
|
170
|
_useStatementNamespaces = value;
|
273
|
|
}
|
274
|
26010
|
get
|
275
|
|
{
|
276
|
26010
|
return _useStatementNamespaces;
|
277
|
|
}
|
278
|
|
}
|
279
|
|
|
280
|
|
|
281
|
|
|
282
|
|
|
283
|
|
public ErrorContext ErrorContext
|
284
|
|
{
|
285
|
277100
|
get
|
286
|
|
{
|
287
|
277100
|
return _errorContext;
|
288
|
|
}
|
289
|
|
}
|
290
|
|
|
291
|
|
|
292
|
|
|
293
|
|
|
294
|
|
public HybridDictionary Providers
|
295
|
|
{
|
296
|
2040
|
get
|
297
|
|
{
|
298
|
2040
|
return _providers;
|
299
|
|
}
|
300
|
|
}
|
301
|
|
|
302
|
|
|
303
|
|
|
304
|
|
|
305
|
|
public NameValueCollection Properties
|
306
|
|
{
|
307
|
37060
|
get
|
308
|
|
{
|
309
|
37060
|
return _properties;
|
310
|
|
}
|
311
|
|
}
|
312
|
|
|
313
|
|
|
314
|
|
|
315
|
|
|
316
|
|
public bool UseEmbedStatementParams
|
317
|
|
{
|
318
|
170
|
get
|
319
|
|
{
|
320
|
170
|
return _useEmbedStatementParams;
|
321
|
|
}
|
322
|
0
|
set
|
323
|
|
{
|
324
|
|
_useEmbedStatementParams = value;
|
325
|
|
}
|
326
|
|
}
|
327
|
|
|
328
|
|
#endregion
|
329
|
|
|
330
|
|
|
331
|
|
|
332
|
|
|
333
|
|
|
334
|
|
|
335
|
|
|
336
|
|
|
337
|
|
|
338
|
24310
|
public ITypeHandler ResolveTypeHandler(Type clazz, string propertyName, string clrType, string dbType)
|
339
|
|
{
|
340
|
24310
|
ITypeHandler handler = null;
|
341
|
24310
|
if (clazz==null)
|
342
|
|
{
|
343
|
0
|
handler = this.TypeHandlerFactory.GetUnkownTypeHandler();
|
344
|
|
}
|
345
|
24310
|
else if (typeof(IDictionary).IsAssignableFrom(clazz))
|
346
|
|
{
|
347
|
|
|
348
|
2210
|
if (clrType.Length == 0)
|
349
|
|
{
|
350
|
680
|
handler = this.TypeHandlerFactory.GetUnkownTypeHandler();
|
351
|
|
}
|
352
|
|
else
|
353
|
|
{
|
354
|
1530
|
try
|
355
|
|
{
|
356
|
1530
|
Type type = Resources.TypeForName(clrType);
|
357
|
1530
|
handler = this.TypeHandlerFactory.GetTypeHandler(type, dbType);
|
358
|
|
}
|
359
|
|
catch (Exception e)
|
360
|
|
{
|
361
|
0
|
throw new ConfigurationException("Error. Could not set TypeHandler. Cause: " + e.Message, e);
|
362
|
|
}
|
363
|
|
}
|
364
|
|
}
|
365
|
22100
|
else if (this.TypeHandlerFactory.GetTypeHandler(clazz, dbType) != null)
|
366
|
|
{
|
367
|
|
|
368
|
510
|
handler = this.TypeHandlerFactory.GetTypeHandler(clazz, dbType);
|
369
|
|
}
|
370
|
|
else
|
371
|
|
{
|
372
|
|
|
373
|
21590
|
if (clrType.Length == 0)
|
374
|
|
{
|
375
|
21250
|
Type type = ObjectProbe.GetPropertyTypeForGetter(clazz, propertyName);
|
376
|
21250
|
handler = this.TypeHandlerFactory.GetTypeHandler(type, dbType);
|
377
|
|
}
|
378
|
|
else
|
379
|
|
{
|
380
|
340
|
try
|
381
|
|
{
|
382
|
340
|
Type type = Resources.TypeForName(clrType);
|
383
|
340
|
handler = this.TypeHandlerFactory.GetTypeHandler(type, dbType);
|
384
|
|
}
|
385
|
|
catch (Exception e)
|
386
|
|
{
|
387
|
0
|
throw new ConfigurationException("Error. Could not set TypeHandler. Cause: " + e.Message, e);
|
388
|
|
}
|
389
|
|
}
|
390
|
|
}
|
391
|
|
|
392
|
24310
|
return handler;
|
393
|
|
}
|
394
|
|
}
|
395
|
|
}
|
396
|
|
|