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:
Joel Bernstein 2016-01-15 18:30:11 +00:00
parent 2a1d20b57a
commit ede76cfe13
4 changed files with 27 additions and 3 deletions

View File

@ -41,18 +41,24 @@ import org.apache.solr.client.solrj.io.SolrClientCache;
class ConnectionImpl implements Connection {
private final String url;
private SolrClientCache sqlSolrClientCache = new SolrClientCache();
private CloudSolrClient client;
private String collection;
Properties props;
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.collection = collection;
this.props = props;
}
String getUrl() {
return url;
}
@Override
public Statement createStatement() throws SQLException {
return new StatementImpl(client, this.collection, props, sqlSolrClientCache);

View File

@ -42,7 +42,7 @@ class DatabaseMetaDataImpl implements DatabaseMetaData {
@Override
public String getURL() throws SQLException {
return null;
return this.connection.getUrl();
}
@Override

View File

@ -69,7 +69,7 @@ public class DriverImpl implements Driver {
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 {

View File

@ -19,6 +19,7 @@ package org.apache.solr.client.solrj.io.sql;
import java.io.File;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
@ -299,5 +300,22 @@ public class JdbcTest extends AbstractFullDistribZkTestBase {
stmt.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());
}
}
}