use of com.alibaba.otter.shared.common.utils.meta.DdlTableNameFilter in project otter by alibaba.
the class DataSourceChecker method checkNamespaceTables.
public String checkNamespaceTables(final String namespace, final String name, final Long dataSourceId) {
DataSource dataSource = null;
try {
DataMediaSource source = dataMediaSourceService.findById(dataSourceId);
DbMediaSource dbMediaSource = (DbMediaSource) source;
dataSource = dataSourceCreator.createDataSource(dbMediaSource);
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
List<String> schemaList;
{
ModeValue mode = ConfigHelper.parseMode(namespace);
String schemaPattern = ConfigHelper.makeSQLPattern(mode, namespace);
final ModeValueFilter modeValueFilter = ConfigHelper.makeModeValueFilter(mode, namespace);
if (source.getType().isOracle()) {
schemaList = Arrays.asList(namespace);
} else {
schemaList = DdlUtils.findSchemas(jdbcTemplate, schemaPattern, new DdlSchemaFilter() {
@Override
public boolean accept(String schemaName) {
return modeValueFilter.accept(schemaName);
}
});
}
}
final List<String> matchSchemaTables = new ArrayList<String>();
matchSchemaTables.add("Find schema and tables:");
if (schemaList != null) {
ModeValue mode = ConfigHelper.parseMode(name);
String tableNamePattern = ConfigHelper.makeSQLPattern(mode, name);
final ModeValueFilter modeValueFilter = ConfigHelper.makeModeValueFilter(mode, name);
for (String schema : schemaList) {
DdlUtils.findTables(jdbcTemplate, schema, schema, tableNamePattern, null, new DdlTableNameFilter() {
@Override
public boolean accept(String catalogName, String schemaName, String tableName) {
if (modeValueFilter.accept(tableName)) {
matchSchemaTables.add(schemaName + "." + tableName);
}
return false;
}
});
}
}
if (matchSchemaTables.size() == 1) {
return TABLE_FAIL;
}
return StringUtils.join(matchSchemaTables, "<br>\n");
} catch (Exception e) {
logger.error("check error!", e);
return TABLE_FAIL;
} finally {
dataSourceCreator.destroyDataSource(dataSource);
}
}
Aggregations