Skip to content

Commit cdf7400

Browse files
committed
Test using two named parameters and an stored procedure.
1 parent 97a4fbe commit cdf7400

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

src/test/java/org/apache/ibatis/submitted/sptests/CreateDB.sql

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,15 @@ BEGIN ATOMIC
123123
END
124124
go
125125

126+
create procedure sptest.getnamesLowHigh(in lowestId int, in highestId int)
127+
modifies sql data
128+
dynamic result sets 1
129+
BEGIN ATOMIC
130+
declare cur cursor for select * from sptest.names where id >= lowestId and id <= highestId;
131+
open cur;
132+
END
133+
go
134+
126135
create procedure sptest.arraytest(in ids int array, out rowsrequested integer, out returnedids int array)
127136
modifies sql data
128137
dynamic result sets 1

src/test/java/org/apache/ibatis/submitted/sptests/SPMapper.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.Map;
2020

2121
import org.apache.ibatis.annotations.Options;
22+
import org.apache.ibatis.annotations.Param;
2223
import org.apache.ibatis.annotations.Result;
2324
import org.apache.ibatis.annotations.ResultMap;
2425
import org.apache.ibatis.annotations.Results;
@@ -75,6 +76,11 @@ public interface SPMapper {
7576
@Options(statementType = StatementType.CALLABLE)
7677
List<Name> getNamesAnnotatedWithXMLResultMap(Map<String, Object> parms);
7778

79+
@Select({ "{call sptest.getnamesLowHigh(", "#{lowestId,jdbcType=INTEGER,mode=IN},", "#{highestId,jdbcType=INTEGER,mode=IN})}" })
80+
@ResultMap("nameResult")
81+
@Options(statementType = StatementType.CALLABLE)
82+
List<Name> getNamesAnnotatedLowHighWithXMLResultMap(@Param("lowestId") int lowestId, @Param("highestId") int highestId);
83+
7884
@Select({ "{call sptest.arraytest(", "#{ids,mode=IN,jdbcType=ARRAY},", "#{requestedRows,jdbcType=INTEGER,mode=OUT},", "#{returnedIds,mode=OUT,jdbcType=ARRAY})}" })
7985
@Results({ @Result(column = "ID", property = "id"), @Result(column = "FIRST_NAME", property = "firstName"), @Result(column = "LAST_NAME", property = "lastName") })
8086
@Options(statementType = StatementType.CALLABLE)

src/test/java/org/apache/ibatis/submitted/sptests/SPTest.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,25 @@ public void testCallWithResultSet4_a2() {
695695
}
696696
}
697697

698+
/*
699+
*
700+
* This test shows using a two named parameters.
701+
*
702+
* This test shows using annotations for stored procedures and using a
703+
* resultMap in XML
704+
*/
705+
@Test
706+
public void testCallLowHighWithResultSet() {
707+
SqlSession sqlSession = sqlSessionFactory.openSession();
708+
try {
709+
SPMapper spMapper = sqlSession.getMapper(SPMapper.class);
710+
List<Name> names = spMapper.getNamesAnnotatedLowHighWithXMLResultMap(1, 1);
711+
assertEquals(1, names.size());
712+
} finally {
713+
sqlSession.close();
714+
}
715+
}
716+
698717
/*
699718
* This test shows how to use the ARRAY JDBC type with MyBatis.
700719
*
@@ -818,5 +837,5 @@ public void testGetNamesAndItemsLinkedWithNoMatchingInfo() throws SQLException {
818837
sqlSession.close();
819838
}
820839
}
821-
840+
822841
}

0 commit comments

Comments
 (0)