Search in sources :

Example 1 with NormalTableConfig

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 + ";");
        }
    }
}
Also used : NormalTableConfig(io.mycat.config.NormalTableConfig) SneakyThrows(lombok.SneakyThrows)

Example 2 with NormalTableConfig

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 + ";");
        }
    }
}
Also used : HashMap(java.util.HashMap) NormalTableConfig(io.mycat.config.NormalTableConfig) Map(java.util.Map) HashMap(java.util.HashMap) SneakyThrows(lombok.SneakyThrows)

Example 3 with NormalTableConfig

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;
}
Also used : NormalTableConfig(io.mycat.config.NormalTableConfig) NormalBackEndTableInfoConfig(io.mycat.config.NormalBackEndTableInfoConfig) DefaultConnection(io.mycat.datasource.jdbc.datasource.DefaultConnection) JdbcConnectionManager(io.mycat.datasource.jdbc.datasource.JdbcConnectionManager) RowBaseIterator(io.mycat.api.collector.RowBaseIterator) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 4 with NormalTableConfig

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;
}
Also used : LogicSchemaConfig(io.mycat.config.LogicSchemaConfig) NormalTableConfig(io.mycat.config.NormalTableConfig)

Example 5 with NormalTableConfig

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;
}
Also used : LogicSchemaConfig(io.mycat.config.LogicSchemaConfig) NormalTableConfig(io.mycat.config.NormalTableConfig)

Aggregations

NormalTableConfig (io.mycat.config.NormalTableConfig)5 LogicSchemaConfig (io.mycat.config.LogicSchemaConfig)2 SneakyThrows (lombok.SneakyThrows)2 RowBaseIterator (io.mycat.api.collector.RowBaseIterator)1 NormalBackEndTableInfoConfig (io.mycat.config.NormalBackEndTableInfoConfig)1 DefaultConnection (io.mycat.datasource.jdbc.datasource.DefaultConnection)1 JdbcConnectionManager (io.mycat.datasource.jdbc.datasource.JdbcConnectionManager)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1