mirror of https://github.com/apache/lucene.git
Fix JdbcTest for database metadata
This commit is contained in:
parent
e9ff7264ed
commit
201527a611
|
@ -705,17 +705,29 @@ class DatabaseMetaDataImpl implements DatabaseMetaData {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResultSet getTables(String catalog, String schemaPattern, String tableNamePattern, String[] types) throws SQLException {
|
public ResultSet getTables(String catalog, String schemaPattern, String tableNamePattern, String[] types) throws SQLException {
|
||||||
return this.connectionStatement.executeQuery("select TABLE_CAT, TABLE_SCHEM, TABLE_NAME, TABLE_TYPE, REMARKS from _TABLES_");
|
String tableCatCheck = "";
|
||||||
|
if(catalog != null) {
|
||||||
|
tableCatCheck = "tableCat = '\" + catalog + \"' and";
|
||||||
|
}
|
||||||
|
if(schemaPattern == null) {
|
||||||
|
schemaPattern = "%";
|
||||||
|
}
|
||||||
|
if(tableNamePattern == null) {
|
||||||
|
tableNamePattern = "%";
|
||||||
|
}
|
||||||
|
return this.connectionStatement.executeQuery("select tableCat, tableSchem, tableName, tableType, remarks from " +
|
||||||
|
"metadata.TABLES where " + tableCatCheck + " tableSchem like '" + schemaPattern + "' and tableName like '" +
|
||||||
|
tableNamePattern + "'");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResultSet getSchemas() throws SQLException {
|
public ResultSet getSchemas() throws SQLException {
|
||||||
return this.connectionStatement.executeQuery("select TABLE_SCHEM, TABLE_CATALOG from _SCHEMAS_");
|
return this.connectionStatement.executeQuery("select distinct tableSchem, tableCat from metadata.TABLES");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResultSet getCatalogs() throws SQLException {
|
public ResultSet getCatalogs() throws SQLException {
|
||||||
return this.connectionStatement.executeQuery("select TABLE_CAT from _CATALOGS_");
|
return this.connectionStatement.executeQuery("select distinct tableCat from metadata.TABLES");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -25,6 +25,9 @@ import java.sql.ResultSet;
|
||||||
import java.sql.ResultSetMetaData;
|
import java.sql.ResultSetMetaData;
|
||||||
import java.sql.Statement;
|
import java.sql.Statement;
|
||||||
import java.sql.Types;
|
import java.sql.Types;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import org.apache.lucene.util.LuceneTestCase;
|
import org.apache.lucene.util.LuceneTestCase;
|
||||||
|
@ -466,11 +469,19 @@ public class JdbcTest extends AbstractFullDistribZkTestBase {
|
||||||
// assertEquals(0, databaseMetaData.getDriverMajorVersion());
|
// assertEquals(0, databaseMetaData.getDriverMajorVersion());
|
||||||
// assertEquals(0, databaseMetaData.getDriverMinorVersion());
|
// assertEquals(0, databaseMetaData.getDriverMinorVersion());
|
||||||
|
|
||||||
// TODO fix getCatalogs, getSchemas, and getTables
|
try(ResultSet rs = databaseMetaData.getSchemas()) {
|
||||||
/*
|
assertTrue(rs.next());
|
||||||
|
assertEquals(zkServer.getZkAddress(), rs.getString("tableSchem"));
|
||||||
|
assertNull(rs.getString("tableCat"));
|
||||||
|
assertTrue(rs.next());
|
||||||
|
assertEquals("metadata", rs.getString("tableSchem"));
|
||||||
|
assertNull(rs.getString("tableCat"));
|
||||||
|
assertFalse(rs.next());
|
||||||
|
}
|
||||||
|
|
||||||
try(ResultSet rs = databaseMetaData.getCatalogs()) {
|
try(ResultSet rs = databaseMetaData.getCatalogs()) {
|
||||||
assertTrue(rs.next());
|
assertTrue(rs.next());
|
||||||
assertEquals(zkServer.getZkAddress(), rs.getString("TABLE_CAT"));
|
assertNull(rs.getString("tableCat"));
|
||||||
assertFalse(rs.next());
|
assertFalse(rs.next());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -478,22 +489,17 @@ public class JdbcTest extends AbstractFullDistribZkTestBase {
|
||||||
collections.addAll(cloudClient.getZkStateReader().getClusterState().getCollections());
|
collections.addAll(cloudClient.getZkStateReader().getClusterState().getCollections());
|
||||||
Collections.sort(collections);
|
Collections.sort(collections);
|
||||||
|
|
||||||
try(ResultSet rs = databaseMetaData.getSchemas()) {
|
try(ResultSet rs = databaseMetaData.getTables(null, zkServer.getZkAddress(), "%", null)) {
|
||||||
assertFalse(rs.next());
|
|
||||||
}
|
|
||||||
|
|
||||||
try(ResultSet rs = databaseMetaData.getTables(zkServer.getZkAddress(), null, "%", null)) {
|
|
||||||
for(String acollection : collections) {
|
for(String acollection : collections) {
|
||||||
assertTrue(rs.next());
|
assertTrue(rs.next());
|
||||||
assertEquals(zkServer.getZkAddress(), rs.getString("TABLE_CAT"));
|
assertNull(rs.getString("tableCat"));
|
||||||
assertNull(rs.getString("TABLE_SCHEM"));
|
assertEquals(zkServer.getZkAddress(), rs.getString("tableSchem"));
|
||||||
assertEquals(acollection, rs.getString("TABLE_NAME"));
|
assertEquals(acollection, rs.getString("tableName"));
|
||||||
assertEquals("TABLE", rs.getString("TABLE_TYPE"));
|
assertEquals("TABLE", rs.getString("tableType"));
|
||||||
assertNull(rs.getString("REMARKS"));
|
assertNull(rs.getString("remarks"));
|
||||||
}
|
}
|
||||||
assertFalse(rs.next());
|
assertFalse(rs.next());
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
assertTrue(con.isReadOnly());
|
assertTrue(con.isReadOnly());
|
||||||
con.setReadOnly(true);
|
con.setReadOnly(true);
|
||||||
|
|
Loading…
Reference in New Issue