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 Imports
|
28
|
|
using System;
|
29
|
|
using System.Data;
|
30
|
|
using System.Collections;
|
31
|
|
using System.Text;
|
32
|
|
using System.Reflection;
|
33
|
|
|
34
|
|
using IBatisNet.Common;
|
35
|
|
using IBatisNet.Common.Utilities;
|
36
|
|
using IBatisNet.Common.Utilities.Objects;
|
37
|
|
|
38
|
|
using IBatisNet.DataMapper;
|
39
|
|
using IBatisNet.DataMapper.Commands;
|
40
|
|
using IBatisNet.DataMapper.Configuration;
|
41
|
|
using IBatisNet.DataMapper.Configuration.Statements;
|
42
|
|
using IBatisNet.DataMapper.Configuration.ResultMapping;
|
43
|
|
using IBatisNet.DataMapper.Configuration.ParameterMapping;
|
44
|
|
using IBatisNet.DataMapper.Configuration.Sql.SimpleDynamic;
|
45
|
|
using IBatisNet.DataMapper.Configuration.Sql.Static;
|
46
|
|
using IBatisNet.DataMapper.TypeHandlers;
|
47
|
|
using IBatisNet.DataMapper.Exceptions;
|
48
|
|
using IBatisNet.DataMapper.Scope;
|
49
|
|
|
50
|
|
using log4net;
|
51
|
|
#endregion
|
52
|
|
|
53
|
|
namespace IBatisNet.DataMapper.MappedStatements
|
54
|
|
{
|
55
|
|
|
56
|
|
|
57
|
|
|
58
|
|
|
59
|
|
public class MappedStatement : IMappedStatement
|
60
|
|
{
|
61
|
|
|
62
|
|
|
63
|
|
|
64
|
|
public event ExecuteEventHandler Execute;
|
65
|
|
|
66
|
|
|
67
|
|
|
68
|
|
|
69
|
|
private enum ExecuteMethod : int
|
70
|
|
{
|
71
|
|
ExecuteQueryForObject =0,
|
72
|
|
ExecuteQueryForIList,
|
73
|
|
ExecuteQueryForArrayList,
|
74
|
|
ExecuteQueryForStrongTypedIList
|
75
|
|
}
|
76
|
|
|
77
|
|
|
78
|
|
|
79
|
|
|
80
|
|
|
81
|
|
|
82
|
|
|
83
|
|
|
84
|
|
|
85
|
|
private class PostBindind
|
86
|
|
{
|
87
|
|
#region Fields
|
88
|
|
private MappedStatement _statement = null;
|
89
|
|
private ResultProperty _property = null;
|
90
|
|
private object _target = null;
|
91
|
|
private object _keys = null;
|
92
|
|
private ExecuteMethod _method = ExecuteMethod.ExecuteQueryForIList;
|
93
|
|
#endregion
|
94
|
|
|
95
|
|
#region Properties
|
96
|
|
|
97
|
|
|
98
|
|
|
99
|
|
public MappedStatement Statement
|
100
|
|
{
|
101
|
22
|
set { _statement = value; }
|
102
|
9
|
get { return _statement; }
|
103
|
|
}
|
104
|
|
|
105
|
|
|
106
|
|
|
107
|
|
|
108
|
|
public ResultProperty ResultProperty
|
109
|
|
{
|
110
|
22
|
set { _property = value; }
|
111
|
10
|
get { return _property; }
|
112
|
|
}
|
113
|
|
|
114
|
|
|
115
|
|
|
116
|
|
|
117
|
|
public object Target
|
118
|
|
{
|
119
|
22
|
set { _target = value; }
|
120
|
9
|
get { return _target; }
|
121
|
|
}
|
122
|
|
|
123
|
|
|
124
|
|
|
125
|
|
|
126
|
|
|
127
|
|
public object Keys
|
128
|
|
{
|
129
|
22
|
set { _keys = value; }
|
130
|
9
|
get { return _keys; }
|
131
|
|
}
|
132
|
|
|
133
|
|
|
134
|
|
|
135
|
|
|
136
|
|
public ExecuteMethod Method
|
137
|
|
{
|
138
|
9
|
set { _method = value; }
|
139
|
32
|
get { return _method; }
|
140
|
|
}
|
141
|
|
#endregion
|
142
|
|
|
143
|
|
}
|
144
|
|
|
145
|
|
|
146
|
|
#region Fields
|
147
|
|
|
148
|
|
|
149
|
|
private const int NO_MAXIMUM_RESULTS = -1;
|
150
|
|
|
151
|
|
private const int NO_SKIPPED_RESULTS = -1;
|
152
|
|
|
153
|
|
private static readonly ILog _logger = LogManager.GetLogger( System.Reflection.MethodBase.GetCurrentMethod().DeclaringType );
|
154
|
|
|
155
|
|
private IStatement _statement = null;
|
156
|
|
|
157
|
|
private SqlMapper _sqlMap = null;
|
158
|
|
|
159
|
|
private IPreparedCommand _preparedCommand = null;
|
160
|
|
|
161
|
|
#endregion
|
162
|
|
|
163
|
|
#region Properties
|
164
|
|
|
165
|
|
|
166
|
|
|
167
|
|
|
168
|
0
|
public IPreparedCommand PreparedCommand
|
169
|
|
{
|
170
|
|
get { return _preparedCommand; }
|
171
|
|
}
|
172
|
|
|
173
|
|
|
174
|
|
|
175
|
|
|
176
|
|
|
177
|
|
public string Name
|
178
|
|
{
|
179
|
26537
|
get { return _statement.Id; }
|
180
|
|
}
|
181
|
|
|
182
|
|
|
183
|
|
|
184
|
|
|
185
|
|
public IStatement Statement
|
186
|
|
{
|
187
|
28861
|
get { return _statement; }
|
188
|
|
}
|
189
|
|
|
190
|
|
|
191
|
|
|
192
|
|
|
193
|
|
public SqlMapper SqlMap
|
194
|
|
{
|
195
|
28
|
get { return _sqlMap; }
|
196
|
|
}
|
197
|
|
#endregion
|
198
|
|
|
199
|
|
#region Constructor (s) / Destructor
|
200
|
|
|
201
|
|
|
202
|
|
|
203
|
|
|
204
|
|
|
205
|
26520
|
internal MappedStatement( SqlMapper sqlMap, IStatement statement )
|
206
|
|
{
|
207
|
26520
|
_sqlMap = sqlMap;
|
208
|
26520
|
_statement = statement;
|
209
|
26520
|
_preparedCommand = PreparedCommandFactory.GetPreparedCommand(sqlMap.UseEmbedStatementParams);
|
210
|
|
}
|
211
|
|
#endregion
|
212
|
|
|
213
|
|
#region Methods
|
214
|
|
|
215
|
|
|
216
|
|
|
217
|
|
|
218
|
0
|
public double GetDataCacheHitRatio()
|
219
|
|
{
|
220
|
|
if (_statement.CacheModel != null)
|
221
|
|
{
|
222
|
|
return _statement.CacheModel.HitRatio;
|
223
|
|
}
|
224
|
|
else
|
225
|
|
{
|
226
|
|
return -1;
|
227
|
|
}
|
228
|
|
}
|
229
|
|
|
230
|
|
|
231
|
|
|
232
|
|
|
233
|
|
|
234
|
|
|
235
|
|
|
236
|
|
|
237
|
|
|
238
|
1
|
private void FillObjectWithReaderAndResultMap(RequestScope request,IDataReader reader, ResultMap resultMap, object resultObject)
|
239
|
|
{
|
240
|
|
|
241
|
1
|
foreach(DictionaryEntry entry in resultMap.ColumnsToPropertiesMap)
|
242
|
|
{
|
243
|
4
|
ResultProperty property = (ResultProperty)entry.Value;
|
244
|
4
|
SetObjectProperty(request, resultMap, property, ref resultObject, reader);
|
245
|
|
}
|
246
|
|
}
|
247
|
|
|
248
|
|
|
249
|
|
|
250
|
|
|
251
|
|
|
252
|
|
|
253
|
|
|
254
|
|
|
255
|
424
|
private object ApplyResultMap(RequestScope request, IDataReader reader, object resultObject)
|
256
|
|
{
|
257
|
424
|
object outObject = resultObject;
|
258
|
|
|
259
|
|
|
260
|
424
|
if (request.ResultMap != null)
|
261
|
|
{
|
262
|
232
|
ResultMap resultMap = request.GetResultMap(reader);
|
263
|
|
|
264
|
232
|
if (outObject == null)
|
265
|
|
{
|
266
|
231
|
outObject = resultMap.CreateInstanceOfResult();
|
267
|
|
}
|
268
|
|
|
269
|
|
|
270
|
232
|
foreach(DictionaryEntry entry in resultMap.ColumnsToPropertiesMap)
|
271
|
|
{
|
272
|
1226
|
ResultProperty property = (ResultProperty)entry.Value;
|
273
|
1226
|
SetObjectProperty(request, resultMap, property, ref outObject, reader);
|
274
|
|
}
|
275
|
|
}
|
276
|
|
else
|
277
|
|
{
|
278
|
192
|
if (_statement.ResultClass != null)
|
279
|
|
{
|
280
|
192
|
if (outObject == null)
|
281
|
|
{
|
282
|
192
|
outObject = _statement.CreateInstanceOfResultClass();
|
283
|
|
}
|
284
|
|
|
285
|
|
|
286
|
192
|
if (_sqlMap.TypeHandlerFactory.IsSimpleType(_statement.ResultClass))
|
287
|
|
{
|
288
|
|
|
289
|
30
|
ResultMap resultMap = new ResultMap();
|
290
|
|
|
291
|
|
|
292
|
30
|
ResultProperty property = new ResultProperty();
|
293
|
30
|
property.PropertyName = "value";
|
294
|
30
|
property.ColumnIndex = 0;
|
295
|
30
|
property.TypeHandler = _sqlMap.TypeHandlerFactory.GetTypeHandler(outObject.GetType());
|
296
|
|
|
297
|
30
|
resultMap.AddResultPropery(property);
|
298
|
|
|
299
|
30
|
SetObjectProperty(request, request.ResultMap, property, ref outObject, reader);
|
300
|
|
}
|
301
|
162
|
else if (outObject is Hashtable)
|
302
|
|
{
|
303
|
30
|
for (int i = 0; i < reader.FieldCount; i++)
|
304
|
|
{
|
305
|
24
|
string columnName = reader.GetName(i);
|
306
|
24
|
((Hashtable) outObject).Add(columnName, reader.GetValue(i));
|
307
|
|
}
|
308
|
|
}
|
309
|
|
else
|
310
|
|
{
|
311
|
156
|
AutoMapReader( reader, ref outObject);
|
312
|
|
}
|
313
|
|
}
|
314
|
|
}
|
315
|
|
|
316
|
424
|
return outObject;
|
317
|
|
}
|
318
|
|
|
319
|
|
|
320
|
|
|
321
|
|
|
322
|
|
|
323
|
|
|
324
|
|
|
325
|
|
|
326
|
|
|
327
|
|
|
328
|
|
|
329
|
300
|
private void RetrieveOutputParameters(RequestScope request, IDalSession session, IDbCommand command, object result)
|
330
|
|
{
|
331
|
300
|
if (request.ParameterMap != null)
|
332
|
|
{
|
333
|
741
|
for(int i=0; i<request.ParameterMap.PropertiesList.Count; i++)
|
334
|
|
{
|
335
|
499
|
ParameterProperty mapping = request.ParameterMap.GetProperty(i);
|
336
|
499
|
if (mapping.Direction == ParameterDirection.Output ||
|
337
|
|
mapping.Direction == ParameterDirection.InputOutput)
|
338
|
|
{
|
339
|
5
|
string parameterName = string.Empty;
|
340
|
5
|
if (session.DataSource.Provider.UseParameterPrefixInParameter == false)
|
341
|
|
{
|
342
|
0
|
parameterName = mapping.ColumnName;
|
343
|
|
}
|
344
|
|
else
|
345
|
|
{
|
346
|
5
|
parameterName = session.DataSource.Provider.ParameterPrefix +
|
347
|
|
mapping.ColumnName;
|
348
|
|
}
|
349
|
|
|
350
|
5
|
if (mapping.TypeHandler == null)
|
351
|
|
{
|
352
|
0
|
lock(mapping)
|
353
|
|
{
|
354
|
|
if (mapping.TypeHandler == null)
|
355
|
|
{
|
356
|
|
Type propertyType =ObjectProbe.GetPropertyTypeForGetter(result,mapping.PropertyName);
|
357
|
|
|
358
|
|
mapping.TypeHandler = _sqlMap.TypeHandlerFactory.GetTypeHandler(propertyType);
|
359
|
|
}
|
360
|
|
}
|
361
|
|
}
|
362
|
|
|
363
|
5
|
object dataBaseValue = mapping.TypeHandler.GetDataBaseValue( ((IDataParameter)command.Parameters[parameterName]).Value, result.GetType() );
|
364
|
|
|
365
|
5
|
ObjectProbe.SetPropertyValue(result, mapping.PropertyName, dataBaseValue);
|
366
|
|
}
|
367
|
|
}
|
368
|
|
}
|
369
|
|
}
|
370
|
|
|
371
|
|
|
372
|
|
#region ExecuteForObject
|
373
|
|
|
374
|
|
|
375
|
|
|
376
|
|
|
377
|
|
|
378
|
|
|
379
|
|
|
380
|
140
|
public virtual object ExecuteQueryForObject( IDalSession session, object parameterObject )
|
381
|
|
{
|
382
|
140
|
return ExecuteQueryForObject(session, parameterObject, null);
|
383
|
|
}
|
384
|
|
|
385
|
|
|
386
|
|
|
387
|
|
|
388
|
|
|
389
|
|
|
390
|
|
|
391
|
|
|
392
|
|
|
393
|
|
|
394
|
141
|
public virtual object ExecuteQueryForObject(IDalSession session, object parameterObject, object resultObject )
|
395
|
|
{
|
396
|
141
|
object obj = null;
|
397
|
141
|
RequestScope request = _statement.Sql.GetRequestScope(parameterObject, session);;
|
398
|
|
|
399
|
141
|
if (_statement.CacheModel == null)
|
400
|
|
{
|
401
|
140
|
obj = RunQueryForObject(request, session, parameterObject, resultObject);
|
402
|
|
}
|
403
|
|
else
|
404
|
|
{
|
405
|
1
|
CacheKey key = null;
|
406
|
1
|
if (_statement.ParameterMap != null)
|
407
|
|
{
|
408
|
1
|
key = new CacheKey(_sqlMap.TypeHandlerFactory, this.Name,
|
409
|
|
request.PreparedStatement.PreparedSql,
|
410
|
|
parameterObject,
|
411
|
|
request.ParameterMap.GetPropertyNameArray(),
|
412
|
|
NO_SKIPPED_RESULTS,
|
413
|
|
NO_MAXIMUM_RESULTS,
|
414
|
|
CacheKeyType.Object);
|
415
|
|
}
|
416
|
|
else
|
417
|
|
{
|
418
|
0
|
key = new CacheKey(_sqlMap.TypeHandlerFactory, this.Name,
|
419
|
|
request.PreparedStatement.PreparedSql,
|
420
|
|
parameterObject,
|
421
|
|
new string[0],
|
422
|
|
NO_SKIPPED_RESULTS,
|
423
|
|
NO_MAXIMUM_RESULTS,
|
424
|
|
CacheKeyType.Object);
|
425
|
|
}
|
426
|
|
|
427
|
1
|
obj = _statement.CacheModel[key];
|
428
|
1
|
if (obj == null)
|
429
|
|
{
|
430
|
1
|
obj = RunQueryForObject(request, session, parameterObject, resultObject);
|
431
|
1
|
_statement.CacheModel[key] = obj;
|
432
|
|
}
|
433
|
|
}
|
434
|
|
|
435
|
141
|
return obj;
|
436
|
|
}
|
437
|
|
|
438
|
|
|
439
|
|
|
440
|
|
|
441
|
|
|
442
|
|
|
443
|
|
|
444
|
|
|
445
|
|
|
446
|
|
|
447
|
|
|
448
|
141
|
private object RunQueryForObject(RequestScope request, IDalSession session, object parameterObject, object resultObject )
|
449
|
|
{
|
450
|
141
|
object result = resultObject;
|
451
|
|
|
452
|
|
|
453
|
141
|
using ( IDbCommand command = _preparedCommand.Create( request, session, this.Statement, parameterObject ) )
|
454
|
|
{
|
455
|
141
|
using ( IDataReader reader = command.ExecuteReader() )
|
456
|
|
{
|
457
|
141
|
if ( reader.Read() )
|
458
|
|
{
|
459
|
133
|
result = ApplyResultMap(request, reader, resultObject);
|
460
|
|
}
|
461
|
|
}
|
462
|
|
|
463
|
141
|
ExecutePostSelect( session, request);
|
464
|
|
|
465
|
|
#region remark
|
466
|
|
|
467
|
|
|
468
|
|
#endregion
|
469
|
|
|
470
|
141
|
RetrieveOutputParameters(request, session, command, parameterObject);
|
471
|
|
}
|
472
|
|
|
473
|
141
|
return result;
|
474
|
|
}
|
475
|
|
|
476
|
|
#endregion
|
477
|
|
|
478
|
|
#region ExecuteQueryForList
|
479
|
|
|
480
|
|
|
481
|
|
|
482
|
|
|
483
|
|
|
484
|
|
|
485
|
|
|
486
|
|
|
487
|
1
|
public virtual IList ExecuteQueryForRowDelegate( IDalSession session, object parameterObject, SqlMapper.RowDelegate rowDelegate )
|
488
|
|
{
|
489
|
1
|
RequestScope request = _statement.Sql.GetRequestScope(parameterObject, session);;
|
490
|
|
|
491
|
1
|
if (rowDelegate == null)
|
492
|
|
{
|
493
|
0
|
throw new DataMapperException("A null RowDelegate was passed to QueryForRowDelegate.");
|
494
|
|
}
|
495
|
|
|
496
|
1
|
return RunQueryForList(request, session, parameterObject, NO_SKIPPED_RESULTS, NO_MAXIMUM_RESULTS, rowDelegate);
|
497
|
|
}
|
498
|
|
|
499
|
|
|
500
|
|
|
501
|
|
|
502
|
|
|
503
|
|
|
504
|
|
|
505
|
|
|
506
|
|
|
507
|
78
|
public virtual IList ExecuteQueryForList( IDalSession session, object parameterObject )
|
508
|
|
{
|
509
|
78
|
return ExecuteQueryForList( session, parameterObject, NO_SKIPPED_RESULTS, NO_MAXIMUM_RESULTS);
|
510
|
|
}
|
511
|
|
|
512
|
|
|
513
|
|
|
514
|
|
|
515
|
|
|
516
|
|
|
517
|
|
|
518
|
|
|
519
|
|
|
520
|
|
|
521
|
93
|
public virtual IList ExecuteQueryForList( IDalSession session, object parameterObject, int skipResults, int maxResults )
|
522
|
|
{
|
523
|
93
|
IList list = null;
|
524
|
93
|
RequestScope request = _statement.Sql.GetRequestScope(parameterObject, session);;
|
525
|
|
|
526
|
93
|
if (_statement.CacheModel == null)
|
527
|
|
{
|
528
|
81
|
list = RunQueryForList(request, session, parameterObject, skipResults, maxResults, null);
|
529
|
|
}
|
530
|
|
else
|
531
|
|
{
|
532
|
12
|
CacheKey key = null;
|
533
|
12
|
if (_statement.ParameterMap != null)
|
534
|
|
{
|
535
|
0
|
key = new CacheKey(_sqlMap.TypeHandlerFactory, this.Name,
|
536
|
|
request.PreparedStatement.PreparedSql,
|
537
|
|
parameterObject,
|
538
|
|
request.ParameterMap.GetPropertyNameArray(),
|
539
|
|
skipResults,
|
540
|
|
maxResults,
|
541
|
|
CacheKeyType.List);
|
542
|
|
}
|
543
|
|
else
|
544
|
|
{
|
545
|
12
|
key = new CacheKey(_sqlMap.TypeHandlerFactory, this.Name,
|
546
|
|
request.PreparedStatement.PreparedSql,
|
547
|
|
parameterObject,
|
548
|
|
new string[0],
|
549
|
|
skipResults,
|
550
|
|
maxResults,
|
551
|
|
CacheKeyType.List);
|
552
|
|
}
|
553
|
|
|
554
|
12
|
list = (IList)_statement.CacheModel[key];
|
555
|
12
|
if (list == null)
|
556
|
|
{
|
557
|
7
|
list = RunQueryForList(request, session, parameterObject, skipResults, maxResults, null);
|
558
|
7
|
_statement.CacheModel[key] = list;
|
559
|
|
}
|
560
|
|
}
|
561
|
|
|
562
|
93
|
return list;
|
563
|
|
}
|
564
|
|
|
565
|
|
|
566
|
|
|
567
|
|
|
568
|
|
|
569
|
|
|
570
|
|
|
571
|
|
|
572
|
|
|
573
|
|
|
574
|
|
|
575
|
|
|
576
|
89
|
private IList RunQueryForList(RequestScope request, IDalSession session, object parameterObject, int skipResults, int maxResults, SqlMapper.RowDelegate rowDelegate)
|
577
|
|
{
|
578
|
89
|
IList list = null;
|
579
|
|
|
580
|
|
|
581
|
89
|
using ( IDbCommand command = _preparedCommand.Create( request, session, this.Statement, parameterObject ) )
|
582
|
|
{
|
583
|
89
|
if (_statement.ListClass == null)
|
584
|
|
{
|
585
|
86
|
list = new ArrayList();
|
586
|
|
}
|
587
|
|
else
|
588
|
|
{
|
589
|
3
|
list = _statement.CreateInstanceOfListClass();
|
590
|
|
}
|
591
|
|
|
592
|
89
|
using ( IDataReader reader = command.ExecuteReader() )
|
593
|
|
{
|
594
|
|
|
595
|
116
|
for (int i = 0; i < skipResults; i++)
|
596
|
|
{
|
597
|
28
|
if (!reader.Read())
|
598
|
|
{
|
599
|
1
|
break;
|
600
|
|
}
|
601
|
|
}
|
602
|
|
|
603
|
89
|
int n = 0;
|
604
|
|
|
605
|
89
|
if (rowDelegate == null)
|
606
|
|
{
|
607
|
369
|
while ( (maxResults == NO_MAXIMUM_RESULTS || n < maxResults)
|
608
|
|
&& reader.Read() )
|
609
|
|
{
|
610
|
281
|
object obj = ApplyResultMap(request, reader, null);
|
611
|
|
|
612
|
281
|
list.Add( obj );
|
613
|
281
|
n++;
|
614
|
|
}
|
615
|
|
}
|
616
|
|
else
|
617
|
|
{
|
618
|
6
|
while ( (maxResults == NO_MAXIMUM_RESULTS || n < maxResults)
|
619
|
|
&& reader.Read() )
|
620
|
|
{
|
621
|
5
|
object obj = ApplyResultMap(request, reader, null);
|
622
|
|
|
623
|
5
|
rowDelegate(obj, list);
|
624
|
5
|
n++;
|
625
|
|
}
|
626
|
|
}
|
627
|
|
}
|
628
|
|
|
629
|
89
|
ExecutePostSelect( session, request);
|
630
|
|
|
631
|
89
|
RetrieveOutputParameters(request, session, command, parameterObject);
|
632
|
|
}
|
633
|
|
|
634
|
89
|
return list;
|
635
|
|
}
|
636
|
|
|
637
|
|
|
638
|
|
|
639
|
|
|
640
|
|
|
641
|
|
|
642
|
|
|
643
|
|
|
644
|
1
|
public virtual void ExecuteQueryForList(IDalSession session, object parameterObject, IList resultObject )
|
645
|
|
{
|
646
|
1
|
RequestScope request = _statement.Sql.GetRequestScope(parameterObject, session);;
|
647
|
|
|
648
|
|
|
649
|
1
|
using ( IDbCommand command = _preparedCommand.Create( request, session, this.Statement, parameterObject ) )
|
650
|
|
{
|
651
|
1
|
using ( IDataReader reader = command.ExecuteReader() )
|
652
|
|
{
|
653
|
6
|
while ( reader.Read() )
|
654
|
|
{
|
655
|
5
|
object obj = ApplyResultMap(request, reader, null);
|
656
|
|
|
657
|
5
|
resultObject.Add( obj );
|
658
|
|
}
|
659
|
|
}
|
660
|
|
|
661
|
1
|
ExecutePostSelect( session, request);
|
662
|
|
|
663
|
1
|
RetrieveOutputParameters(request, session, command, parameterObject);
|
664
|
|
}
|
665
|
|
}
|
666
|
|
|
667
|
|
|
668
|
|
#endregion
|
669
|
|
|
670
|
|
#region ExecuteUpdate, ExecuteInsert
|
671
|
|
|
672
|
|
|
673
|
|
|
674
|
|
|
675
|
|
|
676
|
|
|
677
|
|
|
678
|
|
|
679
|
13
|
public virtual int ExecuteUpdate(IDalSession session, object parameterObject )
|
680
|
|
{
|
681
|
13
|
int rows = 0;
|
682
|
13
|
RequestScope request = _statement.Sql.GetRequestScope(parameterObject, session);;
|
683
|
|
|
684
|
|
|
685
|
13
|
using ( IDbCommand command = _preparedCommand.Create( request, session, this.Statement, parameterObject ) )
|
686
|
|
{
|
687
|
12
|
rows = command.ExecuteNonQuery();
|
688
|
|
|
689
|
12
|
ExecutePostSelect( session, request);
|
690
|
|
|
691
|
12
|
RetrieveOutputParameters(request, session, command, parameterObject);
|
692
|
|
}
|
693
|
|
|
694
|
12
|
RaiseExecuteEvent();
|
695
|
|
|
696
|
12
|
return rows;
|
697
|
|
}
|
698
|
|
|
699
|
|
|
700
|
|
|
701
|
|
|
702
|
|
|
703
|
|
|
704
|
|
|
705
|
|
|
706
|
|
|
707
|
57
|
public virtual object ExecuteInsert(IDalSession session, object parameterObject )
|
708
|
|
{
|
709
|
57
|
object generatedKey = null;
|
710
|
57
|
SelectKey selectKeyStatement = null;
|
711
|
57
|
RequestScope request = _statement.Sql.GetRequestScope(parameterObject, session);;
|
712
|
|
|
713
|
57
|
if (_statement is Insert)
|
714
|
|
{
|
715
|
34
|
selectKeyStatement = ((Insert)_statement).SelectKey;
|
716
|
|
}
|
717
|
|
|
718
|
57
|
if (selectKeyStatement != null && !selectKeyStatement.isAfter)
|
719
|
|
{
|
720
|
1
|
MappedStatement mappedStatement = _sqlMap.GetMappedStatement( selectKeyStatement.Id );
|
721
|
1
|
generatedKey = mappedStatement.ExecuteQueryForObject(session, parameterObject);
|
722
|
|
|
723
|
1
|
ObjectProbe.SetPropertyValue(parameterObject, selectKeyStatement.PropertyName, generatedKey);
|
724
|
|
}
|
725
|
|
|
726
|
|
|
727
|
57
|
using ( IDbCommand command = _preparedCommand.Create( request, session, this.Statement, parameterObject ) )
|
728
|
|
{
|
729
|
57
|
if (_statement is Insert)
|
730
|
|
{
|
731
|
34
|
command.ExecuteNonQuery();
|
732
|
|
}
|
733
|
|
else
|
734
|
|
{
|
735
|
23
|
generatedKey = command.ExecuteScalar();
|
736
|
23
|
if ( (_statement.ResultClass!=null) &&
|
737
|
|
_sqlMap.TypeHandlerFactory.IsSimpleType(_statement.ResultClass) )
|
738
|
|
{
|
739
|
8
|
ITypeHandler typeHandler = _sqlMap.TypeHandlerFactory.GetTypeHandler(_statement.ResultClass);
|
740
|
8
|
generatedKey = typeHandler.GetDataBaseValue(generatedKey, _statement.ResultClass);
|
741
|
|
}
|
742
|
|
}
|
743
|
|
|
744
|
57
|
if (selectKeyStatement != null && selectKeyStatement.isAfter)
|
745
|
|
{
|
746
|
9
|
MappedStatement mappedStatement = _sqlMap.GetMappedStatement( selectKeyStatement.Id );
|
747
|
9
|
generatedKey = mappedStatement.ExecuteQueryForObject(session, parameterObject);
|
748
|
|
|
749
|
9
|
ObjectProbe.SetPropertyValue(parameterObject, selectKeyStatement.PropertyName, generatedKey);
|
750
|
|
}
|
751
|
|
|
752
|
57
|
ExecutePostSelect( session, request);
|
753
|
|
|
754
|
57
|
RetrieveOutputParameters(request, session, command, parameterObject);
|
755
|
|
}
|
756
|
|
|
757
|
57
|
RaiseExecuteEvent();
|
758
|
|
|
759
|
57
|
return generatedKey;
|
760
|
|
}
|
761
|
|
|
762
|
|
#endregion
|
763
|
|
|
764
|
|
#region ExecuteQueryForMap
|
765
|
|
|
766
|
|
|
767
|
|
|
768
|
|
|
769
|
|
|
770
|
|
|
771
|
|
|
772
|
|
|
773
|
|
|
774
|
|
|
775
|
|
|
776
|
|
|
777
|
|
|
778
|
|
|
779
|
|
|
780
|
|
|
781
|
|
|
782
|
|
|
783
|
|
|
784
|
|
|
785
|
|
|
786
|
|
|
787
|
3
|
public virtual IDictionary ExecuteQueryForMap( IDalSession session, object parameterObject, string keyProperty, string valueProperty )
|
788
|
|
{
|
789
|
3
|
IDictionary map = new Hashtable();
|
790
|
3
|
RequestScope request = _statement.Sql.GetRequestScope(parameterObject, session);;
|
791
|
|
|
792
|
3
|
if (_statement.CacheModel == null)
|
793
|
|
{
|
794
|
3
|
map = RunQueryForMap(request, session, parameterObject, keyProperty, valueProperty );
|
795
|
|
}
|
796
|
|
else
|
797
|
|
{
|
798
|
0
|
CacheKey key = null;
|
799
|
0
|
if (_statement.ParameterMap != null)
|
800
|
|
{
|
801
|
|
key = new CacheKey(_sqlMap.TypeHandlerFactory, this.Name,
|
802
|
|
request.PreparedStatement.PreparedSql,
|
803
|
|
parameterObject,
|
804
|
|
request.ParameterMap.GetPropertyNameArray(),
|
805
|
|
NO_SKIPPED_RESULTS,
|
806
|
|
NO_MAXIMUM_RESULTS,
|
807
|
|
CacheKeyType.Map);
|
808
|
|
}
|
809
|
|
else
|
810
|
|
{
|
811
|
|
key = new CacheKey(_sqlMap.TypeHandlerFactory, this.Name,
|
812
|
|
request.PreparedStatement.PreparedSql,
|
813
|
|
parameterObject,
|
814
|
|
new string[0],
|
815
|
|
NO_SKIPPED_RESULTS,
|
816
|
|
NO_MAXIMUM_RESULTS,
|
817
|
|
CacheKeyType.Map);
|
818
|
|
}
|
819
|
|
|
820
|
0
|
map = (IDictionary)_statement.CacheModel[key];
|
821
|
0
|
if (map == null)
|
822
|
|
{
|
823
|
|
map = RunQueryForMap( request, session, parameterObject, keyProperty, valueProperty );
|
824
|
|
_statement.CacheModel[key] = map;
|
825
|
|
}
|
826
|
|
}
|
827
|
|
|
828
|
3
|
return map;
|
829
|
|
}
|
830
|
|
|
831
|
|
|
832
|
|
|
833
|
|
|
834
|
|
|
835
|
|
|
836
|
|
|
837
|
|
|
838
|
|
|
839
|
|
|
840
|
|
|
841
|
|
|
842
|
|
|
843
|
|
|
844
|
3
|
private IDictionary RunQueryForMap( RequestScope request, IDalSession session,
|
845
|
|
object parameterObject, string keyProperty, string valueProperty )
|
846
|
|
{
|
847
|
3
|
IDictionary map = new Hashtable();
|
848
|
|
|
849
|
3
|
IList list = ExecuteQueryForList(session, parameterObject);
|
850
|
|
|
851
|
23
|
for(int i =0; i<list.Count; i++)
|
852
|
|
{
|
853
|
20
|
object obj = list[i];
|
854
|
20
|
if (obj != null)
|
855
|
|
{
|
856
|
20
|
object key = ObjectProbe.GetPropertyValue(obj, keyProperty);
|
857
|
|
|
858
|
20
|
object value = obj;
|
859
|
20
|
if (valueProperty != null)
|
860
|
|
{
|
861
|
5
|
value = ObjectProbe.GetPropertyValue(obj, valueProperty);
|
862
|
|
}
|
863
|
20
|
map.Add(key, value);
|
864
|
|
}
|
865
|
|
}
|
866
|
|
|
867
|
3
|
return map;
|
868
|
|
}
|
869
|
|
|
870
|
|
|
871
|
|
#endregion
|
872
|
|
|
873
|
|
|
874
|
|
|
875
|
|
|
876
|
|
|
877
|
|
|
878
|
300
|
private void ExecutePostSelect(IDalSession session, RequestScope request)
|
879
|
|
{
|
880
|
309
|
while (request.QueueSelect.Count>0)
|
881
|
|
{
|
882
|
9
|
PostBindind postSelect = request.QueueSelect.Dequeue() as PostBindind;
|
883
|
|
|
884
|
9
|
if (postSelect.Method == ExecuteMethod.ExecuteQueryForIList)
|
885
|
|
{
|
886
|
3
|
object values = postSelect.Statement.ExecuteQueryForList(session, postSelect.Keys);
|
887
|
3
|
ObjectProbe.SetPropertyValue( postSelect.Target, postSelect.ResultProperty.PropertyName, values);
|
888
|
|
}
|
889
|
6
|
else if (postSelect.Method == ExecuteMethod.ExecuteQueryForStrongTypedIList)
|
890
|
|
{
|
891
|
0
|
object values = Activator.CreateInstance(postSelect.ResultProperty.PropertyInfo.PropertyType);
|
892
|
0
|
postSelect.Statement.ExecuteQueryForList(session, postSelect.Keys, (IList)values);
|
893
|
0
|
ObjectProbe.SetPropertyValue( postSelect.Target, postSelect.ResultProperty.PropertyName, values);
|
894
|
|
}
|
895
|
9
|
if (postSelect.Method == ExecuteMethod.ExecuteQueryForArrayList)
|
896
|
|
{
|
897
|
1
|
IList values = postSelect.Statement.ExecuteQueryForList(session, postSelect.Keys);
|
898
|
1
|
Type elementType = postSelect.ResultProperty.PropertyInfo.PropertyType.GetElementType();
|
899
|
|
|
900
|
1
|
Array array = Array.CreateInstance(elementType, values.Count);
|
901
|
3
|
for(int i=0;i<values.Count;i++)
|
902
|
|
{
|
903
|
2
|
array.SetValue(values[i],i);
|
904
|
|
}
|
905
|
|
|
906
|
1
|
postSelect.ResultProperty.PropertyInfo.SetValue(postSelect.Target, array, null);
|
907
|
|
}
|
908
|
8
|
else if (postSelect.Method == ExecuteMethod.ExecuteQueryForObject)
|
909
|
|
{
|
910
|
5
|
object value = postSelect.Statement.ExecuteQueryForObject(session, postSelect.Keys);
|
911
|
5
|
ObjectProbe.SetPropertyValue( postSelect.Target, postSelect.ResultProperty.PropertyName, value);
|
912
|
|
}
|
913
|
|
}
|
914
|
|
}
|
915
|
|
|
916
|
|
|
917
|
|
|
918
|
|
|
919
|
|
|
920
|
|
|
921
|
|
|
922
|
|
|
923
|
|
|
924
|
|
|
925
|
1260
|
private void SetObjectProperty(RequestScope request, ResultMap resultMap,
|
926
|
|
ResultProperty mapping, ref object target, IDataReader reader)
|
927
|
|
{
|
928
|
1260
|
string selectStatement = mapping.Select;
|
929
|
|
|
930
|
1260
|
if (selectStatement.Length == 0 && mapping.NestedResultMap == null)
|
931
|
|
{
|
932
|
|
|
933
|
|
|
934
|
|
|
935
|
|
|
936
|
|
#region Not a select statement
|
937
|
1237
|
if (mapping.TypeHandler == null)
|
938
|
|
{
|
939
|
0
|
lock(mapping)
|
940
|
|
{
|
941
|
|
if (mapping.TypeHandler == null)
|
942
|
|
{
|
943
|
|
int columnIndex = 0;
|
944
|
|
if (mapping.ColumnIndex == ResultProperty.UNKNOWN_COLUMN_INDEX)
|
945
|
|
{
|
946
|
|
columnIndex = reader.GetOrdinal(mapping.ColumnName);
|
947
|
|
}
|
948
|
|
else
|
949
|
|
{
|
950
|
|
columnIndex = mapping.ColumnIndex;
|
951
|
|
}
|
952
|
|
Type systemType =((IDataRecord)reader).GetFieldType(columnIndex);
|
953
|
|
|
954
|
|
mapping.TypeHandler = _sqlMap.TypeHandlerFactory.GetTypeHandler(systemType);
|
955
|
|
}
|
956
|
|
}
|
957
|
|
}
|
958
|
|
|
959
|
1237
|
object dataBaseValue = mapping.GetDataBaseValue( reader );
|
960
|
|
|
961
|
1237
|
if (resultMap != null)
|
962
|
|
{
|
963
|
1207
|
resultMap.SetValueOfProperty( ref target, mapping, dataBaseValue );
|
964
|
|
}
|
965
|
|
else
|
966
|
|
{
|
967
|
30
|
MappedStatement.SetValueOfProperty( ref target, mapping, dataBaseValue );
|
968
|
|
}
|
969
|
|
#endregion
|
970
|
|
}
|
971
|
23
|
else if (mapping.NestedResultMap != null)
|
972
|
|
{
|
973
|
1
|
object obj = null;
|
974
|
|
|
975
|
1
|
obj = mapping.NestedResultMap.CreateInstanceOfResult();
|
976
|
1
|
FillObjectWithReaderAndResultMap(request, reader, mapping.NestedResultMap, obj);
|
977
|
1
|
MappedStatement.SetValueOfProperty( ref target, mapping, obj );
|
978
|
|
}
|
979
|
|
else
|
980
|
|
{
|
981
|
|
|
982
|
22
|
MappedStatement queryStatement = _sqlMap.GetMappedStatement(selectStatement);
|
983
|
22
|
string paramString = mapping.ColumnName;
|
984
|
22
|
object keys = null;
|
985
|
22
|
bool wasNull = false;
|
986
|
|
|
987
|
|
#region Find Key(s)
|
988
|
22
|
if (paramString.IndexOf(',')>0 || paramString.IndexOf('=')>0)
|
989
|
|
{
|
990
|
4
|
IDictionary keyMap = new Hashtable();
|
991
|
4
|
keys = keyMap;
|
992
|
|
|
993
|
4
|
char[] splitter = {'=',','};
|
994
|
|
|
995
|
4
|
string[] paramTab = paramString.Split(splitter);
|
996
|
4
|
if (paramTab.Length % 2 != 0)
|
997
|
|
{
|
998
|
0
|
throw new DataMapperException("Invalid composite key string format in '"+mapping.PropertyName+". It must be: property1=column1,property2=column2,...");
|
999
|
|
}
|
1000
|
4
|
IEnumerator enumerator = paramTab.GetEnumerator();
|
1001
|
11
|
while (!wasNull && enumerator.MoveNext())
|
1002
|
|
{
|
1003
|
7
|
string hashKey = ((string)enumerator.Current).Trim();
|
1004
|
7
|
enumerator.MoveNext();
|
1005
|
7
|
object hashValue = reader.GetValue( reader.GetOrdinal(((string)enumerator.Current).Trim()) );
|
1006
|
|
|
1007
|
7
|
keyMap.Add(hashKey, hashValue );
|
1008
|
7
|
wasNull = (hashValue == System.DBNull.Value);
|
1009
|
|
}
|
1010
|
|
}
|
1011
|
|
else
|
1012
|
|
{
|
1013
|
18
|
keys = reader.GetValue(reader.GetOrdinal(paramString));
|
1014
|
18
|
wasNull = reader.IsDBNull(reader.GetOrdinal(paramString));
|
1015
|
|
}
|
1016
|
|
#endregion
|
1017
|
|
|
1018
|
22
|
if (wasNull)
|
1019
|
|
{
|
1020
|
|
|
1021
|
0
|
ObjectProbe.SetPropertyValue(target, mapping.PropertyName, null);
|
1022
|
|
}
|
1023
|
|
else
|
1024
|
|
{
|
1025
|
22
|
PostBindind postSelect = new PostBindind();
|
1026
|
22
|
postSelect.Statement = queryStatement;
|
1027
|
22
|
postSelect.Keys = keys;
|
1028
|
22
|
postSelect.Target = target;
|
1029
|
22
|
postSelect.ResultProperty = mapping;
|
1030
|
|
|
1031
|
|
#region Collection object or .NET object
|
1032
|
|
|
1033
|
|
|
1034
|
22
|
if ( (mapping.PropertyInfo.PropertyType.GetInterface("IList") != null) ||
|
1035
|
|
(mapping.PropertyInfo.PropertyType == typeof(IList)))
|
1036
|
|
{
|
1037
|
16
|
object values = null;
|
1038
|
|
|
1039
|
16
|
if (mapping.IsLazyLoad)
|
1040
|
|
{
|
1041
|
13
|
values = LazyLoadList.NewInstance(_sqlMap.DataSource, queryStatement, keys, target, mapping.PropertyName);
|
1042
|
13
|
ObjectProbe.SetPropertyValue( target, mapping.PropertyName, values);
|
1043
|
|
}
|
1044
|
|
else
|
1045
|
|
{
|
1046
|
|
|
1047
|
|
|
1048
|
3
|
if (mapping.PropertyInfo.PropertyType == typeof(IList))
|
1049
|
|
{
|
1050
|
3
|
postSelect.Method = ExecuteMethod.ExecuteQueryForIList;
|
1051
|
|
}
|
1052
|
|
else
|
1053
|
|
{
|
1054
|
0
|
postSelect.Method = ExecuteMethod.ExecuteQueryForStrongTypedIList;
|
1055
|
|
}
|
1056
|
|
}
|
1057
|
|
}
|
1058
|
6
|
else if (mapping.PropertyInfo.PropertyType.IsArray)
|
1059
|
|
{
|
1060
|
1
|
postSelect.Method = ExecuteMethod.ExecuteQueryForArrayList;
|
1061
|
|
}
|
1062
|
|
else
|
1063
|
|
{
|
1064
|
5
|
postSelect.Method = ExecuteMethod.ExecuteQueryForObject;
|
1065
|
|
}
|
1066
|
|
#endregion
|
1067
|
|
|
1068
|
22
|
if (!mapping.IsLazyLoad)
|
1069
|
|
{
|
1070
|
9
|
request.QueueSelect.Enqueue(postSelect);
|
1071
|
|
}
|
1072
|
|
}
|
1073
|
|
}
|
1074
|
|
}
|
1075
|
|
|
1076
|
|
|
1077
|
646
|
private static void SetValueOfProperty( ref object target, ResultProperty property, object dataBaseValue )
|
1078
|
|
{
|
1079
|
646
|
if (target is Hashtable)
|
1080
|
|
{
|
1081
|
0
|
((Hashtable) target).Add(property.PropertyName, dataBaseValue);
|
1082
|
|
}
|
1083
|
|
else
|
1084
|
|
{
|
1085
|
646
|
if (property.PropertyName == "value")
|
1086
|
|
{
|
1087
|
30
|
target = dataBaseValue;
|
1088
|
|
}
|
1089
|
|
else
|
1090
|
|
{
|
1091
|
616
|
if (dataBaseValue == null)
|
1092
|
|
{
|
1093
|
38
|
if (property.PropertyInfo != null)
|
1094
|
|
{
|
1095
|
38
|
property.PropertyInfo.SetValue( target, null, null );
|
1096
|
|
}
|
1097
|
|
else
|
1098
|
|
{
|
1099
|
0
|
ObjectProbe.SetPropertyValue( target, property.PropertyName, null);
|
1100
|
|
}
|
1101
|
|
}
|
1102
|
|
else
|
1103
|
|
{
|
1104
|
578
|
if (property.PropertyInfo != null)
|
1105
|
|
{
|
1106
|
578
|
property.PropertyInfo.SetValue( target, dataBaseValue, null );
|
1107
|
|
}
|
1108
|
|
else
|
1109
|
|
{
|
1110
|
0
|
ObjectProbe.SetPropertyValue( target, property.PropertyName, dataBaseValue);
|
1111
|
|
}
|
1112
|
|
}
|
1113
|
|
}
|
1114
|
|
}
|
1115
|
|
}
|
1116
|
|
|
1117
|
|
|
1118
|
|
|
1119
|
|
|
1120
|
|
|
1121
|
|
|
1122
|
69
|
private void RaiseExecuteEvent()
|
1123
|
|
{
|
1124
|
69
|
ExecuteEventArgs e = new ExecuteEventArgs();
|
1125
|
69
|
e.StatementName = _statement.Id;
|
1126
|
69
|
if (Execute != null)
|
1127
|
|
{
|
1128
|
5
|
Execute(this, e);
|
1129
|
|
}
|
1130
|
|
}
|
1131
|
|
|
1132
|
|
|
1133
|
|
|
1134
|
|
|
1135
|
|
|
1136
|
0
|
public override string ToString()
|
1137
|
|
{
|
1138
|
|
StringBuilder buffer = new StringBuilder();
|
1139
|
|
buffer.Append("\tMappedStatement: " + this.Name + "\n");
|
1140
|
|
if (_statement.ParameterMap != null) buffer.Append(_statement.ParameterMap.Id);
|
1141
|
|
if (_statement.ResultMap != null) buffer.Append(_statement.ResultMap.Id);
|
1142
|
|
|
1143
|
|
return buffer.ToString();
|
1144
|
|
}
|
1145
|
|
|
1146
|
|
|
1147
|
|
private ReaderAutoMapper _readerAutoMapper = null;
|
1148
|
|
|
1149
|
156
|
private void AutoMapReader( IDataReader reader,ref object resultObject)
|
1150
|
|
{
|
1151
|
156
|
if (_readerAutoMapper == null)
|
1152
|
|
{
|
1153
|
69
|
lock (this)
|
1154
|
|
{
|
1155
|
69
|
if (_readerAutoMapper == null)
|
1156
|
|
{
|
1157
|
69
|
_readerAutoMapper = new ReaderAutoMapper(_sqlMap.TypeHandlerFactory, reader, ref resultObject);
|
1158
|
|
}
|
1159
|
|
}
|
1160
|
|
}
|
1161
|
|
|
1162
|
156
|
_readerAutoMapper.AutoMapReader( reader, ref resultObject );
|
1163
|
|
}
|
1164
|
|
#endregion
|
1165
|
|
|
1166
|
|
private class ReaderAutoMapper
|
1167
|
|
{
|
1168
|
|
|
1169
|
|
|
1170
|
|
private ResultMap _resultMap = new ResultMap();
|
1171
|
|
|
1172
|
|
|
1173
|
|
|
1174
|
|
|
1175
|
|
|
1176
|
|
|
1177
|
|
|
1178
|
69
|
public ReaderAutoMapper(TypeHandlerFactory typeHandlerFactory, IDataReader reader,ref object resultObject)
|
1179
|
|
{
|
1180
|
69
|
try
|
1181
|
|
{
|
1182
|
|
|
1183
|
69
|
ReflectionInfo reflectionInfo = ReflectionInfo.GetInstance(resultObject.GetType());
|
1184
|
69
|
string[] propertiesName = reflectionInfo.GetWriteablePropertyNames();
|
1185
|
|
|
1186
|
69
|
Hashtable propertyMap = new Hashtable();
|
1187
|
526
|
for (int i = 0; i < propertiesName.Length; i++)
|
1188
|
|
{
|
1189
|
457
|
propertyMap.Add( propertiesName[i].ToUpper(), reflectionInfo.GetSetter(propertiesName[i]) );
|
1190
|
|
}
|
1191
|
|
|
1192
|
|
|
1193
|
|
|
1194
|
69
|
DataTable dataColumn = reader.GetSchemaTable();
|
1195
|
337
|
for (int i = 0; i < dataColumn.Rows.Count; i++)
|
1196
|
|
{
|
1197
|
268
|
string columnName = dataColumn.Rows[i][0].ToString();
|
1198
|
268
|
PropertyInfo matchedPropertyInfo = propertyMap[columnName.ToUpper()] as PropertyInfo;
|
1199
|
|
|
1200
|
268
|
ResultProperty property = new ResultProperty();
|
1201
|
268
|
property.ColumnName = columnName;
|
1202
|
|
|
1203
|
268
|
if (matchedPropertyInfo != null )
|
1204
|
|
{
|
1205
|
268
|
property.PropertyName = matchedPropertyInfo.Name;
|
1206
|
268
|
property.Initialize(typeHandlerFactory, matchedPropertyInfo );
|
1207
|
|
|
1208
|
268
|
_resultMap.AddResultPropery(property);
|
1209
|
|
}
|
1210
|
0
|
else if (resultObject is Hashtable)
|
1211
|
|
{
|
1212
|
|
property.PropertyName = columnName;
|
1213
|
|
|
1214
|
|
_resultMap.AddResultPropery(property);
|
1215
|
|
}
|
1216
|
|
|
1217
|
|
|
1218
|
268
|
Type propertyType = reflectionInfo.GetSetterType(property.PropertyName);
|
1219
|
268
|
property.TypeHandler = typeHandlerFactory.GetTypeHandler( propertyType );
|
1220
|
|
}
|
1221
|
|
}
|
1222
|
|
catch (Exception e)
|
1223
|
|
{
|
1224
|
0
|
throw new DataMapperException("Error automapping columns. Cause: " + e);
|
1225
|
|
}
|
1226
|
|
}
|
1227
|
|
|
1228
|
|
|
1229
|
|
|
1230
|
|
|
1231
|
|
|
1232
|
|
|
1233
|
156
|
public void AutoMapReader(IDataReader reader, ref object resultObject)
|
1234
|
|
{
|
1235
|
156
|
foreach (string key in _resultMap.ColumnsToPropertiesMap.Keys)
|
1236
|
|
{
|
1237
|
615
|
ResultProperty property = (ResultProperty) _resultMap.ColumnsToPropertiesMap[key];
|
1238
|
615
|
MappedStatement.SetValueOfProperty( ref resultObject, property,
|
1239
|
|
property.GetDataBaseValue( reader ));
|
1240
|
|
}
|
1241
|
|
}
|
1242
|
|
|
1243
|
|
}
|
1244
|
|
}
|
1245
|
|
}
|
1246
|
|
|