mirror of
https://github.com/apache/lucene.git
synced 2025-02-22 10:15:27 +00:00
SOLR-8502: Implement DatabaseMetaDataImpl.getURL()
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1724867 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
2a1d20b57a
commit
ede76cfe13
@ -41,18 +41,24 @@ import org.apache.solr.client.solrj.io.SolrClientCache;
|
|||||||
|
|
||||||
class ConnectionImpl implements Connection {
|
class ConnectionImpl implements Connection {
|
||||||
|
|
||||||
|
private final String url;
|
||||||
private SolrClientCache sqlSolrClientCache = new SolrClientCache();
|
private SolrClientCache sqlSolrClientCache = new SolrClientCache();
|
||||||
private CloudSolrClient client;
|
private CloudSolrClient client;
|
||||||
private String collection;
|
private String collection;
|
||||||
Properties props;
|
Properties props;
|
||||||
private boolean closed;
|
private boolean closed;
|
||||||
|
|
||||||
ConnectionImpl(String zkHost, String collection, Properties props) {
|
ConnectionImpl(String url, String zkHost, String collection, Properties props) {
|
||||||
|
this.url = url;
|
||||||
this.client = sqlSolrClientCache.getCloudSolrClient(zkHost);
|
this.client = sqlSolrClientCache.getCloudSolrClient(zkHost);
|
||||||
this.collection = collection;
|
this.collection = collection;
|
||||||
this.props = props;
|
this.props = props;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String getUrl() {
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Statement createStatement() throws SQLException {
|
public Statement createStatement() throws SQLException {
|
||||||
return new StatementImpl(client, this.collection, props, sqlSolrClientCache);
|
return new StatementImpl(client, this.collection, props, sqlSolrClientCache);
|
||||||
|
@ -42,7 +42,7 @@ class DatabaseMetaDataImpl implements DatabaseMetaData {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getURL() throws SQLException {
|
public String getURL() throws SQLException {
|
||||||
return null;
|
return this.connection.getUrl();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -69,7 +69,7 @@ public class DriverImpl implements Driver {
|
|||||||
|
|
||||||
String zkHost = uri.getAuthority() + uri.getPath();
|
String zkHost = uri.getAuthority() + uri.getPath();
|
||||||
|
|
||||||
return new ConnectionImpl(zkHost, collection, props);
|
return new ConnectionImpl(url, zkHost, collection, props);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Connection connect(String url) throws SQLException {
|
public Connection connect(String url) throws SQLException {
|
||||||
|
@ -19,6 +19,7 @@ package org.apache.solr.client.solrj.io.sql;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
|
import java.sql.DatabaseMetaData;
|
||||||
import java.sql.DriverManager;
|
import java.sql.DriverManager;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.Statement;
|
import java.sql.Statement;
|
||||||
@ -299,5 +300,22 @@ public class JdbcTest extends AbstractFullDistribZkTestBase {
|
|||||||
|
|
||||||
stmt.close();
|
stmt.close();
|
||||||
con.close();
|
con.close();
|
||||||
|
|
||||||
|
testDriverMetadata();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void testDriverMetadata() throws Exception {
|
||||||
|
String collection = DEFAULT_COLLECTION;
|
||||||
|
String connectionString = "jdbc:solr://" + zkServer.getZkAddress() + "?collection=" + collection +
|
||||||
|
"&username=&password=&testKey1=testValue&testKey2";
|
||||||
|
|
||||||
|
try (Connection con = DriverManager.getConnection(connectionString)) {
|
||||||
|
assertEquals(collection, con.getCatalog());
|
||||||
|
|
||||||
|
DatabaseMetaData databaseMetaData = con.getMetaData();
|
||||||
|
assertNotNull(databaseMetaData);
|
||||||
|
|
||||||
|
assertEquals(connectionString, databaseMetaData.getURL());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user