Search in sources :

Example 1 with TableRuleConfig

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;
}
Also used : BindingTableRuleConfig(com.dangdang.ddframe.rdb.sharding.config.common.api.config.BindingTableRuleConfig) TableRuleConfig(com.dangdang.ddframe.rdb.sharding.config.common.api.config.TableRuleConfig)

Example 2 with TableRuleConfig

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

Example 3 with TableRuleConfig

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;
}
Also used : AutoIncrementColumnConfig(com.dangdang.ddframe.rdb.sharding.config.common.api.config.AutoIncrementColumnConfig) HashMap(java.util.HashMap) DecrementIdGenerator(com.dangdang.ddframe.rdb.sharding.config.common.fixture.DecrementIdGenerator) BindingTableRuleConfig(com.dangdang.ddframe.rdb.sharding.config.common.api.config.BindingTableRuleConfig) TableRuleConfig(com.dangdang.ddframe.rdb.sharding.config.common.api.config.TableRuleConfig)

Aggregations

BindingTableRuleConfig (com.dangdang.ddframe.rdb.sharding.config.common.api.config.BindingTableRuleConfig)3 TableRuleConfig (com.dangdang.ddframe.rdb.sharding.config.common.api.config.TableRuleConfig)3 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 AutoIncrementColumnConfig (com.dangdang.ddframe.rdb.sharding.config.common.api.config.AutoIncrementColumnConfig)1 DecrementIdGenerator (com.dangdang.ddframe.rdb.sharding.config.common.fixture.DecrementIdGenerator)1 InlineParser (com.dangdang.ddframe.rdb.sharding.config.common.internal.parser.InlineParser)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1