Skip to content

Commit 6e04265

Browse files
committed
Change Cursor to implement AutoCloseable instead of Closeable, and override close() to no longer throw IOException
1 parent 4b91bc7 commit 6e04265

File tree

5 files changed

+13
-13
lines changed

5 files changed

+13
-13
lines changed

src/main/java/org/apache/ibatis/cursor/Cursor.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
*
2626
* @author Guillaume Darmont / [email protected]
2727
*/
28-
public interface Cursor<T> extends Closeable, Iterable<T> {
28+
public interface Cursor<T> extends AutoCloseable, Iterable<T> {
2929

3030
/**
3131
* @return true if the cursor has started to fetch items from database.
@@ -43,4 +43,10 @@ public interface Cursor<T> extends Closeable, Iterable<T> {
4343
* @return -1 if the first cursor item has not been retrieved. The index of the current item retrieved.
4444
*/
4545
int getCurrentIndex();
46+
47+
/**
48+
* Closes the cursor.
49+
*/
50+
@Override
51+
void close();
4652
}

src/main/java/org/apache/ibatis/session/defaults/DefaultSqlSession.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -271,11 +271,7 @@ public void close() {
271271
private void closeCursors() {
272272
if (cursorList != null && cursorList.size() != 0) {
273273
for (Cursor<?> cursor : cursorList) {
274-
try {
275-
cursor.close();
276-
} catch (IOException e) {
277-
throw ExceptionFactory.wrapException("Error closing cursor. Cause: " + e, e);
278-
}
274+
cursor.close();
279275
}
280276
cursorList.clear();
281277
}

src/test/java/org/apache/ibatis/binding/BindingTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -675,8 +675,6 @@ void executeWithCursorAndRowBounds() {
675675
assertEquals(2, blog.getId());
676676
assertFalse(blogIterator.hasNext());
677677
}
678-
} catch (IOException e) {
679-
Assertions.fail(e.getMessage());
680678
}
681679
}
682680

src/test/java/org/apache/ibatis/submitted/cursor_simple/CursorSimpleTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ void testCursorWithRowBound() {
158158
}
159159

160160
@Test
161-
void testCursorIteratorNoSuchElementExceptionWithHasNext() throws IOException {
161+
void testCursorIteratorNoSuchElementExceptionWithHasNext() {
162162

163163
try (SqlSession sqlSession = sqlSessionFactory.openSession();
164164
Cursor<User> usersCursor = sqlSession.selectCursor("getAllUsers", null, new RowBounds(1, 1))) {
@@ -180,7 +180,7 @@ void testCursorIteratorNoSuchElementExceptionWithHasNext() throws IOException {
180180
}
181181

182182
@Test
183-
void testCursorIteratorNoSuchElementExceptionNoHasNext() throws IOException {
183+
void testCursorIteratorNoSuchElementExceptionNoHasNext() {
184184
try (SqlSession sqlSession = sqlSessionFactory.openSession();
185185
Cursor<User> usersCursor = sqlSession.selectCursor("getAllUsers", null, new RowBounds(1, 1))) {
186186
try {
@@ -257,7 +257,7 @@ void testCursorMultipleIteratorCall() {
257257
}
258258

259259
@Test
260-
void testCursorMultipleCloseCall() throws IOException {
260+
void testCursorMultipleCloseCall() {
261261
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
262262
Mapper mapper = sqlSession.getMapper(Mapper.class);
263263
Cursor<User> usersCursor = mapper.getAllUsers();
@@ -287,7 +287,7 @@ void testCursorMultipleCloseCall() throws IOException {
287287
}
288288

289289
@Test
290-
void testCursorUsageAfterClose() throws IOException {
290+
void testCursorUsageAfterClose() {
291291

292292
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
293293
Mapper mapper = sqlSession.getMapper(Mapper.class);

src/test/java/org/apache/ibatis/submitted/cursor_simple/PostgresCursorTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ static void tearDown() {
7171
}
7272

7373
@Test
74-
void shouldBeAbleToReuseStatement() throws IOException {
74+
void shouldBeAbleToReuseStatement() {
7575
// #1351
7676
try (SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.REUSE)) {
7777
Mapper mapper = sqlSession.getMapper(Mapper.class);

0 commit comments

Comments
 (0)