diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 306df7e4fc3..e5ddbb3fe39 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -109,6 +109,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) diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/io/sql/ConnectionImpl.java b/solr/solrj/src/java/org/apache/solr/client/solrj/io/sql/ConnectionImpl.java index f7feafc62ca..8e0466d203a 100644 --- a/solr/solrj/src/java/org/apache/solr/client/solrj/io/sql/ConnectionImpl.java +++ b/solr/solrj/src/java/org/apache/solr/client/solrj/io/sql/ConnectionImpl.java @@ -181,12 +181,30 @@ class ConnectionImpl implements Connection { @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 diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/io/sql/JdbcTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/io/sql/JdbcTest.java index 59bd182cc40..c3b41e8cc21 100644 --- a/solr/solrj/src/test/org/apache/solr/client/solrj/io/sql/JdbcTest.java +++ b/solr/solrj/src/test/org/apache/solr/client/solrj/io/sql/JdbcTest.java @@ -526,7 +526,6 @@ public class JdbcTest extends SolrCloudTestCase { // assertEquals(0, databaseMetaData.getDriverMajorVersion()); // assertEquals(0, databaseMetaData.getDriverMinorVersion()); - List tableSchemas = new ArrayList<>(Arrays.asList(zkHost, "metadata")); try(ResultSet rs = databaseMetaData.getSchemas()) { assertTrue(rs.next()); @@ -551,10 +550,8 @@ public class JdbcTest extends SolrCloudTestCase { solrClient.connect(); ZkStateReader zkStateReader = solrClient.getZkStateReader(); - SortedSet tables = new TreeSet<>(); - Set collectionsSet = zkStateReader.getClusterState().getCollectionsMap().keySet(); - tables.addAll(collectionsSet); + SortedSet tables = new TreeSet<>(collectionsSet); Aliases aliases = zkStateReader.getAliases(); tables.addAll(aliases.getCollectionAliasListMap().keySet()); @@ -571,6 +568,15 @@ public class JdbcTest extends SolrCloudTestCase { 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()); @@ -579,7 +585,6 @@ public class JdbcTest extends SolrCloudTestCase { con.clearWarnings(); assertNull(con.getWarnings()); - try (Statement statement = con.createStatement()) { checkStatement(con, statement);