From 74dbd199fe6acff98c497d6dd00e232bb20c3eb7 Mon Sep 17 00:00:00 2001 From: vikram barbade Date: Thu, 29 Aug 2024 16:44:22 -0700 Subject: [PATCH] SNOW-1491028 : Snowflake JDBC Driver 4.2 compliant issue. (#1857) --- .../client/jdbc/SnowflakeConnectionV1.java | 11 ++++++++++- .../jdbc/ConnectionFeatureNotSupportedIT.java | 2 ++ .../net/snowflake/client/jdbc/ConnectionIT.java | 2 +- .../client/jdbc/ConnectionLatestIT.java | 17 +++++++++++++++++ ...alConnectionFeatureNotSupportedLatestIT.java | 2 -- 5 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/snowflake/client/jdbc/SnowflakeConnectionV1.java b/src/main/java/net/snowflake/client/jdbc/SnowflakeConnectionV1.java index 473aa2041..498e6393b 100644 --- a/src/main/java/net/snowflake/client/jdbc/SnowflakeConnectionV1.java +++ b/src/main/java/net/snowflake/client/jdbc/SnowflakeConnectionV1.java @@ -597,7 +597,16 @@ public int getHoldability() throws SQLException { @Override public void setHoldability(int holdability) throws SQLException { - throw new SnowflakeLoggedFeatureNotSupportedException(sfSession); + raiseSQLExceptionIfConnectionIsClosed(); + if ((holdability != ResultSet.CLOSE_CURSORS_AT_COMMIT + && holdability != ResultSet.HOLD_CURSORS_OVER_COMMIT)) { + throw new SQLException("The given parameter is not a ResultSet holdability constant."); + } + // HOLD_CURSORS_OVER_COMMIT holdability is currently not supported. + // no-op if the holdability is CLOSE_CURSORS_AT_COMMIT + if (holdability == ResultSet.HOLD_CURSORS_OVER_COMMIT) { + throw new SnowflakeLoggedFeatureNotSupportedException(sfSession); + } } @Override diff --git a/src/test/java/net/snowflake/client/jdbc/ConnectionFeatureNotSupportedIT.java b/src/test/java/net/snowflake/client/jdbc/ConnectionFeatureNotSupportedIT.java index ae6d1fac4..f91eee092 100644 --- a/src/test/java/net/snowflake/client/jdbc/ConnectionFeatureNotSupportedIT.java +++ b/src/test/java/net/snowflake/client/jdbc/ConnectionFeatureNotSupportedIT.java @@ -43,6 +43,8 @@ public void testFeatureNotSupportedException() throws Throwable { expectFeatureNotSupportedException(connection::createSQLXML); expectFeatureNotSupportedException( () -> connection.createStruct("fakeType", new Object[] {})); + expectFeatureNotSupportedException( + () -> connection.setHoldability(ResultSet.HOLD_CURSORS_OVER_COMMIT)); } } diff --git a/src/test/java/net/snowflake/client/jdbc/ConnectionIT.java b/src/test/java/net/snowflake/client/jdbc/ConnectionIT.java index 0b8115d02..b32ca01c8 100644 --- a/src/test/java/net/snowflake/client/jdbc/ConnectionIT.java +++ b/src/test/java/net/snowflake/client/jdbc/ConnectionIT.java @@ -743,7 +743,7 @@ public void testGetTypeMap() throws Throwable { public void testHolderbility() throws Throwable { try (Connection connection = getConnection()) { try { - connection.setHoldability(0); + connection.setHoldability(ResultSet.HOLD_CURSORS_OVER_COMMIT); } catch (SQLFeatureNotSupportedException ex) { // nop } diff --git a/src/test/java/net/snowflake/client/jdbc/ConnectionLatestIT.java b/src/test/java/net/snowflake/client/jdbc/ConnectionLatestIT.java index 445860545..efed33896 100644 --- a/src/test/java/net/snowflake/client/jdbc/ConnectionLatestIT.java +++ b/src/test/java/net/snowflake/client/jdbc/ConnectionLatestIT.java @@ -37,6 +37,7 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; +import java.sql.SQLFeatureNotSupportedException; import java.sql.Statement; import java.time.Duration; import java.util.ArrayList; @@ -1589,6 +1590,22 @@ public void shouldGetDifferentTimestampLtzConsistentBetweenFormats() throws Exce } } + @Test + public void testSetHoldability() throws Throwable { + try (Connection connection = getConnection()) { + try { + connection.setHoldability(ResultSet.CLOSE_CURSORS_AT_COMMIT); + } catch (SQLFeatureNotSupportedException ex) { + fail("should not fail"); + } + // return an empty type map. setTypeMap is not supported. + assertEquals(ResultSet.CLOSE_CURSORS_AT_COMMIT, connection.getHoldability()); + connection.close(); + expectConnectionAlreadyClosedException( + () -> connection.setHoldability(ResultSet.CLOSE_CURSORS_AT_COMMIT)); + } + } + /** Added in > 3.14.5 and modified in > 3.18.0 */ @Test public void shouldGetOverridenConnectionAndSocketTimeouts() throws Exception { diff --git a/src/test/java/net/snowflake/client/pooling/LogicalConnectionFeatureNotSupportedLatestIT.java b/src/test/java/net/snowflake/client/pooling/LogicalConnectionFeatureNotSupportedLatestIT.java index 97d50970c..39df72aa2 100644 --- a/src/test/java/net/snowflake/client/pooling/LogicalConnectionFeatureNotSupportedLatestIT.java +++ b/src/test/java/net/snowflake/client/pooling/LogicalConnectionFeatureNotSupportedLatestIT.java @@ -66,8 +66,6 @@ public void testLogicalConnectionFeatureNotSupported() throws SQLException { expectFeatureNotSupportedException(logicalConnection::createBlob); expectFeatureNotSupportedException(logicalConnection::createNClob); expectFeatureNotSupportedException(logicalConnection::createSQLXML); - expectFeatureNotSupportedException( - () -> logicalConnection.setHoldability(ResultSet.CLOSE_CURSORS_AT_COMMIT)); expectFeatureNotSupportedException( () -> logicalConnection.setHoldability(ResultSet.HOLD_CURSORS_OVER_COMMIT)); expectFeatureNotSupportedException(