Search in sources :

Example 1 with SingleKeyDynamicModuloTableShardingAlgorithm

use of com.dangdang.ddframe.rdb.integrate.fixture.SingleKeyDynamicModuloTableShardingAlgorithm in project sharding-jdbc by dangdangdotcom.

the class DynamicShardingBothHelper method getShardingDataSource.

public static ShardingDataSource getShardingDataSource(final Map<String, DataSource> dataSourceMap) {
    DataSourceRule dataSourceRule = new DataSourceRule(dataSourceMap);
    TableRule orderTableRule = TableRule.builder("t_order").dynamic(true).dataSourceRule(dataSourceRule).build();
    TableRule orderItemTableRule = TableRule.builder("t_order_item").dynamic(true).dataSourceRule(dataSourceRule).build();
    ShardingRule shardingRule = ShardingRule.builder().dataSourceRule(dataSourceRule).tableRules(Arrays.asList(orderTableRule, orderItemTableRule)).bindingTableRules(Collections.singletonList(new BindingTableRule(Arrays.asList(orderTableRule, orderItemTableRule)))).databaseShardingStrategy(new DatabaseShardingStrategy("user_id", new SingleKeyModuloDatabaseShardingAlgorithm())).tableShardingStrategy(new TableShardingStrategy("order_id", new SingleKeyDynamicModuloTableShardingAlgorithm("t_order_"))).build();
    return new ShardingDataSource(shardingRule);
}
Also used : TableRule(com.dangdang.ddframe.rdb.sharding.api.rule.TableRule) BindingTableRule(com.dangdang.ddframe.rdb.sharding.api.rule.BindingTableRule) DatabaseShardingStrategy(com.dangdang.ddframe.rdb.sharding.api.strategy.database.DatabaseShardingStrategy) ShardingDataSource(com.dangdang.ddframe.rdb.sharding.jdbc.ShardingDataSource) DataSourceRule(com.dangdang.ddframe.rdb.sharding.api.rule.DataSourceRule) SingleKeyDynamicModuloTableShardingAlgorithm(com.dangdang.ddframe.rdb.integrate.fixture.SingleKeyDynamicModuloTableShardingAlgorithm) BindingTableRule(com.dangdang.ddframe.rdb.sharding.api.rule.BindingTableRule) ShardingRule(com.dangdang.ddframe.rdb.sharding.api.rule.ShardingRule) TableShardingStrategy(com.dangdang.ddframe.rdb.sharding.api.strategy.table.TableShardingStrategy) SingleKeyModuloDatabaseShardingAlgorithm(com.dangdang.ddframe.rdb.integrate.fixture.SingleKeyModuloDatabaseShardingAlgorithm)

Aggregations

SingleKeyDynamicModuloTableShardingAlgorithm (com.dangdang.ddframe.rdb.integrate.fixture.SingleKeyDynamicModuloTableShardingAlgorithm)1 SingleKeyModuloDatabaseShardingAlgorithm (com.dangdang.ddframe.rdb.integrate.fixture.SingleKeyModuloDatabaseShardingAlgorithm)1 BindingTableRule (com.dangdang.ddframe.rdb.sharding.api.rule.BindingTableRule)1 DataSourceRule (com.dangdang.ddframe.rdb.sharding.api.rule.DataSourceRule)1 ShardingRule (com.dangdang.ddframe.rdb.sharding.api.rule.ShardingRule)1 TableRule (com.dangdang.ddframe.rdb.sharding.api.rule.TableRule)1 DatabaseShardingStrategy (com.dangdang.ddframe.rdb.sharding.api.strategy.database.DatabaseShardingStrategy)1 TableShardingStrategy (com.dangdang.ddframe.rdb.sharding.api.strategy.table.TableShardingStrategy)1 ShardingDataSource (com.dangdang.ddframe.rdb.sharding.jdbc.ShardingDataSource)1