mirror of https://github.com/apache/lucene.git
SOLR-8574: Implement ConnectionImpl.isValid() and DatabaseMetaDataImpl.getConnection()
This commit is contained in:
parent
eb6bf9bc54
commit
eeaf3eb96f
|
@ -35,6 +35,8 @@ import java.sql.Struct;
|
|||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import org.apache.solr.client.solrj.impl.CloudSolrClient;
|
||||
import org.apache.solr.client.solrj.io.SolrClientCache;
|
||||
|
@ -290,7 +292,16 @@ class ConnectionImpl implements Connection {
|
|||
|
||||
@Override
|
||||
public boolean isValid(int timeout) throws SQLException {
|
||||
throw new UnsupportedOperationException();
|
||||
// check that the connection isn't close and able to connect within the timeout
|
||||
try {
|
||||
if(!isClosed()) {
|
||||
this.client.connect(timeout, TimeUnit.SECONDS);
|
||||
return true;
|
||||
}
|
||||
} catch (InterruptedException|TimeoutException ignore) {
|
||||
// Ignore error since connection is not valid
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -772,7 +772,7 @@ class DatabaseMetaDataImpl implements DatabaseMetaData {
|
|||
|
||||
@Override
|
||||
public Connection getConnection() throws SQLException {
|
||||
return null;
|
||||
return this.connection;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -360,11 +360,13 @@ public class JdbcTest extends AbstractFullDistribZkTestBase {
|
|||
String sql = "select id, a_i, a_s, a_f as my_float_col from " + collection + " order by a_i desc limit 2";
|
||||
|
||||
try (Connection con = DriverManager.getConnection(connectionString)) {
|
||||
assertTrue(con.isValid(DEFAULT_CONNECTION_TIMEOUT));
|
||||
assertEquals(collection, con.getCatalog());
|
||||
|
||||
DatabaseMetaData databaseMetaData = con.getMetaData();
|
||||
assertNotNull(databaseMetaData);
|
||||
|
||||
assertEquals(con, databaseMetaData.getConnection());
|
||||
assertEquals(connectionString, databaseMetaData.getURL());
|
||||
|
||||
assertNull(con.getWarnings());
|
||||
|
|
Loading…
Reference in New Issue