From b6367bafe2927fa0afa3f5b755478c2b89124c37 Mon Sep 17 00:00:00 2001 From: ulvii Date: Tue, 17 Apr 2018 17:18:07 -0700 Subject: [PATCH 1/3] Removing checkClosed() from SQLServerResultSetMetaData. Result set metadata should be accesible after result set is closed --- .../jdbc/SQLServerResultSetMetaData.java | 42 ------------------- 1 file changed, 42 deletions(-) diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResultSetMetaData.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResultSetMetaData.java index 66e801a231..c9aa686a63 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResultSetMetaData.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResultSetMetaData.java @@ -55,10 +55,6 @@ final public String toString() { } } - private void checkClosed() throws SQLServerException { - rs.checkClosed(); - } - /* ------------------ JDBC API Methods --------------------- */ public boolean isWrapperFor(Class iface) throws SQLException { @@ -78,20 +74,14 @@ public T unwrap(Class iface) throws SQLException { } public String getCatalogName(int column) throws SQLServerException { - checkClosed(); return rs.getColumn(column).getTableName().getDatabaseName(); } /* L0 */ public int getColumnCount() throws SQLServerException { - checkClosed(); - if (rs == null) - return 0; return rs.getColumnCount(); } public int getColumnDisplaySize(int column) throws SQLServerException { - checkClosed(); - CryptoMetadata cryptoMetadata = rs.getColumn(column).getCryptoMetadata(); if (null != cryptoMetadata) { return cryptoMetadata.getBaseTypeInfo().getDisplaySize(); @@ -101,17 +91,14 @@ public int getColumnDisplaySize(int column) throws SQLServerException { } public String getColumnLabel(int column) throws SQLServerException { - checkClosed(); return rs.getColumn(column).getColumnName(); } public String getColumnName(int column) throws SQLServerException { - checkClosed(); return rs.getColumn(column).getColumnName(); } public int getColumnType(int column) throws SQLServerException { - checkClosed(); // under Katmai map the max types to non max to be inline with DBMD. TypeInfo typeInfo = rs.getColumn(column).getTypeInfo(); @@ -166,8 +153,6 @@ public int getColumnType(int column) throws SQLServerException { } public String getColumnTypeName(int column) throws SQLServerException { - checkClosed(); - CryptoMetadata cryptoMetadata = rs.getColumn(column).getCryptoMetadata(); if (null != cryptoMetadata) { return cryptoMetadata.getBaseTypeInfo().getSSTypeName(); @@ -177,8 +162,6 @@ public String getColumnTypeName(int column) throws SQLServerException { } public int getPrecision(int column) throws SQLServerException { - checkClosed(); - CryptoMetadata cryptoMetadata = rs.getColumn(column).getCryptoMetadata(); if (null != cryptoMetadata) { return cryptoMetadata.getBaseTypeInfo().getPrecision(); @@ -188,8 +171,6 @@ public int getPrecision(int column) throws SQLServerException { } public int getScale(int column) throws SQLServerException { - checkClosed(); - CryptoMetadata cryptoMetadata = rs.getColumn(column).getCryptoMetadata(); if (null != cryptoMetadata) { return cryptoMetadata.getBaseTypeInfo().getScale(); @@ -199,18 +180,14 @@ public int getScale(int column) throws SQLServerException { } public String getSchemaName(int column) throws SQLServerException { - checkClosed(); return rs.getColumn(column).getTableName().getSchemaName(); } public String getTableName(int column) throws SQLServerException { - checkClosed(); return rs.getColumn(column).getTableName().getObjectName(); } public boolean isAutoIncrement(int column) throws SQLServerException { - checkClosed(); - CryptoMetadata cryptoMetadata = rs.getColumn(column).getCryptoMetadata(); if (null != cryptoMetadata) { return cryptoMetadata.getBaseTypeInfo().isIdentity(); @@ -220,8 +197,6 @@ public boolean isAutoIncrement(int column) throws SQLServerException { } public boolean isCaseSensitive(int column) throws SQLServerException { - checkClosed(); - CryptoMetadata cryptoMetadata = rs.getColumn(column).getCryptoMetadata(); if (null != cryptoMetadata) { return cryptoMetadata.getBaseTypeInfo().isCaseSensitive(); @@ -231,7 +206,6 @@ public boolean isCaseSensitive(int column) throws SQLServerException { } public boolean isCurrency(int column) throws SQLServerException { - checkClosed(); SSType ssType = rs.getColumn(column).getTypeInfo().getSSType(); CryptoMetadata cryptoMetadata = rs.getColumn(column).getCryptoMetadata(); @@ -243,8 +217,6 @@ public boolean isCurrency(int column) throws SQLServerException { } public boolean isDefinitelyWritable(int column) throws SQLServerException { - checkClosed(); - CryptoMetadata cryptoMetadata = rs.getColumn(column).getCryptoMetadata(); if (null != cryptoMetadata) { return TypeInfo.UPDATABLE_READ_WRITE == cryptoMetadata.getBaseTypeInfo().getUpdatability(); @@ -254,8 +226,6 @@ public boolean isDefinitelyWritable(int column) throws SQLServerException { } public int isNullable(int column) throws SQLServerException { - checkClosed(); - CryptoMetadata cryptoMetadata = rs.getColumn(column).getCryptoMetadata(); if (null != cryptoMetadata) { return cryptoMetadata.getBaseTypeInfo().isNullable() ? columnNullable : columnNoNulls; @@ -265,8 +235,6 @@ public int isNullable(int column) throws SQLServerException { } public boolean isReadOnly(int column) throws SQLServerException { - checkClosed(); - CryptoMetadata cryptoMetadata = rs.getColumn(column).getCryptoMetadata(); if (null != cryptoMetadata) { return TypeInfo.UPDATABLE_READ_ONLY == cryptoMetadata.getBaseTypeInfo().getUpdatability(); @@ -276,8 +244,6 @@ public boolean isReadOnly(int column) throws SQLServerException { } public boolean isSearchable(int column) throws SQLServerException { - checkClosed(); - SSType ssType = null; CryptoMetadata cryptoMetadata = rs.getColumn(column).getCryptoMetadata(); @@ -302,8 +268,6 @@ public boolean isSearchable(int column) throws SQLServerException { } public boolean isSigned(int column) throws SQLServerException { - checkClosed(); - CryptoMetadata cryptoMetadata = rs.getColumn(column).getCryptoMetadata(); if (null != cryptoMetadata) { return cryptoMetadata.getBaseTypeInfo().getSSType().getJDBCType().isSigned(); @@ -322,8 +286,6 @@ public boolean isSigned(int column) throws SQLServerException { * when an error occurs */ public boolean isSparseColumnSet(int column) throws SQLServerException { - checkClosed(); - CryptoMetadata cryptoMetadata = rs.getColumn(column).getCryptoMetadata(); if (null != cryptoMetadata) { return cryptoMetadata.getBaseTypeInfo().isSparseColumnSet(); @@ -333,8 +295,6 @@ public boolean isSparseColumnSet(int column) throws SQLServerException { } public boolean isWritable(int column) throws SQLServerException { - checkClosed(); - int updatability = -1; CryptoMetadata cryptoMetadata = rs.getColumn(column).getCryptoMetadata(); if (null != cryptoMetadata) { @@ -347,8 +307,6 @@ public boolean isWritable(int column) throws SQLServerException { } public String getColumnClassName(int column) throws SQLServerException { - checkClosed(); - CryptoMetadata cryptoMetadata = rs.getColumn(column).getCryptoMetadata(); if (null != cryptoMetadata) { return cryptoMetadata.getBaseTypeInfo().getSSType().getJDBCType().className(); From 6aa46de1dd1bc5e4760a1d4be07ffe987ad43581 Mon Sep 17 00:00:00 2001 From: ulvii Date: Thu, 19 Apr 2018 11:04:48 -0700 Subject: [PATCH 2/3] Fix statement test --- .../jdbc/unit/statement/StatementTest.java | 44 ++++++------------- 1 file changed, 13 insertions(+), 31 deletions(-) diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/StatementTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/StatementTest.java index eb105a3532..bb158a25c5 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/StatementTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/StatementTest.java @@ -1827,8 +1827,8 @@ public void testSparseColumnSetIndex() throws Exception { } /** - * Tests the following for isSparseColumnSet api a) An exception is thrown when result set is closed b) An exception is thrown when statement - * is closed c) An exception is thrown when connection is closed + * Tests the following for isSparseColumnSet api a) Metadata is available when result set is closed b) Metadata is available when statement + * is closed c) Metadata is available when connection is closed * * @throws Exception */ @@ -1859,38 +1859,20 @@ public void testSparseColumnSetForException() throws Exception { rs.next(); SQLServerResultSetMetaData rsmd = (SQLServerResultSetMetaData) rs.getMetaData(); - try { - // test that an exception is thrown when result set is closed - rs.close(); - rsmd.isSparseColumnSet(1); - assertEquals(true, false, "Should not reach here. An exception should have been thrown"); - } - catch (SQLException e) { - } + rs.close(); + rsmd.isSparseColumnSet(1); - // test that an exception is thrown when statement is closed - try { - rs = stmt.executeQuery(selectQuery); - rsmd = (SQLServerResultSetMetaData) rs.getMetaData(); + rs = stmt.executeQuery(selectQuery); + rsmd = (SQLServerResultSetMetaData) rs.getMetaData(); - assertEquals(stmt.isClosed(), true, "testSparseColumnSetForException: statement should be closed since resultset is closed."); - stmt.close(); - rsmd.isSparseColumnSet(1); - assertEquals(true, false, "Should not reach here. An exception should have been thrown"); - } - catch (SQLException e) { - } + assertEquals(stmt.isClosed(), true, "testSparseColumnSetForException: statement should be closed since resultset is closed."); + stmt.close(); + rsmd.isSparseColumnSet(1); - // test that an exception is thrown when connection is closed - try { - rs = con.createStatement().executeQuery("SELECT * FROM " + tableName); - rsmd = (SQLServerResultSetMetaData) rs.getMetaData(); - con.close(); - rsmd.isSparseColumnSet(1); - assertEquals(true, false, "Should not reach here. An exception should have been thrown"); - } - catch (SQLException e) { - } + rs = con.createStatement().executeQuery("SELECT * FROM " + tableName); + rsmd = (SQLServerResultSetMetaData) rs.getMetaData(); + con.close(); + rsmd.isSparseColumnSet(1); } From 335b2120f86b8a4f319a88d44afbb76550b79b98 Mon Sep 17 00:00:00 2001 From: ulvii Date: Thu, 19 Apr 2018 14:50:23 -0700 Subject: [PATCH 3/3] =?UTF-8?q?Remove=20=C2=96closeOnCompletion=20from=20S?= =?UTF-8?q?tatementTest?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jdbc/unit/statement/StatementTest.java | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/StatementTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/StatementTest.java index bb158a25c5..8d4f9a6f19 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/StatementTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/StatementTest.java @@ -1844,28 +1844,15 @@ public void testSparseColumnSetForException() throws Exception { con = createConnectionAndPopulateData(); Statement stmt = con.createStatement(); - // enable isCloseOnCompletion - try { - stmt.closeOnCompletion(); - } - catch (Exception e) { - - throw new SQLException("testSparseColumnSetForException threw exception: ", e); - - } - String selectQuery = "SELECT * FROM " + tableName; ResultSet rs = stmt.executeQuery(selectQuery); rs.next(); - SQLServerResultSetMetaData rsmd = (SQLServerResultSetMetaData) rs.getMetaData(); rs.close(); rsmd.isSparseColumnSet(1); rs = stmt.executeQuery(selectQuery); rsmd = (SQLServerResultSetMetaData) rs.getMetaData(); - - assertEquals(stmt.isClosed(), true, "testSparseColumnSetForException: statement should be closed since resultset is closed."); stmt.close(); rsmd.isSparseColumnSet(1);