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.Reflection;
|
21
|
|
using Seasar.Dao.Attrs;
|
22
|
|
|
23
|
|
namespace Seasar.Dao.Impl
|
24
|
|
{
|
25
|
|
public class FieldAnnotationReader : IDaoAnnotationReader
|
26
|
|
{
|
27
|
|
protected Type daoBeanType;
|
28
|
|
|
29
|
18
|
public FieldAnnotationReader(Type daoBeanType)
|
30
|
|
{
|
31
|
18
|
this.daoBeanType = daoBeanType;
|
32
|
|
}
|
33
|
|
|
34
|
|
#region IDaoAnnotationReader メンバ
|
35
|
|
|
36
|
38
|
public string GetQuery(string name)
|
37
|
|
{
|
38
|
38
|
MethodInfo mi = daoBeanType.GetMethod(name);
|
39
|
38
|
QueryAttribute queryAttr = AttributeUtil.GetQueryAttribute(mi);
|
40
|
38
|
if(queryAttr != null)
|
41
|
|
{
|
42
|
33
|
return queryAttr.Query;
|
43
|
|
}
|
44
|
|
else
|
45
|
|
{
|
46
|
5
|
return null;
|
47
|
|
}
|
48
|
|
}
|
49
|
|
|
50
|
18
|
public Type GetBeanType()
|
51
|
|
{
|
52
|
18
|
BeanAttribute beanAttr = AttributeUtil.GetBeanAttribute(daoBeanType);
|
53
|
18
|
return beanAttr.BeanType;
|
54
|
|
}
|
55
|
|
|
56
|
68
|
public string[] GetNoPersistentProps(string methodName)
|
57
|
|
{
|
58
|
68
|
MethodInfo mi = daoBeanType.GetMethod(methodName);
|
59
|
68
|
NoPersistentPropsAttribute nppAttr = AttributeUtil.GetNoPersistentPropsAttribute(mi);
|
60
|
68
|
if(nppAttr != null)
|
61
|
|
{
|
62
|
14
|
return nppAttr.Props;
|
63
|
|
}
|
64
|
|
else
|
65
|
|
{
|
66
|
54
|
return null;
|
67
|
|
}
|
68
|
|
}
|
69
|
|
|
70
|
54
|
public string[] GetPersistentProps(string methodName)
|
71
|
|
{
|
72
|
54
|
MethodInfo mi = daoBeanType.GetMethod(methodName);
|
73
|
54
|
PersistentPropsAttribute ppAttr = AttributeUtil.GetPersistentPropsAttribute(mi);
|
74
|
54
|
if(ppAttr != null)
|
75
|
|
{
|
76
|
14
|
return ppAttr.Props;
|
77
|
|
}
|
78
|
|
else
|
79
|
|
{
|
80
|
40
|
return null;
|
81
|
|
}
|
82
|
|
}
|
83
|
|
|
84
|
116
|
public string GetSql(string name, IDbms dbms)
|
85
|
|
{
|
86
|
116
|
MethodInfo mi = daoBeanType.GetMethod(name);
|
87
|
116
|
SqlAttribute[] sqlAttrs = AttributeUtil.GetSqlAttributes(mi);
|
88
|
116
|
SqlAttribute defaultSqlAttr = null;
|
89
|
116
|
foreach(SqlAttribute sqlAttr in sqlAttrs)
|
90
|
|
{
|
91
|
5
|
if(sqlAttr.Dbms == dbms.Dbms)
|
92
|
0
|
return sqlAttr.Sql;
|
93
|
5
|
if(sqlAttr.Dbms == KindOfDbms.None)
|
94
|
5
|
defaultSqlAttr = sqlAttr;
|
95
|
|
}
|
96
|
|
|
97
|
116
|
return defaultSqlAttr == null ? null : defaultSqlAttr.Sql;
|
98
|
|
}
|
99
|
|
|
100
|
|
#endregion
|
101
|
|
}
|
102
|
|
}
|
103
|
|
|