Skip to content

Commit 66efde5

Browse files
committed
ASL headers and formatting [ci skip]. Related to #307.
1 parent b789646 commit 66efde5

File tree

4 files changed

+182
-146
lines changed

4 files changed

+182
-146
lines changed
Lines changed: 62 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,66 @@
1+
/*
2+
* Copyright 2009-2014 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+
*/
116
package org.apache.ibatis.submitted.nestedresulthandler_multiple_association;
217

318
public class Binome<T, U> {
4-
private T one;
5-
private U two;
6-
7-
public Binome() {
8-
}
9-
10-
public Binome(final T one, final U two) {
11-
this.one = one;
12-
this.two = two;
13-
}
14-
15-
public T getOne() {
16-
return one;
17-
}
18-
19-
public void setOne(T one) {
20-
this.one = one;
21-
}
22-
23-
public U getTwo() {
24-
return two;
25-
}
26-
27-
public void setTwo(U two) {
28-
this.two = two;
29-
}
30-
31-
@Override
32-
public int hashCode() {
33-
return (one != null ? one.hashCode() : 0) + (two != null ? two.hashCode() : 0);
34-
}
35-
36-
@Override
37-
public boolean equals(final Object obj) {
38-
if (obj instanceof Binome<?, ?>) {
39-
Binome<?, ?> bin = (Binome<?, ?>) obj;
40-
return one != null && one.equals(bin.getOne()) && two != null && two.equals(bin.getTwo());
41-
}
42-
return super.equals(obj);
43-
}
44-
45-
@Override
46-
public String toString() {
47-
return "Binome [one=" + one + ", two=" + two + "]";
48-
}
19+
private T one;
20+
private U two;
21+
22+
public Binome() {
23+
}
24+
25+
public Binome(final T one, final U two) {
26+
this.one = one;
27+
this.two = two;
28+
}
29+
30+
public T getOne() {
31+
return one;
32+
}
33+
34+
public void setOne(T one) {
35+
this.one = one;
36+
}
37+
38+
public U getTwo() {
39+
return two;
40+
}
41+
42+
public void setTwo(U two) {
43+
this.two = two;
44+
}
45+
46+
@Override
47+
public int hashCode() {
48+
return (one != null ? one.hashCode() : 0)
49+
+ (two != null ? two.hashCode() : 0);
50+
}
51+
52+
@Override
53+
public boolean equals(final Object obj) {
54+
if (obj instanceof Binome<?, ?>) {
55+
Binome<?, ?> bin = (Binome<?, ?>) obj;
56+
return one != null && one.equals(bin.getOne()) && two != null
57+
&& two.equals(bin.getTwo());
58+
}
59+
return super.equals(obj);
60+
}
61+
62+
@Override
63+
public String toString() {
64+
return "Binome [one=" + one + ", two=" + two + "]";
65+
}
4966
}
Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,42 @@
1+
/*
2+
* Copyright 2009-2014 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+
*/
116
package org.apache.ibatis.submitted.nestedresulthandler_multiple_association;
217

318
public class ChildBean {
4-
private Integer id;
5-
private String value;
19+
private Integer id;
20+
private String value;
621

7-
public Integer getId() {
8-
return id;
9-
}
22+
public Integer getId() {
23+
return id;
24+
}
1025

11-
public void setId(Integer id) {
12-
this.id = id;
13-
}
26+
public void setId(Integer id) {
27+
this.id = id;
28+
}
1429

15-
public String getValue() {
16-
return value;
17-
}
30+
public String getValue() {
31+
return value;
32+
}
1833

19-
public void setValue(String value) {
20-
this.value = value;
21-
}
34+
public void setValue(String value) {
35+
this.value = value;
36+
}
2237

23-
@Override
24-
public String toString() {
25-
return "ChildBean [id=" + id + ", value=" + value + "]";
26-
}
38+
@Override
39+
public String toString() {
40+
return "ChildBean [id=" + id + ", value=" + value + "]";
41+
}
2742
}

src/test/java/org/apache/ibatis/submitted/nestedresulthandler_multiple_association/NestedResultHandlerMultipleAssociationTest.java

Lines changed: 50 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -30,60 +30,63 @@
3030

