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 Seasar.Dao;
|
21
|
|
using Seasar.Dao.Impl;
|
22
|
|
using Seasar.Extension.ADO;
|
23
|
|
using Seasar.Extension.ADO.Impl;
|
24
|
|
using Seasar.Extension.Unit;
|
25
|
|
using Seasar.Framework.Container;
|
26
|
|
using Seasar.Framework.Container.Factory;
|
27
|
|
using Seasar.Framework.Exceptions;
|
28
|
|
using Seasar.Framework.Util;
|
29
|
|
using NUnit.Framework;
|
30
|
|
|
31
|
|
namespace Seasar.Dao.Tests.Impl
|
32
|
|
{
|
33
|
|
|
34
|
|
|
35
|
|
|
36
|
|
[TestFixture]
|
37
|
|
public class UpdateAutoStaticCommandTest : S2TestCase
|
38
|
|
{
|
39
|
|
private const string PATH = "Tests.dicon";
|
40
|
|
private IDataSource dataSource;
|
41
|
|
|
42
|
5
|
[SetUp]
|
43
|
|
public void SetUp()
|
44
|
|
{
|
45
|
5
|
IS2Container container = S2ContainerFactory.Create(PATH);
|
46
|
5
|
dataSource = (IDataSource) container.GetComponent(typeof(IDataSource));
|
47
|
|
}
|
48
|
|
|
49
|
1
|
[Test, S2(Tx.Rollback)]
|
50
|
|
public void TestExecuteTx()
|
51
|
|
{
|
52
|
1
|
IDaoMetaData dmd = new DaoMetaDataImpl(typeof(EmployeeAutoDao),
|
53
|
|
dataSource, BasicCommandFactory.INSTANCE,
|
54
|
|
BasicDataReaderFactory.INSTANCE, new DatabaseMetaDataImpl(dataSource));
|
55
|
|
|
56
|
1
|
ISqlCommand cmd = dmd.GetSqlCommand("Update");
|
57
|
1
|
ISqlCommand cmd2 = dmd.GetSqlCommand("GetEmployee");
|
58
|
1
|
Employee emp = (Employee) cmd2.Execute(new Object[] { 7788 });
|
59
|
1
|
Int32 count = (Int32) cmd.Execute(new Object[] { emp });
|
60
|
1
|
Assert.AreEqual(1, count, "1");
|
61
|
|
|
62
|
|
}
|
63
|
|
|
64
|
1
|
[Test, S2(Tx.Rollback)]
|
65
|
|
public void TestExecute2Tx()
|
66
|
|
{
|
67
|
1
|
IDaoMetaData dmd = new DaoMetaDataImpl(typeof(DepartmentAutoDao),
|
68
|
|
dataSource, BasicCommandFactory.INSTANCE,
|
69
|
|
BasicDataReaderFactory.INSTANCE, new DatabaseMetaDataImpl(dataSource));
|
70
|
|
|
71
|
1
|
ISqlCommand cmd = dmd.GetSqlCommand("Update");
|
72
|
1
|
Department dept = new Department();
|
73
|
1
|
dept.Deptno =10;
|
74
|
1
|
Int32 count = (Int32) cmd.Execute(new Object[] { dept });
|
75
|
1
|
Assert.AreEqual(1, count, "1");
|
76
|
1
|
Assert.AreEqual(1, dept.VersionNo, "2");
|
77
|
|
|
78
|
|
|
79
|
|
|
80
|
1
|
string cmdText = "Update [dbo].[DEPT] SET VERSIONNO = 0 WHERE DEPTNO = 10";
|
81
|
1
|
System.Data.IDbConnection cn = DataSourceUtil.GetConnection(dataSource);
|
82
|
1
|
System.Data.IDbCommand dbcmd = dataSource.GetCommand(cmdText,cn);
|
83
|
1
|
CommandUtil.ExecuteNonQuery(dataSource,dbcmd);
|
84
|
|
|
85
|
|
}
|
86
|
|
|
87
|
1
|
[Test, S2(Tx.Rollback)]
|
88
|
|
[ExpectedException(typeof(NotSingleRowUpdatedRuntimeException))]
|
89
|
|
public void TestExecute3Tx()
|
90
|
|
{
|
91
|
1
|
IDaoMetaData dmd = new DaoMetaDataImpl(typeof(DepartmentAutoDao),
|
92
|
|
dataSource, BasicCommandFactory.INSTANCE,
|
93
|
|
BasicDataReaderFactory.INSTANCE, new DatabaseMetaDataImpl(dataSource));
|
94
|
|
|
95
|
1
|
ISqlCommand cmd = dmd.GetSqlCommand("Update");
|
96
|
1
|
Department dept = new Department();
|
97
|
1
|
dept.Deptno = 10;
|
98
|
1
|
dept.VersionNo = -1;
|
99
|
|
|
100
|
|
|
101
|
1
|
cmd.Execute(new Object[] { dept });
|
102
|
|
|
103
|
|
|
104
|
|
|
105
|
|
|
106
|
|
|
107
|
|
|
108
|
|
}
|
109
|
|
|
110
|
1
|
[Test, S2(Tx.Rollback)]
|
111
|
|
public void TestExecute4Tx()
|
112
|
|
{
|
113
|
1
|
IDaoMetaData dmd = new DaoMetaDataImpl(typeof(EmployeeAutoDao),
|
114
|
|
dataSource, BasicCommandFactory.INSTANCE,
|
115
|
|
BasicDataReaderFactory.INSTANCE, new DatabaseMetaDataImpl(dataSource));
|
116
|
|
|
117
|
1
|
ISqlCommand cmd = dmd.GetSqlCommand("Update2");
|
118
|
1
|
ISqlCommand cmd2 = dmd.GetSqlCommand("GetEmployee");
|
119
|
1
|
Employee emp = (Employee) cmd2.Execute(new Object[] { 7788 });
|
120
|
1
|
Int32 count = (Int32) cmd.Execute(new Object[] { emp });
|
121
|
1
|
Assert.AreEqual(1, count, "1");
|
122
|
|
}
|
123
|
|
|
124
|
1
|
[Test, S2(Tx.Rollback)]
|
125
|
|
public void TestExecute5Tx()
|
126
|
|
{
|
127
|
1
|
IDaoMetaData dmd = new DaoMetaDataImpl(typeof(EmployeeAutoDao),
|
128
|
|
dataSource, BasicCommandFactory.INSTANCE,
|
129
|
|
BasicDataReaderFactory.INSTANCE, new DatabaseMetaDataImpl(dataSource));
|
130
|
|
|
131
|
1
|
ISqlCommand cmd = dmd.GetSqlCommand("Update3");
|
132
|
1
|
ISqlCommand cmd2 = dmd.GetSqlCommand("GetEmployee");
|
133
|
1
|
Employee emp = (Employee) cmd2.Execute(new Object[] { 7788 });
|
134
|
1
|
Int32 count = (Int32) cmd.Execute(new Object[] { emp });
|
135
|
1
|
Assert.AreEqual(1, count, "1");
|
136
|
|
}
|
137
|
|
}
|
138
|
|
}
|
139
|
|
|