Skip to content

Commit

Permalink
Added test for multiple result sets with no matching information
Browse files Browse the repository at this point in the history
  • Loading branch information
emacarron committed Apr 24, 2013
1 parent 4f2f1e5 commit 4a0e58a
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/test/java/org/apache/ibatis/submitted/sptests/CreateDB.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public interface SPMapper {
List<List<?>> getNamesAndItems();

List<Name> getNamesAndItemsLinked();

List<Name> getNamesAndItemsLinkedById(int id);

// annotated
@Select({ "{call sptest.adder(", "#{addend1,jdbcType=INTEGER,mode=IN},", "#{addend2,jdbcType=INTEGER,mode=IN},", "#{sum,jdbcType=INTEGER,mode=OUT})}" })
Expand Down
11 changes: 11 additions & 0 deletions src/test/java/org/apache/ibatis/submitted/sptests/SPMapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@
<collection property="items" column="id" foreignColumn="name_id" resultSet="items" resultMap="itemResult"/>
</resultMap>

<resultMap type="org.apache.ibatis.submitted.sptests.Name" id="nameResultLinkedNoMatchingInfo">
<result column="ID" property="id"/>
<result column="FIRST_NAME" property="firstName"/>
<result column="LAST_NAME" property="lastName"/>
<collection property="items" resultSet="items" resultMap="itemResult"/>
</resultMap>

<resultMap type="org.apache.ibatis.submitted.sptests.Item" id="itemResult">
<result column="ID" property="id"/>
<result column="ITEM" property="item"/>
Expand Down Expand Up @@ -109,5 +116,9 @@
<select id="getNamesAndItemsLinked" statementType="CALLABLE" resultSets="names,items" resultMap="nameResultLinked">
{call sptest.getnamesanditems()}
</select>

<select id="getNamesAndItemsLinkedById" statementType="CALLABLE" resultSets="names,items" resultMap="nameResultLinkedNoMatchingInfo">
{call sptest.getnamesanditemsbyid(#{id,jdbcType=INTEGER,mode=IN})}
</select>

</mapper>
14 changes: 14 additions & 0 deletions src/test/java/org/apache/ibatis/submitted/sptests/SPTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Name> names = spMapper.getNamesAndItemsLinkedById(0);
assertEquals(1, names.size());
assertEquals(2, names.get(0).getItems().size());
} finally {
sqlSession.close();
}
}

}

0 comments on commit 4a0e58a

Please sign in to comment.