Skip to content

Commit 9745e2b

Browse files
committed
Merge branch 'master' of https://github.com/FrantaM/mybatis-3
2 parents d0a120e + 7375e5a commit 9745e2b

File tree

3 files changed

+86
-0
lines changed

3 files changed

+86
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright 2013 MyBatis.org.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package domain.blog;
17+
18+
import java.util.List;
19+
20+
public class BlogLite {
21+
22+
private int id;
23+
private List<PostLite> posts;
24+
25+
public int getId() {
26+
return id;
27+
}
28+
29+
public void setId(int id) {
30+
this.id = id;
31+
}
32+
33+
public List<PostLite> getPosts() {
34+
return posts;
35+
}
36+
37+
public void setPosts(List<PostLite> posts) {
38+
this.posts = posts;
39+
}
40+
}

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,26 @@
3535
</constructor>
3636
</resultMap>
3737

38+
<resultMap id="postLiteMap2NestedWithSelect" type="domain.blog.BlogLite">
39+
<id column="blog_id" property="id" />
40+
<collection property="posts" ofType="domain.blog.PostLite">
41+
<constructor>
42+
<arg javaType="domain.blog.PostLiteId" column="{id=id}" select="selectPostLiteId" />
43+
<arg javaType="_int" column="blog_id"/>
44+
</constructor>
45+
</collection>
46+
</resultMap>
47+
48+
<resultMap id="postLiteMap2NestedWithoutSelect" type="domain.blog.BlogLite">
49+
<id column="blog_id" property="id" />
50+
<collection property="posts" ofType="domain.blog.PostLite">
51+
<constructor>
52+
<arg javaType="domain.blog.PostLiteId" resultMap="postLiteIdMap" />
53+
<arg javaType="_int" column="blog_id"/>
54+
</constructor>
55+
</collection>
56+
</resultMap>
57+
3858
<resultMap id="mutablePostLiteMap" type="domain.blog.PostLite">
3959
<result property="blogId" column="blog_id"/>
4060
<association property="id" column="id" resultMap="postLiteIdMap"/>
@@ -48,6 +68,18 @@
4868
select id, blog_id from post where blog_id is not null
4969
</select>
5070

71+
<select id="selectPostLite2NestedWithSelect" resultMap="postLiteMap2NestedWithSelect">
72+
select id, 1 as blog_id from post where blog_id is not null
73+
</select>
74+
75+
<select id="selectPostLite2NestedWithoutSelect" resultMap="postLiteMap2NestedWithoutSelect">
76+
select id, 1 as blog_id from post where blog_id is not null
77+
</select>
78+
79+
<select id="selectPostLiteId" resultMap="postLiteIdMap">
80+
select ${id} as id from (values(0)) as t
81+
</select>
82+
5183
<select id="selectMutablePostLite" resultMap="mutablePostLiteMap">
5284
select id, blog_id from post where blog_id is not null
5385
</select>

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,20 @@ public void shouldFindAllPostLites() throws Exception {
479479
assertEquals(4, posts.size());
480480
}
481481

482+
@Test
483+
public void shouldFindAllPostLitesWithNestedSelect() throws Exception {
484+
final BlogLite blog = manager.selectOne("domain.blog.mappers.PostMapper.selectPostLite2NestedWithSelect");
485+
assertNotNull(blog);
486+
assertEquals(4, blog.getPosts().size());
487+
}
488+
489+
@Test
490+
public void shouldFindAllPostLitesWithNestedResultMap() throws Exception {
491+
final BlogLite blog = manager.selectOne("domain.blog.mappers.PostMapper.selectPostLite2NestedWithoutSelect");
492+
assertNotNull(blog);
493+
assertEquals(4, blog.getPosts().size());
494+
}
495+
482496
@Test
483497
public void shouldFindAllMutablePostLites() throws Exception {
484498
List<PostLite> posts = manager.selectList("domain.blog.mappers.PostMapper.selectMutablePostLite");

0 commit comments

Comments
 (0)