Repository: calcite-avatica Updated Branches: refs/heads/master 8e2a250df -> 02726a87c
[CALCITE-2140] Basic implementation of Statement#getMoreResults() Add a basic implementation of Statement#getMoreResults() and Statement#getMoreResults(int), only supporting CLOSE_CURRENT_RESULT. Closes apache/calcite-avatica#24 Project: http://git-wip-us.apache.org/repos/asf/calcite-avatica/repo Commit: http://git-wip-us.apache.org/repos/asf/calcite-avatica/commit/02d00b77 Tree: http://git-wip-us.apache.org/repos/asf/calcite-avatica/tree/02d00b77 Diff: http://git-wip-us.apache.org/repos/asf/calcite-avatica/diff/02d00b77 Branch: refs/heads/master Commit: 02d00b7718e1680f3c29d623c9fd688c398b7bf0 Parents: 8e2a250 Author: Laurent Goujon <laur...@dremio.com> Authored: Tue Feb 27 17:08:36 2018 -0800 Committer: Julian Hyde <jh...@apache.org> Committed: Tue Feb 27 18:48:07 2018 -0800 ---------------------------------------------------------------------- .../calcite/avatica/AvaticaStatement.java | 23 ++++++++++++++++++-- .../java/org/apache/calcite/avatica/Helper.java | 4 ++++ .../calcite/avatica/AvaticaStatementTest.java | 18 +++++++++++++++ 3 files changed, 43 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/02d00b77/core/src/main/java/org/apache/calcite/avatica/AvaticaStatement.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/avatica/AvaticaStatement.java b/core/src/main/java/org/apache/calcite/avatica/AvaticaStatement.java index 2900229..dcb2188 100644 --- a/core/src/main/java/org/apache/calcite/avatica/AvaticaStatement.java +++ b/core/src/main/java/org/apache/calcite/avatica/AvaticaStatement.java @@ -366,7 +366,7 @@ public abstract class AvaticaStatement } public boolean getMoreResults() throws SQLException { - throw connection.helper.unsupported(); + return getMoreResults(CLOSE_CURRENT_RESULT); } public void setFetchDirection(int direction) throws SQLException { @@ -420,7 +420,26 @@ public abstract class AvaticaStatement } public boolean getMoreResults(int current) throws SQLException { - throw connection.helper.unsupported(); + if (closed) { + throw connection.helper.closed(); + } + switch (current) { + case KEEP_CURRENT_RESULT: + case CLOSE_ALL_RESULTS: + throw connection.helper.unsupported(); + + case CLOSE_CURRENT_RESULT: + break; + + default: + throw connection.helper.createException("value " + current + + " is not one of CLOSE_CURRENT_RESULT, KEEP_CURRENT_RESULT or CLOSE_ALL_RESULTS"); + } + + if (openResultSet != null) { + openResultSet.close(); + } + return false; } public ResultSet getGeneratedKeys() throws SQLException { http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/02d00b77/core/src/main/java/org/apache/calcite/avatica/Helper.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/avatica/Helper.java b/core/src/main/java/org/apache/calcite/avatica/Helper.java index 27c6056..fe716db 100644 --- a/core/src/main/java/org/apache/calcite/avatica/Helper.java +++ b/core/src/main/java/org/apache/calcite/avatica/Helper.java @@ -64,6 +64,10 @@ public class Helper { return exception; } + public SQLException closed() { + return createException("Connection closed"); + } + public SQLException unsupported() { return new SQLFeatureNotSupportedException(); } http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/02d00b77/core/src/test/java/org/apache/calcite/avatica/AvaticaStatementTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/calcite/avatica/AvaticaStatementTest.java b/core/src/test/java/org/apache/calcite/avatica/AvaticaStatementTest.java index 5f6b56a..ca18f4a 100644 --- a/core/src/test/java/org/apache/calcite/avatica/AvaticaStatementTest.java +++ b/core/src/test/java/org/apache/calcite/avatica/AvaticaStatementTest.java @@ -19,10 +19,16 @@ package org.apache.calcite.avatica; import org.junit.Before; import org.junit.Test; +import java.sql.ResultSet; import java.sql.SQLException; import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertFalse; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.Mockito.doCallRealMethod; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; /** @@ -46,6 +52,18 @@ public class AvaticaStatementTest { assertArrayEquals(intValues, statement.executeBatch()); assertArrayEquals(longValues, statement.executeLargeBatch()); } + + @Test public void testGetMoreResults() throws SQLException { + AvaticaResultSet resultSet = mock(AvaticaResultSet.class); + statement.openResultSet = resultSet; + + doCallRealMethod().when(statement).onResultSetClose(any(ResultSet.class)); + when(statement.getMoreResults()).thenCallRealMethod(); + when(statement.getMoreResults(anyInt())).thenCallRealMethod(); + + assertFalse(statement.getMoreResults()); + verify(resultSet).close(); + } } // End AvaticaStatementTest.java