File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed
src/test/java/org/apache/ibatis/submitted/usesjava8/refcursor Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -84,8 +84,13 @@ CREATE OR REPLACE FUNCTION mbtest.get_order_out_params(
84
84
detail_count out integer ,
85
85
header_curs out refcursor
86
86
) AS $BODY$
87
+ DECLARE
88
+ order_exists boolean ;
87
89
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;
89
94
select count (* ) into detail_count from mbtest .order_detail where order_id = ORDER_NUMBER;
90
95
END;
91
96
$BODY$
Original file line number Diff line number Diff line change @@ -146,4 +146,20 @@ List<Order> getResult() {
146
146
assertEquals ("Anonymous" , handler .getResult ().get (0 ).getCustomerName ());
147
147
}
148
148
}
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
+ }
149
165
}
You can’t perform that action at this time.
0 commit comments