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);
}
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;
}
Aggregations