Search in sources :

Example 1 with InlineParser

use of com.dangdang.ddframe.rdb.sharding.config.common.internal.parser.InlineParser in project sharding-jdbc by dangdangdotcom.

the class ShardingRuleBuilder method buildShardingStrategy.

private <T extends ShardingStrategy> T buildShardingStrategy(final StrategyConfig config, final Class<T> returnClass) {
    if (null == config) {
        return null;
    }
    Preconditions.checkArgument(Strings.isNullOrEmpty(config.getAlgorithmExpression()) && !Strings.isNullOrEmpty(config.getAlgorithmClassName()) || !Strings.isNullOrEmpty(config.getAlgorithmExpression()) && Strings.isNullOrEmpty(config.getAlgorithmClassName()));
    Preconditions.checkState(returnClass.isAssignableFrom(DatabaseShardingStrategy.class) || returnClass.isAssignableFrom(TableShardingStrategy.class), "Sharding-JDBC: returnClass is illegal");
    List<String> shardingColumns = new InlineParser(config.getShardingColumns()).split();
    if (Strings.isNullOrEmpty(config.getAlgorithmClassName())) {
        return buildShardingAlgorithmExpression(shardingColumns, config.getAlgorithmExpression(), returnClass);
    }
    return buildShardingAlgorithmClassName(shardingColumns, config.getAlgorithmClassName(), returnClass);
}
Also used : InlineParser(com.dangdang.ddframe.rdb.sharding.config.common.internal.parser.InlineParser)

Example 2 with InlineParser

use of com.dangdang.ddframe.rdb.sharding.config.common.internal.parser.InlineParser in project sharding-jdbc by dangdangdotcom.

the class ShardingRuleBuilder method buildTableRules.

private Collection<TableRule> buildTableRules(final DataSourceRule dataSourceRule) {
    Collection<TableRule> result = new ArrayList<>(shardingRuleConfig.getTables().size());
    for (Entry<String, TableRuleConfig> each : shardingRuleConfig.getTables().entrySet()) {
        String logicTable = each.getKey();
        TableRuleConfig tableRuleConfig = each.getValue();
        TableRule.TableRuleBuilder tableRuleBuilder = TableRule.builder(logicTable).dataSourceRule(dataSourceRule).dynamic(tableRuleConfig.isDynamic()).databaseShardingStrategy(buildShardingStrategy(tableRuleConfig.getDatabaseStrategy(), DatabaseShardingStrategy.class)).tableShardingStrategy(buildShardingStrategy(tableRuleConfig.getTableStrategy(), TableShardingStrategy.class));
        if (null != tableRuleConfig.getActualTables()) {
            tableRuleBuilder.actualTables(new InlineParser(tableRuleConfig.getActualTables()).evaluate());
        }
        if (!Strings.isNullOrEmpty(tableRuleConfig.getDataSourceNames())) {
            tableRuleBuilder.dataSourceNames(new InlineParser(tableRuleConfig.getDataSourceNames()).evaluate());
        }
        buildAutoIncrementColumn(tableRuleBuilder, tableRuleConfig);
        result.add(tableRuleBuilder.build());
    }
    return result;
}
Also used : TableRule(com.dangdang.ddframe.rdb.sharding.api.rule.TableRule) BindingTableRule(com.dangdang.ddframe.rdb.sharding.api.rule.BindingTableRule) ArrayList(java.util.ArrayList) InlineParser(com.dangdang.ddframe.rdb.sharding.config.common.internal.parser.InlineParser) TableShardingStrategy(com.dangdang.ddframe.rdb.sharding.api.strategy.table.TableShardingStrategy) BindingTableRuleConfig(com.dangdang.ddframe.rdb.sharding.config.common.api.config.BindingTableRuleConfig) TableRuleConfig(com.dangdang.ddframe.rdb.sharding.config.common.api.config.TableRuleConfig)

Aggregations

InlineParser (com.dangdang.ddframe.rdb.sharding.config.common.internal.parser.InlineParser)2 BindingTableRule (com.dangdang.ddframe.rdb.sharding.api.rule.BindingTableRule)1 TableRule (com.dangdang.ddframe.rdb.sharding.api.rule.TableRule)1 TableShardingStrategy (com.dangdang.ddframe.rdb.sharding.api.strategy.table.TableShardingStrategy)1 BindingTableRuleConfig (com.dangdang.ddframe.rdb.sharding.config.common.api.config.BindingTableRuleConfig)1 TableRuleConfig (com.dangdang.ddframe.rdb.sharding.config.common.api.config.TableRuleConfig)1 ArrayList (java.util.ArrayList)1