Skip to content

Commit d7c3343

Browse files
committed
Re-formatted (no logical change).
1 parent e74f2bd commit d7c3343

File tree

6 files changed

+154
-146
lines changed

6 files changed

+154
-146
lines changed
Lines changed: 71 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2009-2016 the original author or authors.
2+
* Copyright 2009-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -40,75 +40,77 @@
4040
*/
4141
public final class LazyDeserializeTest {
4242

43-
private static final int FOO_ID = 1;
44-
private static final int BAR_ID = 10;
45-
private static SqlSessionFactory factory;
46-
47-
public static Configuration getConfiguration() {
48-
return factory.getConfiguration();
49-
}
50-
51-
@BeforeClass
52-
public static void setupClass() throws Exception {
53-
Connection conn = null;
54-
55-
try {
56-
Class.forName("org.hsqldb.jdbcDriver");
57-
conn = DriverManager.getConnection("jdbc:hsqldb:mem:lazy_deserialize", "sa", "");
58-
59-
Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/lazy_deserialize/CreateDB.sql");
60-
61-
ScriptRunner runner = new ScriptRunner(conn);
62-
runner.setLogWriter(null);
63-
runner.setErrorLogWriter(new PrintWriter(System.err));
64-
runner.runScript(reader);
65-
conn.commit();
66-
reader.close();
67-
68-
reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/lazy_deserialize/ibatisConfig.xml");
69-
factory = new SqlSessionFactoryBuilder().build(reader);
70-
reader.close();
71-
} finally {
72-
if (conn != null) {
73-
conn.close();
74-
}
75-
}
76-
}
77-
78-
@Test
79-
public void testLoadLazyDeserialize() throws Exception {
80-
final SqlSession session = factory.openSession();
81-
try {
82-
final Mapper mapper = session.getMapper(Mapper.class);
83-
final LazyObjectFoo foo = mapper.loadFoo(FOO_ID);
84-
85-
final byte[] serializedFoo = this.serializeFoo(foo);
86-
final LazyObjectFoo deserializedFoo = this.deserializeFoo(serializedFoo);
87-
88-
assertNotNull(deserializedFoo);
89-
assertEquals(Integer.valueOf(FOO_ID), deserializedFoo.getId());
90-
assertNotNull(deserializedFoo.getLazyObjectBar());
91-
assertEquals(Integer.valueOf(BAR_ID), deserializedFoo.getLazyObjectBar().getId());
92-
} finally {
93-
session.close();
94-
}
43+
private static final int FOO_ID = 1;
44+
private static final int BAR_ID = 10;
45+
private static SqlSessionFactory factory;
46+
47+
public static Configuration getConfiguration() {
48+
return factory.getConfiguration();
49+
}
50+
51+
@BeforeClass
52+
public static void setupClass() throws Exception {
53+
Connection conn = null;
54+
55+
try {
56+
Class.forName("org.hsqldb.jdbcDriver");
57+
conn = DriverManager.getConnection("jdbc:hsqldb:mem:lazy_deserialize", "sa", "");
58+
59+
Reader reader = Resources
60+
.getResourceAsReader("org/apache/ibatis/submitted/lazy_deserialize/CreateDB.sql");
61+
62+
ScriptRunner runner = new ScriptRunner(conn);
63+
runner.setLogWriter(null);
64+
runner.setErrorLogWriter(new PrintWriter(System.err));
65+
runner.runScript(reader);
66+
conn.commit();
67+
reader.close();
68+
69+
reader = Resources
70+
.getResourceAsReader("org/apache/ibatis/submitted/lazy_deserialize/ibatisConfig.xml");
71+
factory = new SqlSessionFactoryBuilder().build(reader);
72+
reader.close();
73+
} finally {
74+
if (conn != null) {
75+
conn.close();
76+
}
9577
}
96-
97-
private byte[] serializeFoo(final LazyObjectFoo foo) throws Exception {
98-
final ByteArrayOutputStream bos = new ByteArrayOutputStream();
99-
final ObjectOutputStream oos = new ObjectOutputStream(bos);
100-
oos.writeObject(foo);
101-
oos.close();
102-
103-
return bos.toByteArray();
104-
}
105-
106-
private LazyObjectFoo deserializeFoo(final byte[] serializedFoo) throws Exception {
107-
final ByteArrayInputStream bis = new ByteArrayInputStream(serializedFoo);
108-
final ObjectInputStream ios = new ObjectInputStream(bis);
109-
final LazyObjectFoo foo = LazyObjectFoo.class.cast(ios.readObject());
110-
ios.close();
111-
return foo;
78+
}
79+
80+
@Test
81+
public void testLoadLazyDeserialize() throws Exception {
82+
final SqlSession session = factory.openSession();
83+
try {
84+
final Mapper mapper = session.getMapper(Mapper.class);
85+
final LazyObjectFoo foo = mapper.loadFoo(FOO_ID);
86+
87+
final byte[] serializedFoo = this.serializeFoo(foo);
88+
final LazyObjectFoo deserializedFoo = this.deserializeFoo(serializedFoo);
89+
90+
assertNotNull(deserializedFoo);
91+
assertEquals(Integer.valueOf(FOO_ID), deserializedFoo.getId());
92+
assertNotNull(deserializedFoo.getLazyObjectBar());
93+
assertEquals(Integer.valueOf(BAR_ID), deserializedFoo.getLazyObjectBar().getId());
94+
} finally {
95+
session.close();
11296
}
97+
}
98+
99+
private byte[] serializeFoo(final LazyObjectFoo foo) throws Exception {
100+
final ByteArrayOutputStream bos = new ByteArrayOutputStream();
101+
final ObjectOutputStream oos = new ObjectOutputStream(bos);
102+
oos.writeObject(foo);
103+
oos.close();
104+
105+
return bos.toByteArray();
106+
}
107+
108+
private LazyObjectFoo deserializeFoo(final byte[] serializedFoo) throws Exception {
109+
final ByteArrayInputStream bis = new ByteArrayInputStream(serializedFoo);
110+
final ObjectInputStream ios = new ObjectInputStream(bis);
111+
final LazyObjectFoo foo = LazyObjectFoo.class.cast(ios.readObject());
112+
ios.close();
113+
return foo;
114+
}
113115

114116
}

src/test/java/org/apache/ibatis/submitted/lazy_deserialize/LazyObjectBar.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2009-2016 the original author or authors.
2+
* Copyright 2009-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -23,14 +23,15 @@
2323
*/
2424
public class LazyObjectBar implements Serializable {
2525

26-
private Integer id;
26+
private static final long serialVersionUID = 1L;
27+
private Integer id;
2728

28-
public Integer getId() {
29-
return id;
30-
}
29+
public Integer getId() {
30+
return id;
31+
}
3132

32-
public void setId(Integer id) {
33-
this.id = id;
34-
}
33+
public void setId(Integer id) {
34+
this.id = id;
35+
}
3536

3637
}

src/test/java/org/apache/ibatis/submitted/lazy_deserialize/LazyObjectFoo.java

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2009-2016 the original author or authors.
2+
* Copyright 2009-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -23,23 +23,24 @@
2323
*/
2424
public class LazyObjectFoo implements Serializable {
2525

26-
private Integer id;
27-
private LazyObjectBar lazyObjectBar;
26+
private static final long serialVersionUID = 1L;
27+
private Integer id;
28+
private LazyObjectBar lazyObjectBar;
2829

29-
public Integer getId() {
30-
return id;
31-
}
30+
public Integer getId() {
31+
return id;
32+
}
3233

33-
public void setId(Integer id) {
34-
this.id = id;
35-
}
34+
public void setId(Integer id) {
35+
this.id = id;
36+
}
3637

37-
public LazyObjectBar getLazyObjectBar() {
38-
return this.lazyObjectBar;
39-
}
38+
public LazyObjectBar getLazyObjectBar() {
39+
return this.lazyObjectBar;
40+
}
4041

41-
public void setLazyObjectBar(final LazyObjectBar lazyObjectBar) {
42-
this.lazyObjectBar = lazyObjectBar;
43-
}
42+
public void setLazyObjectBar(final LazyObjectBar lazyObjectBar) {
43+
this.lazyObjectBar = lazyObjectBar;
44+
}
4445

4546
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2009-2016 the original author or authors.
2+
* Copyright 2009-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -23,5 +23,5 @@
2323
*/
2424
public interface Mapper {
2525

26-
LazyObjectFoo loadFoo(@Param("fooId") int fooId);
26+
LazyObjectFoo loadFoo(@Param("fooId") int fooId);
2727
}
Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
22
<!--
33
4-
Copyright 2009-2016 the original author or authors.
4+
Copyright 2009-2017 the original author or authors.
55
66
Licensed under the Apache License, Version 2.0 (the "License");
77
you may not use this file except in compliance with the License.
@@ -22,28 +22,29 @@
2222

2323
<mapper namespace="org.apache.ibatis.submitted.lazy_deserialize.Mapper">
2424

25-
<resultMap id="resultFoo" type="LazyFoo">
26-
<id property="id" column="id" />
27-
<association property="lazyObjectBar" column="id_bar" select="loadBar" />
28-
</resultMap>
29-
30-
<resultMap id="resultBar" type="LazyBar">
31-
<id property="id" column="id" />
32-
</resultMap>
33-
34-
<select id="loadFoo" parameterType="int" resultMap="resultFoo">
35-
SELECT
36-
f.id AS id,
37-
f.id_bar AS id_bar
38-
FROM table_foo AS f
39-
WHERE f.id = #{fooId}
40-
</select>
41-
42-
<select id="loadBar" parameterType="int" resultMap="resultBar">
43-
SELECT
44-
b.id AS id
45-
FROM table_bar AS b
46-
WHERE b.id = #{barId}
47-
</select>
48-
49-
</mapper>
25+
<resultMap id="resultFoo" type="LazyFoo">
26+
<id property="id" column="id" />
27+
<association property="lazyObjectBar" column="id_bar"
28+
select="loadBar" />
29+
</resultMap>
30+
31+
<resultMap id="resultBar" type="LazyBar">
32+
<id property="id" column="id" />
33+
</resultMap>
34+
35+
<select id="loadFoo" parameterType="int" resultMap="resultFoo">
36+
SELECT
37+
f.id AS id,
38+
f.id_bar AS id_bar
39+
FROM table_foo AS f
40+
WHERE f.id = #{fooId}
41+
</select>
42+
43+
<select id="loadBar" parameterType="int" resultMap="resultBar">
44+
SELECT
45+
b.id AS id
46+
FROM table_bar AS b
47+
WHERE b.id = #{barId}
48+
</select>
49+
50+
</mapper>
Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
22
<!--
33
4-
Copyright 2009-2016 the original author or authors.
4+
Copyright 2009-2017 the original author or authors.
55
66
Licensed under the Apache License, Version 2.0 (the "License");
77
you may not use this file except in compliance with the License.
@@ -21,29 +21,32 @@
2121
"http://mybatis.org/dtd/mybatis-3-config.dtd">
2222

2323
<configuration>
24-
<settings>
25-
<setting name="lazyLoadingEnabled" value="true"/>
26-
<setting name="aggressiveLazyLoading" value="false" />
27-
<setting name="configurationFactory" value="org.apache.ibatis.submitted.lazy_deserialize.LazyDeserializeTest" />
28-
</settings>
29-
30-
<typeAliases>
31-
<typeAlias alias="LazyFoo" type="org.apache.ibatis.submitted.lazy_deserialize.LazyObjectFoo"/>
32-
<typeAlias alias="LazyBar" type="org.apache.ibatis.submitted.lazy_deserialize.LazyObjectBar"/>
33-
</typeAliases>
34-
35-
<environments default="test">
36-
<environment id="test">
37-
<transactionManager type="JDBC"></transactionManager>
38-
<dataSource type="UNPOOLED">
39-
<property name="driver" value="org.hsqldb.jdbcDriver"/>
40-
<property name="url" value="jdbc:hsqldb:mem:lazy_deserialize"/>
41-
<property name="username" value="sa"/>
42-
</dataSource>
43-
</environment>
44-
</environments>
45-
46-
<mappers>
47-
<mapper resource="org/apache/ibatis/submitted/lazy_deserialize/Mapper.xml"/>
48-
</mappers>
24+
<settings>
25+
<setting name="lazyLoadingEnabled" value="true" />
26+
<setting name="aggressiveLazyLoading" value="false" />
27+
<setting name="configurationFactory"
28+
value="org.apache.ibatis.submitted.lazy_deserialize.LazyDeserializeTest" />
29+
</settings>
30+
31+
<typeAliases>
32+
<typeAlias alias="LazyFoo"
33+
type="org.apache.ibatis.submitted.lazy_deserialize.LazyObjectFoo" />
34+
<typeAlias alias="LazyBar"
35+
type="org.apache.ibatis.submitted.lazy_deserialize.LazyObjectBar" />
36+
</typeAliases>
37+
38+
<environments default="test">
39+
<environment id="test">
40+
<transactionManager type="JDBC"></transactionManager>
41+
<dataSource type="UNPOOLED">
42+
<property name="driver" value="org.hsqldb.jdbcDriver" />
43+
<property name="url" value="jdbc:hsqldb:mem:lazy_deserialize" />
44+
<property name="username" value="sa" />
45+
</dataSource>
46+
</environment>
47+
</environments>
48+
49+
<mappers>
50+
<mapper resource="org/apache/ibatis/submitted/lazy_deserialize/Mapper.xml" />
51+
</mappers>
4952
</configuration>

0 commit comments

Comments
 (0)