use of io.mycat.config.NormalTableConfig in project Mycat2 by MyCATApache.
the class PerformanceSchema method main.
@SneakyThrows
public static void main(String[] args) {
Map<String, Map<String, NormalTableConfig>> normalTablesSet = Collections.emptyMap();
HashMap<String, HashMap<String, String>> map = new HashMap<>();
for (Map.Entry<String, Map<String, NormalTableConfig>> stringMapEntry : normalTablesSet.entrySet()) {
String key = stringMapEntry.getKey();
Map<String, NormalTableConfig> value = stringMapEntry.getValue();
for (Map.Entry<String, NormalTableConfig> entry : stringMapEntry.getValue().entrySet()) {
NormalTableConfig normalTableConfig = entry.getValue();
String createTableSQL = normalTableConfig.getCreateTableSQL();
String tableName = entry.getKey();
String schemaName = key;
HashMap<String, String> stringStringHashMap = map.computeIfAbsent(schemaName, s1 -> new HashMap<>());
stringStringHashMap.put(tableName, createTableSQL);
}
}
for (Map.Entry<String, HashMap<String, String>> stringHashMapEntry : map.entrySet()) {
String key = stringHashMapEntry.getKey();
HashMap<String, String> value = stringHashMapEntry.getValue();
System.out.println("-----------------------------------");
for (Map.Entry<String, String> stringStringEntry : value.entrySet()) {
String s1 = JsonUtil.toJson(stringStringEntry.getValue());
System.out.println("public static String " + stringStringEntry.getKey() + " = " + s1 + ";");
}
}
}
use of io.mycat.config.NormalTableConfig in project Mycat2 by MyCATApache.
the class MysqlSchema method main.
@SneakyThrows
public static void main(String[] args) {
Map<String, Map<String, NormalTableConfig>> normalTablesSet = Collections.emptyMap();
HashMap<String, HashMap<String, String>> map = new HashMap<>();
for (Map.Entry<String, Map<String, NormalTableConfig>> stringMapEntry : normalTablesSet.entrySet()) {
String key = stringMapEntry.getKey();
Map<String, NormalTableConfig> value = stringMapEntry.getValue();
for (Map.Entry<String, NormalTableConfig> entry : stringMapEntry.getValue().entrySet()) {
NormalTableConfig normalTableConfig = entry.getValue();
String createTableSQL = normalTableConfig.getCreateTableSQL();
String tableName = entry.getKey();
String schemaName = key;
HashMap<String, String> stringStringHashMap = map.computeIfAbsent(schemaName, s1 -> new HashMap<>());
stringStringHashMap.put(tableName, createTableSQL);
}
}
for (Map.Entry<String, HashMap<String, String>> stringHashMapEntry : map.entrySet()) {
String key = stringHashMapEntry.getKey();
HashMap<String, String> value = stringHashMapEntry.getValue();
System.out.println("-----------------------------------");
for (Map.Entry<String, String> stringStringEntry : value.entrySet()) {
String s1 = JsonUtil.toJson(stringStringEntry.getValue());
System.out.println("public static String " + stringStringEntry.getKey() + " = " + s1 + ";");
}
}
}
use of io.mycat.config.NormalTableConfig 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;
}
use of io.mycat.config.NormalTableConfig in project Mycat2 by MyCATApache.
the class MysqlSchema method getStringNormalTableConfigMap.
private static Map<String, NormalTableConfig> getStringNormalTableConfigMap(String path) throws IOException {
byte[] bytes = Files.readAllBytes(Paths.get(path));
String s = new String(bytes);
LogicSchemaConfig logicSchemaConfig = JsonUtil.from(s, LogicSchemaConfig.class);
Map<String, NormalTableConfig> normalTables1 = logicSchemaConfig.getNormalTables();
return normalTables1;
}
use of io.mycat.config.NormalTableConfig in project Mycat2 by MyCATApache.
the class PerformanceSchema method getStringNormalTableConfigMap.
private static Map<String, NormalTableConfig> getStringNormalTableConfigMap(String path) throws IOException {
byte[] bytes = Files.readAllBytes(Paths.get(path));
String s = new String(bytes);
LogicSchemaConfig logicSchemaConfig = JsonUtil.from(s, LogicSchemaConfig.class);
Map<String, NormalTableConfig> normalTables1 = logicSchemaConfig.getNormalTables();
return normalTables1;
}
Aggregations