3131
public class NestedResultHandlerMultipleAssociationTest {
3232

33-
private static SqlSessionFactory sqlSessionFactory;
33+
private static SqlSessionFactory sqlSessionFactory;
3434

35-
@BeforeClass
36-
public static void setUp() throws Exception {
37-
// create an SqlSessionFactory
38-
Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/nestedresulthandler_multiple_association/mybatis-config.xml");
39-
sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
40-
reader.close();
35+
@BeforeClass
36+
public static void setUp() throws Exception {
37+
// create an SqlSessionFactory
38+
Reader reader = Resources
39+
.getResourceAsReader("org/apache/ibatis/submitted/nestedresulthandler_multiple_association/mybatis-config.xml");
40+
sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
41+
reader.close();
4142

42-
// populate in-memory database
43-
SqlSession session = sqlSessionFactory.openSession();
44-
Connection conn = session.getConnection();
45-
reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/nestedresulthandler_multiple_association/CreateDB.sql");
46-
ScriptRunner runner = new ScriptRunner(conn);
47-
runner.setLogWriter(null);
48-
runner.runScript(reader);
49-
reader.close();
50-
session.close();
51-
}
43+
// populate in-memory database
44+
SqlSession session = sqlSessionFactory.openSession();
45+
Connection conn = session.getConnection();
46+
reader = Resources
47+
.getResourceAsReader("org/apache/ibatis/submitted/nestedresulthandler_multiple_association/CreateDB.sql");
48+
ScriptRunner runner = new ScriptRunner(conn);
49+
runner.setLogWriter(null);
50+
runner.runScript(reader);
51+
reader.close();
52+
session.close();
53+
}
5254

53-
@Test
54-
public void failure() throws Exception {
55-
SqlSession sqlSession = sqlSessionFactory.openSession();
55+
@Test
56+
public void failure() throws Exception {
57+
SqlSession sqlSession = sqlSessionFactory.openSession();
5658

57-
// Parents have child going from somewhere to somewhere, they are stored in a Binome object
58-
// In this test we have 2 parents:
59-
// Parent1 is going from Child1 to Child2
60-
// Parent2 is going from Child2 to Child3 and from Child1 to Child2
61-
// You'll see a NULL entry in the list instead of the Binome Child1/Child2
62-
List<ParentBean> list = sqlSession.selectList("selectParentBeans");
63-
for (ParentBean pb : list) {
64-
for (Binome<ChildBean, ChildBean> childs : pb.getChilds()) {
65-
Assert.assertNotNull(childs);
66-
Assert.assertNotNull(childs.getOne());
67-
Assert.assertNotNull(childs.getTwo());
68-
}
69-
}
59+
// Parents have child going from somewhere to somewhere, they are stored in
60+
// a Binome object
61+
// In this test we have 2 parents:
62+
// Parent1 is going from Child1 to Child2
63+
// Parent2 is going from Child2 to Child3 and from Child1 to Child2
64+
// You'll see a NULL entry in the list instead of the Binome Child1/Child2
65+
List<ParentBean> list = sqlSession.selectList("selectParentBeans");
66+
for (ParentBean pb : list) {
67+
for (Binome<ChildBean, ChildBean> childs : pb.getChilds()) {
68+
Assert.assertNotNull(childs);
69+
Assert.assertNotNull(childs.getOne());
70+
Assert.assertNotNull(childs.getTwo());
71+
}
72+
}
7073

71-
sqlSession.close();
72-
}
74+
sqlSession.close();
75+
}
7376

74-
@Test
75-
public void success() throws Exception {
76-
SqlSession sqlSession = sqlSessionFactory.openSession();
77+
@Test
78+
public void success() throws Exception {
79+
SqlSession sqlSession = sqlSessionFactory.openSession();
7780

78-
ParentBean parent = sqlSession.selectOne("selectParentBeanById", 2);
81+
ParentBean parent = sqlSession.selectOne("selectParentBeanById", 2);
7982

80-
// If you only select the Parent2 it works
81-
for (Binome<ChildBean, ChildBean> childs : parent.getChilds()) {
82-
Assert.assertNotNull(childs);
83-
Assert.assertNotNull(childs.getOne());
84-
Assert.assertNotNull(childs.getTwo());
85-
}
86-
sqlSession.close();
87-
}
83+
// If you only select the Parent2 it works
84+
for (Binome<ChildBean, ChildBean> childs : parent.getChilds()) {
85+
Assert.assertNotNull(childs);
86+
Assert.assertNotNull(childs.getOne());
87+
Assert.assertNotNull(childs.getTwo());
88+
}
89+
sqlSession.close();
90+
}
8891

8992
}

src/test/java/org/apache/ibatis/submitted/nestedresulthandler_multiple_association/ParentBean.java

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,41 @@
33
import java.util.List;
44

55
public class ParentBean {
6-
private Integer id;
7-
private String value;
8-
private List<Binome<ChildBean, ChildBean>> childs;
9-
10-
public Integer getId() {
11-
return id;
12-
}
13-
14-
public void setId(Integer id) {
15-
this.id = id;
16-
}
17-
18-
public String getValue() {
19-
return value;
20-
}
21-
22-
public void setValue(String value) {
23-
this.value = value;
24-
}
25-
26-
public List<Binome<ChildBean, ChildBean>> getChilds() {
27-
return childs;
28-
}
29-
30-
public void setChilds(List<Binome<ChildBean, ChildBean>> childs) {
31-
this.childs = childs;
32-
}
33-
34-
@Override
35-
public String toString() {
36-
StringBuilder sb = new StringBuilder("ParentBean [id=" + id + ", value=" + value + "]\nChilds:\n");
37-
for (Binome<ChildBean, ChildBean> binome : childs) {
38-
sb.append("\tChild : ").append(binome).append('\n');
39-
}
40-
return sb.toString();
41-
}
6+
private Integer id;
7+
private String value;
8+
private List<Binome<ChildBean, ChildBean>> childs;
9+
10+
public Integer getId() {
11+
return id;
12+
}
13+
14+
public void setId(Integer id) {
15+
this.id = id;
16+
}
17+
18+
public String getValue() {
19+
return value;
20+
}
21+
22+
public void setValue(String value) {
23+
this.value = value;
24+
}
25+
26+
public List<Binome<ChildBean, ChildBean>> getChilds() {
27+
return childs;
28+
}
29+
30+
public void setChilds(List<Binome<ChildBean, ChildBean>> childs) {
31+
this.childs = childs;
32+
}
33+
34+
@Override
35+
public String toString() {
36+
StringBuilder sb = new StringBuilder("ParentBean [id=" + id + ", value="
37+
+ value + "]\nChilds:\n");
38+
for (Binome<ChildBean, ChildBean> binome : childs) {
39+
sb.append("\tChild : ").append(binome).append('\n');
40+
}
41+
return sb.toString();
42+
}
4243
}

0 commit comments

Comments
 (0)