Skip to content

Commit 4e1c015

Browse files
committed
Simpler test for #149.
1 parent a91f6c8 commit 4e1c015

File tree

9 files changed

+28
-285
lines changed

9 files changed

+28
-285
lines changed

src/test/java/org/apache/ibatis/builder/BlogMapper.xml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,17 @@
5555
select count(1) from post
5656
</select>
5757

58+
<resultMap id="blogWithPostsLazy" type="Blog">
59+
<id property="id" column="id"/>
60+
<result property="title" column="title"/>
61+
<association property="author" column="author_id" select="domain.blog.mappers.AuthorMapper.selectAuthorWithInlineParams" lazy="true"/>
62+
<collection property="posts" column="id" select="selectPostsForBlog" lazy="true"/>
63+
</resultMap>
64+
65+
<select id="selectBlogWithPostsUsingSubSelectLazily" parameterType="int" resultMap="blogWithPostsLazy">
66+
select * from Blog where id = #{id}
67+
</select>
68+
5869
<resultMap id="joinedAuthor" type="domain.blog.Author">
5970
<id property="id" column="author_id"/>
6071
<result property="username" column="author_username"/>
@@ -139,7 +150,6 @@
139150
where B.id = #{id}
140151
</select>
141152

142-
143153
<select id="selectAllPosts" resultType="hashmap">
144154
select * from post order by id
145155
</select>

src/test/java/org/apache/ibatis/session/SqlSessionTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.apache.ibatis.executor.result.DefaultResultHandler;
3636
import org.apache.ibatis.io.Resources;
3737
import org.apache.ibatis.session.defaults.DefaultSqlSessionFactory;
38+
import org.junit.Assert;
3839
import org.junit.BeforeClass;
3940
import org.junit.Test;
4041

@@ -386,6 +387,22 @@ public void shouldSelectBlogWithPostsAndAuthorUsingSubSelects() throws Exception
386387
}
387388
}
388389

390+
@Test
391+
public void shouldSelectBlogWithPostsAndAuthorUsingSubSelectsLazily() throws Exception {
392+
SqlSession session = sqlMapper.openSession();
393+
try {
394+
Blog blog = session.selectOne("domain.blog.mappers.BlogMapper.selectBlogWithPostsUsingSubSelectLazily", 1);
395+
Assert.assertTrue(blog.getClass().getName().contains("CGLIB"));
396+
assertEquals("Jim Business", blog.getTitle());
397+
assertEquals(2, blog.getPosts().size());
398+
assertEquals("Corn nuts", blog.getPosts().get(0).getSubject());
399+
assertEquals(101, blog.getAuthor().getId());
400+
assertEquals("jim", blog.getAuthor().getUsername());
401+
} finally {
402+
session.close();
403+
}
404+
}
405+
389406
@Test
390407
public void shouldSelectBlogWithPostsAndAuthorUsingJoin() throws Exception {
391408
SqlSession session = sqlMapper.openSession();

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

Lines changed: 0 additions & 31 deletions
This file was deleted.

src/test/java/org/apache/ibatis/submitted/finelazyloading/FineLazyLoadingTest.java

Lines changed: 0 additions & 67 deletions
This file was deleted.

src/test/java/org/apache/ibatis/submitted/finelazyloading/Group.java

Lines changed: 0 additions & 38 deletions
This file was deleted.

src/test/java/org/apache/ibatis/submitted/finelazyloading/Mapper.java

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/test/java/org/apache/ibatis/submitted/finelazyloading/Mapper.xml

Lines changed: 0 additions & 37 deletions
This file was deleted.

src/test/java/org/apache/ibatis/submitted/finelazyloading/User.java

Lines changed: 0 additions & 49 deletions
This file was deleted.

src/test/java/org/apache/ibatis/submitted/finelazyloading/mybatis-config.xml

Lines changed: 0 additions & 40 deletions
This file was deleted.

0 commit comments

Comments
 (0)