From 6e042655c6c10a067f43963c84e94faba4a05148 Mon Sep 17 00:00:00 2001 From: Luke Hutteman Date: Wed, 6 Mar 2019 19:32:00 -0500 Subject: [PATCH 1/2] Change Cursor to implement AutoCloseable instead of Closeable, and override close() to no longer throw IOException --- src/main/java/org/apache/ibatis/cursor/Cursor.java | 8 +++++++- .../apache/ibatis/session/defaults/DefaultSqlSession.java | 6 +----- src/test/java/org/apache/ibatis/binding/BindingTest.java | 2 -- .../ibatis/submitted/cursor_simple/CursorSimpleTest.java | 8 ++++---- .../submitted/cursor_simple/PostgresCursorTest.java | 2 +- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/apache/ibatis/cursor/Cursor.java b/src/main/java/org/apache/ibatis/cursor/Cursor.java index 2529384ba47..25fcb53404e 100644 --- a/src/main/java/org/apache/ibatis/cursor/Cursor.java +++ b/src/main/java/org/apache/ibatis/cursor/Cursor.java @@ -25,7 +25,7 @@ * * @author Guillaume Darmont / guillaume@dropinocean.com */ -public interface Cursor extends Closeable, Iterable { +public interface Cursor extends AutoCloseable, Iterable { /** * @return true if the cursor has started to fetch items from database. @@ -43,4 +43,10 @@ public interface Cursor extends Closeable, Iterable { * @return -1 if the first cursor item has not been retrieved. The index of the current item retrieved. */ int getCurrentIndex(); + + /** + * Closes the cursor. + */ + @Override + void close(); } diff --git a/src/main/java/org/apache/ibatis/session/defaults/DefaultSqlSession.java b/src/main/java/org/apache/ibatis/session/defaults/DefaultSqlSession.java index 45d91622e1d..a85316e844a 100644 --- a/src/main/java/org/apache/ibatis/session/defaults/DefaultSqlSession.java +++ b/src/main/java/org/apache/ibatis/session/defaults/DefaultSqlSession.java @@ -271,11 +271,7 @@ public void close() { private void closeCursors() { if (cursorList != null && cursorList.size() != 0) { for (Cursor cursor : cursorList) { - try { - cursor.close(); - } catch (IOException e) { - throw ExceptionFactory.wrapException("Error closing cursor. Cause: " + e, e); - } + cursor.close(); } cursorList.clear(); } diff --git a/src/test/java/org/apache/ibatis/binding/BindingTest.java b/src/test/java/org/apache/ibatis/binding/BindingTest.java index 63aa65df566..fb617b81bfe 100644 --- a/src/test/java/org/apache/ibatis/binding/BindingTest.java +++ b/src/test/java/org/apache/ibatis/binding/BindingTest.java @@ -675,8 +675,6 @@ void executeWithCursorAndRowBounds() { assertEquals(2, blog.getId()); assertFalse(blogIterator.hasNext()); } - } catch (IOException e) { - Assertions.fail(e.getMessage()); } } diff --git a/src/test/java/org/apache/ibatis/submitted/cursor_simple/CursorSimpleTest.java b/src/test/java/org/apache/ibatis/submitted/cursor_simple/CursorSimpleTest.java index b63b4f939a0..fe26a6ecc8d 100644 --- a/src/test/java/org/apache/ibatis/submitted/cursor_simple/CursorSimpleTest.java +++ b/src/test/java/org/apache/ibatis/submitted/cursor_simple/CursorSimpleTest.java @@ -158,7 +158,7 @@ void testCursorWithRowBound() { } @Test - void testCursorIteratorNoSuchElementExceptionWithHasNext() throws IOException { + void testCursorIteratorNoSuchElementExceptionWithHasNext() { try (SqlSession sqlSession = sqlSessionFactory.openSession(); Cursor usersCursor = sqlSession.selectCursor("getAllUsers", null, new RowBounds(1, 1))) { @@ -180,7 +180,7 @@ void testCursorIteratorNoSuchElementExceptionWithHasNext() throws IOException { } @Test - void testCursorIteratorNoSuchElementExceptionNoHasNext() throws IOException { + void testCursorIteratorNoSuchElementExceptionNoHasNext() { try (SqlSession sqlSession = sqlSessionFactory.openSession(); Cursor usersCursor = sqlSession.selectCursor("getAllUsers", null, new RowBounds(1, 1))) { try { @@ -257,7 +257,7 @@ void testCursorMultipleIteratorCall() { } @Test - void testCursorMultipleCloseCall() throws IOException { + void testCursorMultipleCloseCall() { try (SqlSession sqlSession = sqlSessionFactory.openSession()) { Mapper mapper = sqlSession.getMapper(Mapper.class); Cursor usersCursor = mapper.getAllUsers(); @@ -287,7 +287,7 @@ void testCursorMultipleCloseCall() throws IOException { } @Test - void testCursorUsageAfterClose() throws IOException { + void testCursorUsageAfterClose() { try (SqlSession sqlSession = sqlSessionFactory.openSession()) { Mapper mapper = sqlSession.getMapper(Mapper.class); diff --git a/src/test/java/org/apache/ibatis/submitted/cursor_simple/PostgresCursorTest.java b/src/test/java/org/apache/ibatis/submitted/cursor_simple/PostgresCursorTest.java index b75fa6f5a7b..96399a72879 100644 --- a/src/test/java/org/apache/ibatis/submitted/cursor_simple/PostgresCursorTest.java +++ b/src/test/java/org/apache/ibatis/submitted/cursor_simple/PostgresCursorTest.java @@ -71,7 +71,7 @@ static void tearDown() { } @Test - void shouldBeAbleToReuseStatement() throws IOException { + void shouldBeAbleToReuseStatement() { // #1351 try (SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.REUSE)) { Mapper mapper = sqlSession.getMapper(Mapper.class); From b5da351cec7c1d7a5dcc1d1b0203ca8aae9ea3b1 Mon Sep 17 00:00:00 2001 From: Iwao AVE! Date: Fri, 3 Jan 2025 06:51:11 +0900 Subject: [PATCH 2/2] License years --- src/main/java/org/apache/ibatis/cursor/Cursor.java | 2 +- .../org/apache/ibatis/session/defaults/DefaultSqlSession.java | 2 +- .../apache/ibatis/submitted/cursor_simple/CursorSimpleTest.java | 2 +- .../ibatis/submitted/cursor_simple/PostgresCursorTest.java | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/apache/ibatis/cursor/Cursor.java b/src/main/java/org/apache/ibatis/cursor/Cursor.java index aebe664ee50..d2ccc04fea6 100644 --- a/src/main/java/org/apache/ibatis/cursor/Cursor.java +++ b/src/main/java/org/apache/ibatis/cursor/Cursor.java @@ -1,5 +1,5 @@ /* - * Copyright 2009-2023 the original author or authors. + * Copyright 2009-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/main/java/org/apache/ibatis/session/defaults/DefaultSqlSession.java b/src/main/java/org/apache/ibatis/session/defaults/DefaultSqlSession.java index 6b15a7edfba..a72c932edd3 100644 --- a/src/main/java/org/apache/ibatis/session/defaults/DefaultSqlSession.java +++ b/src/main/java/org/apache/ibatis/session/defaults/DefaultSqlSession.java @@ -1,5 +1,5 @@ /* - * Copyright 2009-2024 the original author or authors. + * Copyright 2009-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/test/java/org/apache/ibatis/submitted/cursor_simple/CursorSimpleTest.java b/src/test/java/org/apache/ibatis/submitted/cursor_simple/CursorSimpleTest.java index 294e2d6a53d..783857717da 100644 --- a/src/test/java/org/apache/ibatis/submitted/cursor_simple/CursorSimpleTest.java +++ b/src/test/java/org/apache/ibatis/submitted/cursor_simple/CursorSimpleTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2009-2024 the original author or authors. + * Copyright 2009-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/test/java/org/apache/ibatis/submitted/cursor_simple/PostgresCursorTest.java b/src/test/java/org/apache/ibatis/submitted/cursor_simple/PostgresCursorTest.java index fc869f7a00d..b9924b2a8df 100644 --- a/src/test/java/org/apache/ibatis/submitted/cursor_simple/PostgresCursorTest.java +++ b/src/test/java/org/apache/ibatis/submitted/cursor_simple/PostgresCursorTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2009-2023 the original author or authors. + * Copyright 2009-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License.