SOLR-8573: Implement ConnectionImpl,StatementImpl,ResultSetImpl clearWarnings and getWarnings

This commit is contained in:
jbernste 2016-01-23 22:44:18 -05:00 committed by Dawid Weiss
parent b18d2b3330
commit a652065c26
4 changed files with 45 additions and 6 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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"));