提交 6f5ed794 编写于 作者: Z zyyang

change

上级 904116ef
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册