Skip to content

Commit 93757d2

Browse files
committed
Failing test cases for #215 (ignored for now). It might be related to #39 as well.
1 parent 0261d32 commit 93757d2

File tree

6 files changed

+293
-0
lines changed

6 files changed

+293
-0
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/**
2+
* Copyright 2009-2016 the original author or authors.
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 org.apache.ibatis.submitted.ancestor_ref;
17+
18+
import static org.junit.Assert.*;
19+
20+
import java.io.Reader;
21+
import java.sql.Connection;
22+
23+
import org.apache.ibatis.io.Resources;
24+
import org.apache.ibatis.jdbc.ScriptRunner;
25+
import org.apache.ibatis.session.SqlSession;
26+
import org.apache.ibatis.session.SqlSessionFactory;
27+
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
28+
import org.junit.BeforeClass;
29+
import org.junit.Ignore;
30+
import org.junit.Test;
31+
32+
public class AncestorRefTest {
33+
private static SqlSessionFactory sqlSessionFactory;
34+
35+
@BeforeClass
36+
public static void setUp() throws Exception {
37+
// create an SqlSessionFactory
38+
Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/ancestor_ref/mybatis-config.xml");
39+
sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
40+
reader.close();
41+
42+
// populate in-memory database
43+
SqlSession session = sqlSessionFactory.openSession();
44+
Connection conn = session.getConnection();
45+
reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/ancestor_ref/CreateDB.sql");
46+
ScriptRunner runner = new ScriptRunner(conn);
47+
runner.setLogWriter(null);
48+
runner.runScript(reader);
49+
reader.close();
50+
session.close();
51+
}
52+
53+
@Ignore("issue #215")
54+
@Test
55+
public void testCircularAssociation() {
56+
SqlSession sqlSession = sqlSessionFactory.openSession();
57+
try {
58+
Mapper mapper = sqlSession.getMapper(Mapper.class);
59+
User user = mapper.getUserAssociation(1);
60+
assertEquals("User2", user.getFriend().getName());
61+
} finally {
62+
sqlSession.close();
63+
}
64+
}
65+
66+
@Ignore("issue #215")
67+
@Test
68+
public void testCircularCollection() {
69+
SqlSession sqlSession = sqlSessionFactory.openSession();
70+
try {
71+
Mapper mapper = sqlSession.getMapper(Mapper.class);
72+
User user = mapper.getUserCollection(2);
73+
assertEquals("User2", user.getFriends().get(0).getName());
74+
assertEquals("User3", user.getFriends().get(1).getName());
75+
} finally {
76+
sqlSession.close();
77+
}
78+
}
79+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
--
2+
-- Copyright 2009-2016 the original author or authors.
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+
17+
drop table users if exists;
18+
drop table friend if exists;
19+
20+
create table users (
21+
id int,
22+
name varchar(20)
23+
);
24+
25+
create table friend (
26+
user_id int,
27+
friend_id int
28+
);
29+
30+
insert into users (id, name) values
31+
(1, 'User1'), (2, 'User2'), (3, 'User3');
32+
33+
insert into friend (user_id, friend_id) values
34+
(1, 2), (2, 2), (2, 3);
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* Copyright 2009-2016 the original author or authors.
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 org.apache.ibatis.submitted.ancestor_ref;
17+
18+
public interface Mapper {
19+
20+
User getUserAssociation(Integer id);
21+
User getUserCollection(Integer id);
22+
23+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
Copyright 2009-2016 the original author or authors.
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
18+
-->
19+
<!DOCTYPE mapper
20+
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
21+
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
22+
23+
<mapper namespace="org.apache.ibatis.submitted.ancestor_ref.Mapper">
24+
25+
<resultMap type="org.apache.ibatis.submitted.ancestor_ref.User"
26+
id="userMapAssociation">
27+
<id property="id" column="id" />
28+
<result property="name" column="name" />
29+
<association property="friend" resultMap="userMapAssociation"
30+
columnPrefix="friend_" />
31+
</resultMap>
32+
33+
<select id="getUserAssociation" resultMap="userMapAssociation">
34+
select u.id, u.name, uf.id friend_id, uf.name friend_name
35+
from users u
36+
left join friend f on f.user_id = u.id
37+
left join users uf on uf.id = f.friend_id
38+
where u.id = #{id}
39+
</select>
40+
41+
<resultMap type="org.apache.ibatis.submitted.ancestor_ref.User"
42+
id="userMapCollection">
43+
<id property="id" column="id" />
44+
<result property="name" column="name" />
45+
<collection property="friends" resultMap="userMapCollection"
46+
columnPrefix="friend_" />
47+
</resultMap>
48+
49+
<select id="getUserCollection" resultMap="userMapCollection">
50+
select u.id, u.name, uf.id friend_id, uf.name friend_name
51+
from users u
52+
left join friend f on f.user_id = u.id
53+
left join users uf on uf.id = f.friend_id
54+
where u.id = #{id}
55+
order by uf.id
56+
</select>
57+
58+
</mapper>
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/**
2+
* Copyright 2009-2016 the original author or authors.
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 org.apache.ibatis.submitted.ancestor_ref;
17+
18+
import java.util.List;
19+
20+
public class User {
21+
private Integer id;
22+
private String name;
23+
private User friend;
24+
private List<User> friends;
25+
26+
public Integer getId() {
27+
return id;
28+
}
29+
30+
public void setId(Integer id) {
31+
this.id = id;
32+
}
33+
34+
public String getName() {
35+
return name;
36+
}
37+
38+
public void setName(String name) {
39+
this.name = name;
40+
}
41+
42+
public User getFriend() {
43+
return friend;
44+
}
45+
46+
public void setFriend(User friend) {
47+
this.friend = friend;
48+
}
49+
50+
public List<User> getFriends() {
51+
return friends;
52+
}
53+
54+
public void setFriends(List<User> friends) {
55+
this.friends = friends;
56+
}
57+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<!--
3+
4+
Copyright 2009-2016 the original author or authors.
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
18+
-->
19+
<!DOCTYPE configuration
20+
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
21+
"http://mybatis.org/dtd/mybatis-3-config.dtd">
22+
23+
<configuration>
24+
25+
<environments default="development">
26+
<environment id="development">
27+
<transactionManager type="JDBC">
28+
<property name="" value="" />
29+
</transactionManager>
30+
<dataSource type="UNPOOLED">
31+
<property name="driver" value="org.hsqldb.jdbcDriver" />
32+
<property name="url" value="jdbc:hsqldb:mem:ancestorref" />
33+
<property name="username" value="sa" />
34+
</dataSource>
35+
</environment>
36+
</environments>
37+
38+
<mappers>
39+
<mapper class="org.apache.ibatis.submitted.ancestor_ref.Mapper" />
40+
</mappers>
41+
42+
</configuration>

0 commit comments

Comments
 (0)