Skip to content

Commit 79096cf

Browse files
committed
Added a test case for a corner case.
1 parent 09f11eb commit 79096cf

File tree

5 files changed

+253
-0
lines changed

5 files changed

+253
-0
lines changed
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
/*
2+
* Copyright 2009-2012 The MyBatis Team
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.apache.ibatis.submitted.no_param_type;
17+
18+
import static org.junit.Assert.*;
19+
20+
import java.io.Reader;
21+
import java.sql.Connection;
22+
import java.util.List;
23+
24+
import org.apache.ibatis.executor.BatchResult;
25+
import org.apache.ibatis.io.Resources;
26+
import org.apache.ibatis.jdbc.ScriptRunner;
27+
import org.apache.ibatis.session.ExecutorType;
28+
import org.apache.ibatis.session.SqlSession;
29+
import org.apache.ibatis.session.SqlSessionFactory;
30+
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
31+
import org.junit.BeforeClass;
32+
import org.junit.Test;
33+
34+
public class BaseTest {
35+
36+
private static SqlSessionFactory sqlSessionFactory;
37+
38+
@BeforeClass
39+
public static void setUp() throws Exception {
40+
// create a SqlSessionFactory
41+
Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/no_param_type/mybatis-config.xml");
42+
sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
43+
reader.close();
44+
45+
// populate in-memory database
46+
SqlSession session = sqlSessionFactory.openSession();
47+
Connection conn = session.getConnection();
48+
reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/no_param_type/CreateDB.sql");
49+
ScriptRunner runner = new ScriptRunner(conn);
50+
runner.setLogWriter(null);
51+
runner.runScript(reader);
52+
reader.close();
53+
session.close();
54+
}
55+
56+
@Test
57+
public void shouldAcceptDifferentTypeInTheSameBatch() {
58+
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
59+
try {
60+
ObjA a = new ObjA();
61+
a.setId(1);
62+
a.setName(111);
63+
sqlSession.insert("insertUser", a);
64+
ObjB b = new ObjB();
65+
b.setId(2);
66+
b.setName("222");
67+
sqlSession.insert("insertUser", b);
68+
List<BatchResult> batchResults = sqlSession.flushStatements();
69+
batchResults.clear();
70+
sqlSession.clearCache();
71+
sqlSession.commit();
72+
List<User> users = sqlSession.selectList("selectUser");
73+
assertEquals(2, users.size());
74+
} finally {
75+
sqlSession.close();
76+
}
77+
}
78+
79+
public static class ObjA {
80+
private Integer id;
81+
82+
private Integer name;
83+
84+
public Integer getId() {
85+
return id;
86+
}
87+
88+
public void setId(Integer id) {
89+
this.id = id;
90+
}
91+
92+
public Integer getName() {
93+
return name;
94+
}
95+
96+
public void setName(Integer name) {
97+
this.name = name;
98+
}
99+
}
100+
101+
public static class ObjB {
102+
private Integer id;
103+
104+
private String name;
105+
106+
public Integer getId() {
107+
return id;
108+
}
109+
110+
public void setId(Integer id) {
111+
this.id = id;
112+
}
113+
114+
public String getName() {
115+
return name;
116+
}
117+
118+
public void setName(String name) {
119+
this.name = name;
120+
}
121+
}
122+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--
2+
-- Copyright 2009-2012 The MyBatis Team
3+
--
4+
-- Licensed under the Apache License, Version 2.0 (the "License");
5+
-- you may not use this file except in compliance with the License.
6+
-- You may obtain a copy of the License at
7+
--
8+
-- http://www.apache.org/licenses/LICENSE-2.0
9+
--
10+
-- Unless required by applicable law or agreed to in writing, software
11+
-- distributed under the License is distributed on an "AS IS" BASIS,
12+
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
-- See the License for the specific language governing permissions and
14+
-- limitations under the License.
15+
--
16+
17+
drop table users if exists;
18+
19+
create table users (
20+
id int,
21+
name varchar(20)
22+
);
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Copyright 2009-2012 The MyBatis Team
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
-->
17+
<!DOCTYPE mapper
18+
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
19+
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
20+
21+
<mapper namespace="org.apache.ibatis.submitted.no_param_type.Mapper">
22+
23+
<insert id="insertUser">
24+
insert into users (id, name) values (#{id}, #{name})
25+
</insert>
26+
27+
<select id="selectUser" resultType="org.apache.ibatis.submitted.no_param_type.User">
28+
select * from users
29+
</select>
30+
31+
</mapper>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright 2009-2012 The MyBatis Team
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.apache.ibatis.submitted.no_param_type;
17+
18+
public class User {
19+
20+
private Integer id;
21+
private String name;
22+
23+
public Integer getId() {
24+
return id;
25+
}
26+
27+
public void setId(Integer id) {
28+
this.id = id;
29+
}
30+
31+
public String getName() {
32+
return name;
33+
}
34+
35+
public void setName(String name) {
36+
this.name = name;
37+
}
38+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<!--
3+
Copyright 2009-2012 The MyBatis Team
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
-->
17+
<!DOCTYPE configuration
18+
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
19+
"http://mybatis.org/dtd/mybatis-3-config.dtd">
20+
21+
<configuration>
22+
23+
<environments default="development">
24+
<environment id="development">
25+
<transactionManager type="JDBC">
26+
<property name="" value="" />
27+
</transactionManager>
28+
<dataSource type="UNPOOLED">
29+
<property name="driver" value="org.hsqldb.jdbcDriver" />
30+
<property name="url" value="jdbc:hsqldb:mem:basetest" />
31+
<property name="username" value="sa" />
32+
</dataSource>
33+
</environment>
34+
</environments>
35+
36+
<mappers>
37+
<mapper resource="org/apache/ibatis/submitted/no_param_type/Mapper.xml" />
38+
</mappers>
39+
40+
</configuration>

0 commit comments

Comments
 (0)