1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.ibatis.submitted.no_param_type;
17
18 import static org.junit.jupiter.api.Assertions.assertEquals;
19
20 import java.io.Reader;
21 import java.util.List;
22
23 import org.apache.ibatis.BaseDataTest;
24 import org.apache.ibatis.executor.BatchResult;
25 import org.apache.ibatis.io.Resources;
26 import org.apache.ibatis.session.ExecutorType;
27 import org.apache.ibatis.session.SqlSession;
28 import org.apache.ibatis.session.SqlSessionFactory;
29 import org.apache.ibatis.session.SqlSessionFactoryBuilder;
30 import org.junit.jupiter.api.BeforeAll;
31 import org.junit.jupiter.api.Test;
32
33 class NoParamTypeTest {
34
35 private static SqlSessionFactory sqlSessionFactory;
36
37 @BeforeAll
38 static void setUp() throws Exception {
39
40 try (
41 Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/no_param_type/mybatis-config.xml")) {
42 sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
43 }
44
45
46 BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(),
47 "org/apache/ibatis/submitted/no_param_type/CreateDB.sql");
48 }
49
50 @Test
51 void shouldAcceptDifferentTypeInTheSameBatch() {
52 try (SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH)) {
53 ObjA a = new ObjA();
54 a.setId(1);
55 a.setName(111);
56 sqlSession.insert("insertUser", a);
57 ObjB b = new ObjB();
58 b.setId(2);
59 b.setName("222");
60 sqlSession.insert("insertUser", b);
61 List<BatchResult> batchResults = sqlSession.flushStatements();
62 batchResults.clear();
63 sqlSession.clearCache();
64 sqlSession.commit();
65 List<User> users = sqlSession.selectList("selectUser");
66 assertEquals(2, users.size());
67 }
68 }
69
70 public static class ObjA {
71 private Integer id;
72
73 private Integer name;
74
75 public Integer getId() {
76 return id;
77 }
78
79 public void setId(Integer id) {
80 this.id = id;
81 }
82
83 public Integer getName() {
84 return name;
85 }
86
87 public void setName(Integer name) {
88 this.name = name;
89 }
90 }
91
92 public static class ObjB {
93 private Integer id;
94
95 private String name;
96
97 public Integer getId() {
98 return id;
99 }
100
101 public void setId(Integer id) {
102 this.id = id;
103 }
104
105 public String getName() {
106 return name;
107 }
108
109 public void setName(String name) {
110 this.name = name;
111 }
112 }
113 }