diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index b6ef5955eb3..e6131c00c8c 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -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) 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 @@ 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 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 @@ private void testJDBCMethods(String collection, String connectionString, Propert // 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 @@ private void testJDBCMethods(String collection, String connectionString, Propert 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 @@ 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()); @@ -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);