Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,30 @@ public List<DBDatabase> listDatabases() {
public List<DBObjectIdentity> listTables(String schemaName, String tableNameLike) {
List<DBObjectIdentity> results = super.listTables(schemaName, tableNameLike);

String querySystemTable = "show full tables from oceanbase where Table_type='BASE TABLE'";
try {
List<String> tables = jdbcOperations.query(querySystemTable, (rs, rowNum) -> rs.getString(1));
tables.forEach(name -> results.add(DBObjectIdentity.of("oceanbase", DBObjectType.TABLE, name)));
} catch (Exception e) {
log.warn("List system tables from 'oceanbase' failed, reason={}", e.getMessage());
if (StringUtils.isBlank(schemaName) || "oceanbase".equals(schemaName)) {
MySQLSqlBuilder querySystemTable = new MySQLSqlBuilder();
querySystemTable.append("show full tables from oceanbase where Table_type='BASE TABLE'");
if (StringUtils.isNotBlank(tableNameLike)) {
querySystemTable.append(" and tables_in_oceanbase like ").value("%" + tableNameLike + "%");
}
try {
List<String> tables =
jdbcOperations.query(querySystemTable.toString(), (rs, rowNum) -> rs.getString(1));
tables.forEach(name -> results.add(DBObjectIdentity.of("oceanbase", DBObjectType.TABLE, name)));
} catch (Exception e) {
log.warn("List system tables from 'oceanbase' failed, reason={}", e.getMessage());
}
}

if (StringUtils.isBlank(schemaName) || "mysql".equals(schemaName)) {
MySQLSqlBuilder queryMysqlTable = new MySQLSqlBuilder();
queryMysqlTable.append("show full tables from `mysql` where Table_type='BASE TABLE'");
if (StringUtils.isNotBlank(tableNameLike)) {
queryMysqlTable.append(" and tables_in_mysql like ").value("%" + tableNameLike + "%");
}
jdbcOperations.query(queryMysqlTable.toString(),
(rs, num) -> results.add(DBObjectIdentity.of("mysql", DBObjectType.TABLE, rs.getString(1))));
}
String queryMysqlTable = "show full tables from `mysql`";
jdbcOperations.query(queryMysqlTable,
(rs, num) -> results.add(DBObjectIdentity.of("mysql", DBObjectType.TABLE, rs.getString(1))));
return results;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,23 @@ public void listTableOptions_Success() {
}

@Test
public void showTablelike_Success() {
public void listTables_Success() {
List<DBObjectIdentity> tables = accessor.listTables(getOBMySQLDataBaseName(), null);
Assert.assertTrue(tables != null && tables.size() > 0);
}

@Test
public void listTables_inOceanbaseSchema_Success() {
List<DBObjectIdentity> tables = accessor.listTables("oceanbase", "job");
Assert.assertTrue(tables != null && tables.size() > 0);
}

@Test
public void listTables_inMySQLSchema_Success() {
List<DBObjectIdentity> tables = accessor.listTables("mysql", "time");
Assert.assertTrue(tables != null && tables.size() > 0);
}

@Test
public void showViews_Success() {
List<DBObjectIdentity> views = accessor.listViews(getOBMySQLDataBaseName());
Expand Down