use of com.dangdang.ddframe.rdb.sharding.config.common.api.config.TableRuleConfig in project sharding-jdbc by dangdangdotcom.
the class ShardingRuleBuilderTest method createDynamicTableRuleConfig.
private TableRuleConfig createDynamicTableRuleConfig() {
TableRuleConfig result = new TableRuleConfig();
result.setDynamic(true);
return result;
}
use of com.dangdang.ddframe.rdb.sharding.config.common.api.config.TableRuleConfig 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;
}
use of com.dangdang.ddframe.rdb.sharding.config.common.api.config.TableRuleConfig in project sharding-jdbc by dangdangdotcom.
the class ShardingRuleBuilderTest method createTableRuleConfig.
private TableRuleConfig createTableRuleConfig(final String logicTable) {
TableRuleConfig result = new TableRuleConfig();
result.setActualTables(logicTable + "_${[0, 1]}");
result.setDataSourceNames("ds_${0..1}");
result.setDatabaseStrategy(getDatabaseStrategyConfig(SingleAlgorithm.class.getName()));
result.setTableStrategy(getTableStrategyConfigForExpression());
Map<String, String> autoIncrementColumnMap = new HashMap<>();
autoIncrementColumnMap.put("order_id", null);
AutoIncrementColumnConfig orderIdConfig = new AutoIncrementColumnConfig();
orderIdConfig.setColumnName("order_id");
autoIncrementColumnMap.put("order_item_id", "com.dangdang.ddframe.rdb.sharding.config.common.fixture.DecrementIdGenerator");
AutoIncrementColumnConfig orderItemIdConfig = new AutoIncrementColumnConfig();
orderItemIdConfig.setColumnName("order_item_id");
orderItemIdConfig.setColumnIdGeneratorClass(DecrementIdGenerator.class.getName());
result.setAutoIncrementColumns(Arrays.asList(orderIdConfig, orderItemIdConfig));
return result;
}
Aggregations