1
|
|
#region Copyright
|
2
|
|
|
3
|
|
|
4
|
|
|
5
|
|
|
6
|
|
|
7
|
|
|
8
|
|
|
9
|
|
|
10
|
|
|
11
|
|
|
12
|
|
|
13
|
|
|
14
|
|
|
15
|
|
|
16
|
|
|
17
|
|
#endregion
|
18
|
|
|
19
|
|
using System;
|
20
|
|
using System.Data;
|
21
|
|
using System.Reflection;
|
22
|
|
using Seasar.Extension.ADO.Types;
|
23
|
|
using Seasar.Framework.Util;
|
24
|
|
|
25
|
|
namespace Seasar.Extension.ADO.Impl
|
26
|
|
{
|
27
|
|
public abstract class AbstractBeanDataReaderHandler : IDataReaderHandler
|
28
|
|
{
|
29
|
|
private Type beanType_;
|
30
|
|
|
31
|
3
|
public AbstractBeanDataReaderHandler(Type beanType)
|
32
|
|
{
|
33
|
3
|
SetBeanType(beanType);
|
34
|
|
}
|
35
|
|
|
36
|
0
|
public Type BeanType
|
37
|
|
{
|
38
|
|
get { return beanType_; }
|
39
|
|
}
|
40
|
|
|
41
|
3
|
public void SetBeanType(Type beanType)
|
42
|
|
{
|
43
|
3
|
beanType_ = beanType;
|
44
|
|
}
|
45
|
|
|
46
|
3
|
protected IPropertyType[] CreatePropertyTypes(DataTable metaData)
|
47
|
|
{
|
48
|
3
|
int count = metaData.Rows.Count;
|
49
|
3
|
IPropertyType[] propertyTypes = new PropertyTypeImpl[count];
|
50
|
23
|
for (int i = 0; i < count; ++i)
|
51
|
|
{
|
52
|
20
|
DataRow row = metaData.Rows[i];
|
53
|
20
|
string columnName = (string) row["ColumnName"];
|
54
|
20
|
string propertyName = columnName.Replace("_", "");
|
55
|
20
|
PropertyInfo pi = beanType_.GetProperty(
|
56
|
|
propertyName,
|
57
|
|
BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance | BindingFlags.IgnoreCase
|
58
|
|
);
|
59
|
20
|
IValueType valueType = ValueTypes.GetValueType(pi.PropertyType);
|
60
|
20
|
propertyTypes[i] = new PropertyTypeImpl(pi, valueType, columnName);
|
61
|
|
}
|
62
|
3
|
return propertyTypes;
|
63
|
|
}
|
64
|
|
|
65
|
16
|
protected object CreateRow(IDataReader dataReader, IPropertyType[] propertyTypes)
|
66
|
|
{
|
67
|
16
|
object row = ClassUtil.NewInstance(beanType_);
|
68
|
153
|
for (int i = 0; i < propertyTypes.Length; ++i)
|
69
|
|
{
|
70
|
137
|
IPropertyType pt = propertyTypes[i];
|
71
|
137
|
IValueType valueType = pt.ValueType;
|
72
|
137
|
object value = valueType.GetValue(dataReader, pt.ColumnName);
|
73
|
137
|
PropertyInfo pi = pt.PropertyInfo;
|
74
|
137
|
pi.SetValue(row, value, null);
|
75
|
|
}
|
76
|
16
|
return row;
|
77
|
|
}
|
78
|
|
|
79
|
|
#region IDataReaderHandler メンバ
|
80
|
|
|
81
|
|
public abstract object Handle(IDataReader dataReader);
|
82
|
|
|
83
|
|
#endregion
|
84
|
|
}
|
85
|
|
}
|
86
|
|
|