Skip to content

Commit 1edff06

Browse files
committed
refs #492 Added a test case. Thanks to Erwan Letessier.
https://groups.google.com/d/msg/mybatis-user/dqHzZjyZ4zo/E50uPsCgAQAJ
1 parent cfa0874 commit 1edff06

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/test/java/org/apache/ibatis/submitted/usesjava8/refcursor/CreateDB.sql

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,13 @@ CREATE OR REPLACE FUNCTION mbtest.get_order_out_params(
8484
detail_count out integer,
8585
header_curs out refcursor
8686
) AS $BODY$
87+
DECLARE
88+
order_exists boolean;
8789
BEGIN
88-
open header_curs for select * from mbtest.order_header where order_id = ORDER_NUMBER;
90+
select order_id is not null into order_exists from mbtest.order_header where order_id = ORDER_NUMBER;
91+
if order_exists then
92+
open header_curs for select * from mbtest.order_header where order_id = ORDER_NUMBER;
93+
end if;
8994
select count(*) into detail_count from mbtest.order_detail where order_id = ORDER_NUMBER;
9095
END;
9196
$BODY$

src/test/java/org/apache/ibatis/submitted/usesjava8/refcursor/RefCursorTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,4 +146,20 @@ List<Order> getResult() {
146146
assertEquals("Anonymous", handler.getResult().get(0).getCustomerName());
147147
}
148148
}
149+
150+
@Test
151+
public void shouldNullResultSetNotCauseNpe() throws IOException {
152+
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
153+
OrdersMapper mapper = sqlSession.getMapper(OrdersMapper.class);
154+
Map<String, Object> parameter = new HashMap<String, Object>();
155+
parameter.put("orderId", 99);
156+
mapper.getOrder3(parameter, new ResultHandler<Order>() {
157+
@Override
158+
public void handleResult(ResultContext<? extends Order> resultContext) {
159+
// won't be used
160+
}
161+
});
162+
assertEquals(Integer.valueOf(0), parameter.get("detailCount"));
163+
}
164+
}
149165
}

0 commit comments

Comments
 (0)