From 4a0e58aa13eed831e7e1c8e6379a22a3fefa2698 Mon Sep 17 00:00:00 2001 From: Eduardo Macarron Date: Wed, 24 Apr 2013 20:57:21 +0200 Subject: [PATCH] Added test for multiple result sets with no matching information --- .../apache/ibatis/submitted/sptests/CreateDB.sql | 11 +++++++++++ .../apache/ibatis/submitted/sptests/SPMapper.java | 2 ++ .../apache/ibatis/submitted/sptests/SPMapper.xml | 11 +++++++++++ .../apache/ibatis/submitted/sptests/SPTest.java | 14 ++++++++++++++ 4 files changed, 38 insertions(+) diff --git a/src/test/java/org/apache/ibatis/submitted/sptests/CreateDB.sql b/src/test/java/org/apache/ibatis/submitted/sptests/CreateDB.sql index b18f8091f06..cf3f2ef4177 100644 --- a/src/test/java/org/apache/ibatis/submitted/sptests/CreateDB.sql +++ b/src/test/java/org/apache/ibatis/submitted/sptests/CreateDB.sql @@ -102,6 +102,17 @@ BEGIN ATOMIC END go +create procedure sptest.getnamesanditemsbyid(in nameId integer) +modifies sql data +dynamic result sets 2 +BEGIN ATOMIC + declare cur1 cursor for select * from sptest.names where id = nameId; + declare cur2 cursor for select * from sptest.items where name_id in (select id from sptest.names where id = nameId); + open cur1; + open cur2; +END +go + create procedure sptest.getnames(in lowestId int, out totalrows integer) modifies sql data dynamic result sets 1 diff --git a/src/test/java/org/apache/ibatis/submitted/sptests/SPMapper.java b/src/test/java/org/apache/ibatis/submitted/sptests/SPMapper.java index 59165f64ec6..d46f8acaadb 100644 --- a/src/test/java/org/apache/ibatis/submitted/sptests/SPMapper.java +++ b/src/test/java/org/apache/ibatis/submitted/sptests/SPMapper.java @@ -43,6 +43,8 @@ public interface SPMapper { List> getNamesAndItems(); List getNamesAndItemsLinked(); + + List getNamesAndItemsLinkedById(int id); // annotated @Select({ "{call sptest.adder(", "#{addend1,jdbcType=INTEGER,mode=IN},", "#{addend2,jdbcType=INTEGER,mode=IN},", "#{sum,jdbcType=INTEGER,mode=OUT})}" }) diff --git a/src/test/java/org/apache/ibatis/submitted/sptests/SPMapper.xml b/src/test/java/org/apache/ibatis/submitted/sptests/SPMapper.xml index 748d49e0d76..29c9d0e0592 100644 --- a/src/test/java/org/apache/ibatis/submitted/sptests/SPMapper.xml +++ b/src/test/java/org/apache/ibatis/submitted/sptests/SPMapper.xml @@ -32,6 +32,13 @@ + + + + + + + @@ -109,5 +116,9 @@ + + diff --git a/src/test/java/org/apache/ibatis/submitted/sptests/SPTest.java b/src/test/java/org/apache/ibatis/submitted/sptests/SPTest.java index 5afad5397ae..9fea1c256af 100644 --- a/src/test/java/org/apache/ibatis/submitted/sptests/SPTest.java +++ b/src/test/java/org/apache/ibatis/submitted/sptests/SPTest.java @@ -790,4 +790,18 @@ public void testGetNamesAndItemsLinked() throws SQLException { } } + @Test + public void testGetNamesAndItemsLinkedWithNoMatchingInfo() throws SQLException { + SqlSession sqlSession = sqlSessionFactory.openSession(); + try { + SPMapper spMapper = sqlSession.getMapper(SPMapper.class); + + List names = spMapper.getNamesAndItemsLinkedById(0); + assertEquals(1, names.size()); + assertEquals(2, names.get(0).getItems().size()); + } finally { + sqlSession.close(); + } + } + }