Skip to content

Commit bce6fca

Browse files
committedMar 11, 2023
Format, license header
1 parent 9a4fc60 commit bce6fca

File tree

15 files changed

+91
-97
lines changed

15 files changed

+91
-97
lines changed
 

‎src/site/es/xdoc/sqlmap-xml.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!--
33
4-
Copyright 2009-2022 the original author or authors.
4+
Copyright 2009-2023 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.

‎src/site/ja/xdoc/sqlmap-xml.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!--
33
4-
Copyright 2009-2022 the original author or authors.
4+
Copyright 2009-2023 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.

‎src/site/xdoc/sqlmap-xml.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!--
33
4-
Copyright 2009-2022 the original author or authors.
4+
Copyright 2009-2023 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.

‎src/test/java/org/apache/ibatis/submitted/cursor_cache_oom/CursorOomTest.java

Lines changed: 55 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -38,77 +38,70 @@
3838
@SuppressWarnings("ALL")
3939
class CursorOomTest {
4040

41-
private static SqlSessionFactory sqlSessionFactory;
41+
private static SqlSessionFactory sqlSessionFactory;
4242

43-
@BeforeAll
44-
static void setUp() throws Exception {
45-
// create an SqlSessionFactory
46-
try (Reader reader = Resources.getResourceAsReader(
47-
"org/apache/ibatis/submitted/cursor_cache_oom/mybatis-config.xml")) {
48-
sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
49-
}
50-
51-
// populate in-memory database
52-
BaseDataTest.runScript(
53-
sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(),
54-
"org/apache/ibatis/submitted/cursor_cache_oom/CreateDB.sql"
55-
);
43+
@BeforeAll
44+
static void setUp() throws Exception {
45+
// create an SqlSessionFactory
46+
try (Reader reader = Resources
47+
.getResourceAsReader("org/apache/ibatis/submitted/cursor_cache_oom/mybatis-config.xml")) {
48+
sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
5649
}
5750

58-
private static Map<CacheKey, Object> getNestedResultObjects(Cursor<User> users) throws IllegalAccessException,
59-
NoSuchFieldException {
60-
DefaultCursor<User> defaultCursor = (DefaultCursor<User>) users;
61-
Field resultSetHandlerField = DefaultCursor.class.getDeclaredField("resultSetHandler");
62-
resultSetHandlerField.setAccessible(true);
63-
DefaultResultSetHandler defaultResultSetHandler =
64-
(DefaultResultSetHandler) resultSetHandlerField
65-
.get(defaultCursor);
66-
Field nestedResultObjectsField = DefaultResultSetHandler.class.getDeclaredField("nestedResultObjects");
67-
nestedResultObjectsField.setAccessible(true);
68-
return (Map<CacheKey, Object>) nestedResultObjectsField
69-
.get(defaultResultSetHandler);
70-
}
51+
// populate in-memory database
52+
BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(),
53+
"org/apache/ibatis/submitted/cursor_cache_oom/CreateDB.sql");
54+
}
7155

72-
private static List<Cursor<?>> getCursors(SqlSession sqlSession)
73-
throws NoSuchFieldException, IllegalAccessException {
74-
DefaultSqlSession session = (DefaultSqlSession) sqlSession;
75-
Field cursorListField = DefaultSqlSession.class.getDeclaredField("cursorList");
76-
cursorListField.setAccessible(true);
77-
List<Cursor<?>> cursorList =
78-
(List<Cursor<?>>) cursorListField.get(session);
79-
return cursorList;
80-
}
56+
private static Map<CacheKey, Object> getNestedResultObjects(Cursor<User> users)
57+
throws IllegalAccessException, NoSuchFieldException {
58+
DefaultCursor<User> defaultCursor = (DefaultCursor<User>) users;
59+
Field resultSetHandlerField = DefaultCursor.class.getDeclaredField("resultSetHandler");
60+
resultSetHandlerField.setAccessible(true);
61+
DefaultResultSetHandler defaultResultSetHandler = (DefaultResultSetHandler) resultSetHandlerField
62+
.get(defaultCursor);
63+
Field nestedResultObjectsField = DefaultResultSetHandler.class.getDeclaredField("nestedResultObjects");
64+
nestedResultObjectsField.setAccessible(true);
65+
return (Map<CacheKey, Object>) nestedResultObjectsField.get(defaultResultSetHandler);
66+
}
8167

82-
@Test
83-
void shouldNotCacheAllDataForWholeSessionWhileUsingCursor() throws IOException, NoSuchFieldException,
84-
IllegalAccessException {
85-
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
86-
Mapper mapper = sqlSession.getMapper(Mapper.class);
87-
try (Cursor<User> users = mapper.fetchUsers()) {
88-
for (User user : users) {
89-
consumeUser(user);
90-
}
91-
Map nestedResultObjects = getNestedResultObjects(users);
68+
private static List<Cursor<?>> getCursors(SqlSession sqlSession) throws NoSuchFieldException, IllegalAccessException {
69+
DefaultSqlSession session = (DefaultSqlSession) sqlSession;
70+
Field cursorListField = DefaultSqlSession.class.getDeclaredField("cursorList");
71+
cursorListField.setAccessible(true);
72+
List<Cursor<?>> cursorList = (List<Cursor<?>>) cursorListField.get(session);
73+
return cursorList;
74+
}
9275

93-
Assertions.assertFalse(nestedResultObjects.isEmpty());
76+
@Test
77+
void shouldNotCacheAllDataForWholeSessionWhileUsingCursor()
78+
throws IOException, NoSuchFieldException, IllegalAccessException {
79+
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
80+
Mapper mapper = sqlSession.getMapper(Mapper.class);
81+
try (Cursor<User> users = mapper.fetchUsers()) {
82+
for (User user : users) {
83+
consumeUser(user);
84+
}
85+
Map nestedResultObjects = getNestedResultObjects(users);
9486

95-
// does not pass now
96-
// will be great, if cursor will use constant memory instead of linear one
97-
// Assertions.assertTrue(nestedResultObjects.size() <= 2);
98-
}
87+
Assertions.assertFalse(nestedResultObjects.isEmpty());
9988

100-
List<Cursor<?>> cursorList = getCursors(sqlSession);
89+
// does not pass now
90+
// will be great, if cursor will use constant memory instead of linear one
91+
// Assertions.assertTrue(nestedResultObjects.size() <= 2);
92+
}
10193

102-
// expect that either reference to the cursor itselfis gone or cursor does not contains all the fetched data
103-
// the most preferrable way will be not to cache data, when the row is already processed (see commented
104-
// line above)
105-
Assertions.assertTrue(
106-
cursorList.isEmpty() || getNestedResultObjects((Cursor<User>) cursorList.get(0)).size() <= 2
107-
);
108-
}
109-
}
94+
List<Cursor<?>> cursorList = getCursors(sqlSession);
11095

111-
private void consumeUser(User user) {
112-
// do nothing
96+
// expect that either reference to the cursor itselfis gone or cursor does not contains all the fetched data
97+
// the most preferrable way will be not to cache data, when the row is already processed (see commented
98+
// line above)
99+
Assertions
100+
.assertTrue(cursorList.isEmpty() || getNestedResultObjects((Cursor<User>) cursorList.get(0)).size() <= 2);
113101
}
102+
}
103+
104+
private void consumeUser(User user) {
105+
// do nothing
106+
}
114107
}

