From a652065c2669e23635828481bfcad4aab6ced4fd Mon Sep 17 00:00:00 2001 From: jbernste Date: Sat, 23 Jan 2016 22:44:18 -0500 Subject: [PATCH] SOLR-8573: Implement ConnectionImpl,StatementImpl,ResultSetImpl clearWarnings and getWarnings --- .../solr/client/solrj/io/sql/ConnectionImpl.java | 13 +++++++++++-- .../solr/client/solrj/io/sql/ResultSetImpl.java | 13 +++++++++++-- .../solr/client/solrj/io/sql/StatementImpl.java | 13 +++++++++++-- .../apache/solr/client/solrj/io/sql/JdbcTest.java | 12 ++++++++++++ 4 files changed, 45 insertions(+), 6 deletions(-) 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 38977056481..41fbdffed7e 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 @@ -47,6 +47,7 @@ class ConnectionImpl implements Connection { private final String collection; private final Properties properties; private boolean closed; + private SQLWarning currentWarning; ConnectionImpl(String url, String zkHost, String collection, Properties properties) { this.url = url; @@ -166,12 +167,20 @@ class ConnectionImpl implements Connection { @Override public SQLWarning getWarnings() throws SQLException { - throw new UnsupportedOperationException(); + if(isClosed()) { + throw new SQLException("Statement is closed."); + } + + return this.currentWarning; } @Override public void clearWarnings() throws SQLException { - throw new UnsupportedOperationException(); + if(isClosed()) { + throw new SQLException("Statement is closed."); + } + + this.currentWarning = null; } @Override diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/io/sql/ResultSetImpl.java b/solr/solrj/src/java/org/apache/solr/client/solrj/io/sql/ResultSetImpl.java index 114a659fe57..1f55eed5bbc 100644 --- a/solr/solrj/src/java/org/apache/solr/client/solrj/io/sql/ResultSetImpl.java +++ b/solr/solrj/src/java/org/apache/solr/client/solrj/io/sql/ResultSetImpl.java @@ -48,6 +48,7 @@ class ResultSetImpl implements ResultSet { private Tuple tuple; private boolean done; private boolean closed; + private SQLWarning currentWarning; ResultSetImpl(StatementImpl statement) { this.statement = statement; @@ -255,12 +256,20 @@ class ResultSetImpl implements ResultSet { @Override public SQLWarning getWarnings() throws SQLException { - throw new UnsupportedOperationException(); + if(isClosed()) { + throw new SQLException("Statement is closed."); + } + + return this.currentWarning; } @Override public void clearWarnings() throws SQLException { - throw new UnsupportedOperationException(); + if(isClosed()) { + throw new SQLException("Statement is closed."); + } + + this.currentWarning = null; } @Override diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/io/sql/StatementImpl.java b/solr/solrj/src/java/org/apache/solr/client/solrj/io/sql/StatementImpl.java index 762f74c65b6..bea6488efcb 100644 --- a/solr/solrj/src/java/org/apache/solr/client/solrj/io/sql/StatementImpl.java +++ b/solr/solrj/src/java/org/apache/solr/client/solrj/io/sql/StatementImpl.java @@ -47,6 +47,7 @@ class StatementImpl implements Statement { private boolean closed; private String currentSQL; private ResultSetImpl currentResultSet; + private SQLWarning currentWarning; StatementImpl(ConnectionImpl connection) { this.connection = connection; @@ -178,12 +179,20 @@ class StatementImpl implements Statement { @Override public SQLWarning getWarnings() throws SQLException { - throw new UnsupportedOperationException(); + if(isClosed()) { + throw new SQLException("Statement is closed."); + } + + return this.currentWarning; } @Override public void clearWarnings() throws SQLException { - throw new UnsupportedOperationException(); + if(isClosed()) { + throw new SQLException("Statement is closed."); + } + + this.currentWarning = null; } @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 7e76ce0be4d..b1ce84f381a 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 @@ -320,9 +320,17 @@ public class JdbcTest extends AbstractFullDistribZkTestBase { assertEquals(connectionString, databaseMetaData.getURL()); + assertNull(con.getWarnings()); + con.clearWarnings(); + assertNull(con.getWarnings()); + try (Statement statement = con.createStatement()) { assertEquals(con, statement.getConnection()); + assertNull(statement.getWarnings()); + statement.clearWarnings(); + assertNull(statement.getWarnings()); + try (ResultSet rs = statement.executeQuery(sql)) { assertEquals(statement, rs.getStatement()); @@ -350,6 +358,10 @@ public class JdbcTest extends AbstractFullDistribZkTestBase { } private void checkResultSet(ResultSet rs) throws Exception { + assertNull(rs.getWarnings()); + rs.clearWarnings(); + assertNull(rs.getWarnings()); + assertTrue(rs.next()); assertEquals(14, rs.getLong("a_i")); assertEquals("hello0", rs.getString("a_s"));