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 Seasar.Dao;
|
22
|
|
using Seasar.Dao.Dbms;
|
23
|
|
using Seasar.Dao.Impl;
|
24
|
|
using Seasar.Extension.ADO;
|
25
|
|
using Seasar.Extension.ADO.Impl;
|
26
|
|
using Seasar.Extension.ADO.Types;
|
27
|
|
using Seasar.Framework.Container;
|
28
|
|
using Seasar.Framework.Container.Factory;
|
29
|
|
using Seasar.Framework.Util;
|
30
|
|
using MbUnit.Framework;
|
31
|
|
|
32
|
|
namespace Seasar.Dao.Tests.Impl
|
33
|
|
{
|
34
|
|
[TestFixture]
|
35
|
|
public class BeanMetaDataDataReaderHandlerTest
|
36
|
|
{
|
37
|
|
private const string PATH = "Tests.dicon";
|
38
|
|
private IBeanMetaData beanMetaData_;
|
39
|
|
private IDataSource dataSource;
|
40
|
|
|
41
|
3
|
[SetUp]
|
42
|
|
public void SetUp()
|
43
|
|
{
|
44
|
3
|
IS2Container container = S2ContainerFactory.Create(PATH);
|
45
|
3
|
dataSource = (IDataSource) container.GetComponent(typeof(IDataSource));
|
46
|
|
|
47
|
3
|
IDbConnection cn = DataSourceUtil.GetConnection(dataSource);
|
48
|
3
|
IDbms dbms = new MSSQLServer();
|
49
|
3
|
beanMetaData_ = new BeanMetaDataImpl(typeof(Employee), new DatabaseMetaDataImpl(dataSource), dbms);
|
50
|
|
}
|
51
|
|
|
52
|
1
|
[Test]
|
53
|
|
public void TestHandle()
|
54
|
|
{
|
55
|
1
|
IDataReaderHandler handler = new BeanMetaDataDataReaderHandler(
|
56
|
|
beanMetaData_);
|
57
|
1
|
String sql = "select emp.*, dept.deptno as deptno_0, dept.dname as dname_0 from emp, dept where empno = 7788 and emp.deptno = dept.deptno";
|
58
|
1
|
IDbConnection cn = DataSourceUtil.GetConnection(dataSource);
|
59
|
|
|
60
|
1
|
IDbCommand cmd = dataSource.GetCommand(sql,cn);
|
61
|
1
|
Employee ret = null;
|
62
|
1
|
try {
|
63
|
|
|
64
|
1
|
IDataReader rs = cmd.ExecuteReader();
|
65
|
1
|
try {
|
66
|
1
|
ret = (Employee) handler.Handle(rs);
|
67
|
|
} finally {
|
68
|
|
|
69
|
|
}
|
70
|
|
} finally {
|
71
|
|
|
72
|
|
}
|
73
|
1
|
Assert.IsNotNull(ret, "1");
|
74
|
|
|
75
|
1
|
Department dept = ret.Department;
|
76
|
1
|
Assert.IsNotNull(dept, "2");
|
77
|
1
|
Assert.AreEqual(20, dept.Deptno, "3");
|
78
|
1
|
Assert.AreEqual("RESEARCH", dept.Dname, "4");
|
79
|
|
}
|
80
|
|
|
81
|
1
|
[Test]
|
82
|
|
public void TestHandle2() {
|
83
|
1
|
IDataReaderHandler handler = new BeanMetaDataDataReaderHandler(
|
84
|
|
beanMetaData_);
|
85
|
1
|
String sql = "select ename, job from emp where empno = 7788";
|
86
|
1
|
IDbConnection cn = DataSourceUtil.GetConnection(dataSource);
|
87
|
|
|
88
|
1
|
IDbCommand cmd = dataSource.GetCommand(sql,cn);
|
89
|
1
|
Employee ret = null;
|
90
|
1
|
try {
|
91
|
|
|
92
|
1
|
IDataReader rs = cmd.ExecuteReader();
|
93
|
1
|
try
|
94
|
|
{
|
95
|
1
|
ret = (Employee) handler.Handle(rs);
|
96
|
|
} finally {
|
97
|
|
|
98
|
|
}
|
99
|
|
} finally {
|
100
|
|
|
101
|
|
}
|
102
|
1
|
Assert.IsNotNull(ret, "1");
|
103
|
|
|
104
|
1
|
Department dept = ret.Department;
|
105
|
1
|
Assert.IsNull(dept, "2");
|
106
|
|
}
|
107
|
|
|
108
|
1
|
[Test]
|
109
|
|
public void TestHandle3() {
|
110
|
1
|
IDataReaderHandler handler = new BeanMetaDataDataReaderHandler(
|
111
|
|
beanMetaData_);
|
112
|
1
|
String sql = "select ename, dept.dname as dname_0 from emp, dept where empno = 7788 and emp.deptno = dept.deptno";
|
113
|
1
|
IDbConnection cn = DataSourceUtil.GetConnection(dataSource);
|
114
|
|
|
115
|
1
|
IDbCommand cmd = dataSource.GetCommand(sql,cn);
|
116
|
1
|
Employee ret = null;
|
117
|
1
|
try {
|
118
|
|
|
119
|
1
|
IDataReader rs = cmd.ExecuteReader();
|
120
|
1
|
try
|
121
|
|
{
|
122
|
1
|
ret = (Employee) handler.Handle(rs);
|
123
|
|
} finally {
|
124
|
|
|
125
|
|
}
|
126
|
|
} finally {
|
127
|
|
|
128
|
|
}
|
129
|
1
|
Assert.IsNotNull(ret, "1");
|
130
|
|
|
131
|
1
|
Department dept = ret.Department;
|
132
|
1
|
Assert.IsNotNull(dept, "2");
|
133
|
1
|
Assert.AreEqual("RESEARCH", dept.Dname, "3");
|
134
|
|
}
|
135
|
|
}
|
136
|
|
}
|
137
|
|
|