Skip to content

Commit 07e657f

Browse files
committed
Another test for @SelectKey annotation
1 parent 644bbd2 commit 07e657f

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

src/test/java/org/apache/ibatis/submitted/selectkey/AnnotatedMapper.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.apache.ibatis.submitted.selectkey;
22

33
import org.apache.ibatis.annotations.Insert;
4+
import org.apache.ibatis.annotations.InsertProvider;
45
import org.apache.ibatis.annotations.SelectKey;
56

67
public interface AnnotatedMapper {
@@ -12,4 +13,8 @@ public interface AnnotatedMapper {
1213
@Insert("insert into table3 (id, name) values(#{nameId}, #{name})")
1314
@SelectKey(statement="call next value for TestSequence", keyProperty="nameId", before=true, resultType=int.class)
1415
int insertTable3(Name name);
16+
17+
@InsertProvider(type=SqlProvider.class,method="insertTable3_2")
18+
@SelectKey(statement="call next value for TestSequence", keyProperty="nameId", before=true, resultType=int.class)
19+
int insertTable3_2(Name name);
1520
}

src/test/java/org/apache/ibatis/submitted/selectkey/SelectKeyTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,20 @@ public void testAnnotatedInsertTable3() {
124124
sqlSession.close();
125125
}
126126
}
127+
128+
@Test
129+
public void testAnnotatedInsertTable3_2() {
130+
SqlSession sqlSession = sqlSessionFactory.openSession();
131+
132+
try {
133+
Name name = new Name();
134+
name.setName("barney");
135+
AnnotatedMapper mapper = sqlSession.getMapper(AnnotatedMapper.class);
136+
int rows = mapper.insertTable3_2(name);
137+
assertEquals(1, rows);
138+
assertEquals(33, name.getNameId());
139+
} finally {
140+
sqlSession.close();
141+
}
142+
}
127143
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package org.apache.ibatis.submitted.selectkey;
2+
3+
public class SqlProvider {
4+
5+
public String insertTable3_2(Name name) {
6+
return "insert into table3 (id, name) values(#{nameId}, #{name})";
7+
}
8+
}

0 commit comments

Comments
 (0)