‎src/test/java/org/apache/ibatis/submitted/cursor_cache_oom/Friend.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2009-2022 the original author or authors.
2+
* Copyright 2009-2023 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.

‎src/test/java/org/apache/ibatis/submitted/cursor_cache_oom/Mapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2009-2022 the original author or authors.
2+
* Copyright 2009-2023 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.
Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2009-2022 the original author or authors.
2+
* Copyright 2009-2023 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.
@@ -17,31 +17,31 @@
1717

1818
public class User {
1919

20-
private Integer id;
21-
private String name;
22-
private Friend friend;
20+
private Integer id;
21+
private String name;
22+
private Friend friend;
2323

24-
public Integer getId() {
25-
return id;
26-
}
24+
public Integer getId() {
25+
return id;
26+
}
2727

28-
public void setId(Integer id) {
29-
this.id = id;
30-
}
28+
public void setId(Integer id) {
29+
this.id = id;
30+
}
3131

32-
public String getName() {
33-
return name;
34-
}
32+
public String getName() {
33+
return name;
34+
}
3535

36-
public void setName(String name) {
37-
this.name = name;
38-
}
36+
public void setName(String name) {
37+
this.name = name;
38+
}
3939

40-
public Friend getFriend() {
41-
return friend;
42-
}
40+
public Friend getFriend() {
41+
return friend;
42+
}
4343

44-
public void setFriend(Friend friend) {
45-
this.friend = friend;
46-
}
44+
public void setFriend(Friend friend) {
45+
this.friend = friend;
46+
}
4747
}

‎src/test/java/org/apache/ibatis/submitted/unmatched_prop_type/UnmatchedPropTypeMapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2009-2022 the original author or authors.
2+
* Copyright 2009-2023 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.

‎src/test/java/org/apache/ibatis/submitted/unmatched_prop_type/UnmatchedPropTypeTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ class UnmatchedPropTypeTest {
3232

3333
@BeforeAll
3434
static void setUp() throws Exception {
35-
try (Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/unmatched_prop_type/mybatis-config.xml")) {
35+
try (Reader reader = Resources
36+
.getResourceAsReader("org/apache/ibatis/submitted/unmatched_prop_type/mybatis-config.xml")) {
3637
sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
3738
}
3839
BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(),

‎src/test/java/org/apache/ibatis/submitted/unmatched_prop_type/User.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2009-2022 the original author or authors.
2+
* Copyright 2009-2023 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.

‎src/test/resources/org/apache/ibatis/submitted/cursor_cache_oom/CreateDB.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--
2-
-- Copyright 2009-2022 the original author or authors.
2+
-- Copyright 2009-2023 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.

‎src/test/resources/org/apache/ibatis/submitted/cursor_cache_oom/Mapper.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!--
33
4-
Copyright 2009-2022 the original author or authors.
4+
Copyright 2009-2023 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.

‎src/test/resources/org/apache/ibatis/submitted/cursor_cache_oom/mybatis-config.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8" ?>
22
<!--
33
4-
Copyright 2009-2022 the original author or authors.
4+
Copyright 2009-2023 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.

‎src/test/resources/org/apache/ibatis/submitted/unmatched_prop_type/CreateDB.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--
2-
-- Copyright 2009-2022 the original author or authors.
2+
-- Copyright 2009-2023 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.

‎src/test/resources/org/apache/ibatis/submitted/unmatched_prop_type/mybatis-config.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8" ?>
22
<!--
33
4-
Copyright 2009-2022 the original author or authors.
4+
Copyright 2009-2023 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.

0 commit comments

Comments
 (0)
Please sign in to comment.