change
This commit is contained in:
parent
904116ef64
commit
6f5ed79457
|
@ -290,7 +290,21 @@ public abstract class AbstractConnection extends WrapperImpl implements Connecti
|
|||
}
|
||||
|
||||
@Override
|
||||
public abstract boolean isValid(int timeout) throws SQLException;
|
||||
public boolean isValid(int timeout) throws SQLException {
|
||||
if (isClosed())
|
||||
return false;
|
||||
if (timeout < 0)
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_VARIABLE);
|
||||
|
||||
int status;
|
||||
try (Statement stmt = createStatement()) {
|
||||
ResultSet resultSet = stmt.executeQuery("select server_status()");
|
||||
resultSet.next();
|
||||
status = resultSet.getInt("server_status()");
|
||||
resultSet.close();
|
||||
}
|
||||
return status == 1 ? true : false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setClientInfo(String name, String value) throws SQLClientInfoException {
|
||||
|
|
|
@ -142,8 +142,9 @@ public class TSDBConnection extends AbstractConnection {
|
|||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
||||
}
|
||||
|
||||
public boolean isValid(int timeout) throws SQLException {
|
||||
return !this.isClosed();
|
||||
}
|
||||
// @Override
|
||||
// public boolean isValid(int timeout) throws SQLException {
|
||||
// return !this.isClosed();
|
||||
// }
|
||||
|
||||
}
|
||||
|
|
|
@ -357,9 +357,8 @@ public class RestfulConnection implements Connection {
|
|||
public boolean isValid(int timeout) throws SQLException {
|
||||
if (timeout < 0)
|
||||
throw new SQLException(TSDBConstants.INVALID_VARIABLES);
|
||||
// TODO:
|
||||
/* The driver shall submit a query on the connection or use some other mechanism that positively verifies
|
||||
the connection is still valid when this method is called.*/
|
||||
// TODO: The driver shall submit a query on the connection or use some other mechanism
|
||||
// that positively verifies the connection is still valid when this method is called.
|
||||
return !isClosed();
|
||||
}
|
||||
|
||||
|
|
|
@ -187,12 +187,15 @@ public class TSDBConnectionTest {
|
|||
public void createNClob() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createSQLXML() {
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void createSQLXML() throws SQLException {
|
||||
conn.createSQLXML();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isValid() {
|
||||
public void isValid() throws SQLException {
|
||||
Assert.assertTrue(conn.isValid(1000));
|
||||
conn.isValid(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue