use of io.mycat.config.NormalBackEndTableInfoConfig in project Mycat2 by MyCATApache.
the class PrototypeService method getDefaultNormalTable.
public Map<String, NormalTableConfig> getDefaultNormalTable(String targetName, String schemaName, Predicate<String> tableFilter) {
Set<String> tables = new HashSet<>();
Optional<JdbcConnectionManager> jdbcConnectionManagerOptional = getPrototypeConnectionManager();
if (!jdbcConnectionManagerOptional.isPresent()) {
return Collections.emptyMap();
}
JdbcConnectionManager jdbcConnectionManager = jdbcConnectionManagerOptional.get();
try (DefaultConnection connection = jdbcConnectionManager.getConnection(targetName)) {
RowBaseIterator tableIterator = connection.executeQuery("show tables from " + schemaName);
while (tableIterator.next()) {
tables.add(tableIterator.getString(0));
}
} catch (Exception e) {
LOGGER.error("", e);
return Collections.emptyMap();
}
Map<String, NormalTableConfig> res = new ConcurrentHashMap<>();
tables.stream().filter(tableFilter).parallel().forEach(tableName -> {
NormalBackEndTableInfoConfig normalBackEndTableInfoConfig = new NormalBackEndTableInfoConfig(targetName, schemaName, tableName);
try {
String createTableSQLByJDBC = getCreateTableSQLByJDBC(schemaName, tableName, Collections.singletonList(new BackendTableInfo(targetName, schemaName, tableName))).orElse(null);
if (createTableSQLByJDBC != null) {
res.put(tableName, new NormalTableConfig(createTableSQLByJDBC, normalBackEndTableInfoConfig));
} else {
// exception
}
} catch (Throwable e) {
LOGGER.warn("", e);
}
});
return res;
}
Aggregations