Skip to content

Commit

Permalink
Make ResultSetMetaData accessible when ResultSet is closed (#685)
Browse files Browse the repository at this point in the history
* Removing checkClosed() from SQLServerResultSetMetaData. Result set metadata should be accesible after result set is closed

* Fix statement test

* Remove �closeOnCompletion from StatementTest
  • Loading branch information
ulvii authored Apr 30, 2018
1 parent b3afe25 commit 6ea661a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -78,20 +74,14 @@ public <T> T unwrap(Class<T> 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();
Expand All @@ -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();

Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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;
Expand All @@ -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();
Expand All @@ -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();

Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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) {
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -1844,53 +1844,22 @@ 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();
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) {
}

// test that an exception is thrown when statement is closed
try {
rs = stmt.executeQuery(selectQuery);
rsmd = (SQLServerResultSetMetaData) rs.getMetaData();
rs.close();
rsmd.isSparseColumnSet(1);

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) {
}
rs = stmt.executeQuery(selectQuery);
rsmd = (SQLServerResultSetMetaData) rs.getMetaData();
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);

}

Expand Down

0 comments on commit 6ea661a

Please sign in to comment.