Skip to content

Commit

Permalink
SOLR-14153: Return correct isolation level when retrieving it from th…
Browse files Browse the repository at this point in the history
…e SQL Connection

As transactions are not supported a request to getTransactionIsolation() should return TRANSACTION_NONE (https://docs.oracle.com/javase/8/docs/api/java/sql/Connection.html#TRANSACTION_NONE)

Signed-off-by: Kevin Risden <[email protected]>
  • Loading branch information
nvercamm authored and risdenk committed Jan 3, 2020
1 parent 50176fd commit 1e0471a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
2 changes: 2 additions & 0 deletions solr/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ Improvements
hl.fragsizeIsMinimum, with defaults that aim to better center matches in fragments than previously. See the ref guide.
Regardless of the settings, the passages may be sized differently than before. (Nándor Mátravölgyi, David Smiley)

* SOLR-14154: Return correct isolation level when retrieving it from the SQL Connection (Nick Vercammen, Kevin Risden)

Optimizations
---------------------
(No changes)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,30 @@ public String getCatalog() throws SQLException {

@Override
public void setTransactionIsolation(int level) throws SQLException {
throw new UnsupportedOperationException();
if(isClosed()) {
throw new SQLException("Connection is closed.");
}
if(Connection.TRANSACTION_NONE == level) {
throw new SQLException("Connection.TRANSACTION_NONE cannot be used.");
}
if(
Connection.TRANSACTION_READ_COMMITTED == level ||
Connection.TRANSACTION_READ_UNCOMMITTED == level ||
Connection.TRANSACTION_REPEATABLE_READ == level ||
Connection.TRANSACTION_SERIALIZABLE == level
) {
throw new SQLException(new UnsupportedOperationException());
} else {
throw new SQLException("Unsupported transaction type specified.");
}
}

@Override
public int getTransactionIsolation() throws SQLException {
throw new UnsupportedOperationException();
if(isClosed()) {
throw new SQLException("Connection is closed.");
}
return Connection.TRANSACTION_NONE;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,6 @@ private void testJDBCMethods(String collection, String connectionString, Propert
// assertEquals(0, databaseMetaData.getDriverMajorVersion());
// assertEquals(0, databaseMetaData.getDriverMinorVersion());


List<String> tableSchemas = new ArrayList<>(Arrays.asList(zkHost, "metadata"));
try(ResultSet rs = databaseMetaData.getSchemas()) {
assertTrue(rs.next());
Expand All @@ -551,10 +550,8 @@ private void testJDBCMethods(String collection, String connectionString, Propert
solrClient.connect();
ZkStateReader zkStateReader = solrClient.getZkStateReader();

SortedSet<String> tables = new TreeSet<>();

Set<String> collectionsSet = zkStateReader.getClusterState().getCollectionsMap().keySet();
tables.addAll(collectionsSet);
SortedSet<String> tables = new TreeSet<>(collectionsSet);

Aliases aliases = zkStateReader.getAliases();
tables.addAll(aliases.getCollectionAliasListMap().keySet());
Expand All @@ -571,6 +568,15 @@ private void testJDBCMethods(String collection, String connectionString, Propert
assertFalse(rs.next());
}

assertEquals(Connection.TRANSACTION_NONE, con.getTransactionIsolation());
try {
con.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
fail("should not have been able to set transaction isolation");
} catch (SQLException e) {
assertEquals(UnsupportedOperationException.class, e.getCause().getClass());
}
assertEquals(Connection.TRANSACTION_NONE, con.getTransactionIsolation());

assertTrue(con.isReadOnly());
con.setReadOnly(true);
assertTrue(con.isReadOnly());
Expand All @@ -579,7 +585,6 @@ private void testJDBCMethods(String collection, String connectionString, Propert
con.clearWarnings();
assertNull(con.getWarnings());


try (Statement statement = con.createStatement()) {
checkStatement(con, statement);

Expand Down

0 comments on commit 1e0471a

Please sign in to comment.