Search in sources :

Example 1 with ModuloTableShardingAlgorithm

use of com.dangdang.ddframe.rdb.sharding.example.transaction.algorithm.ModuloTableShardingAlgorithm in project sharding-jdbc by dangdangdotcom.

the class Main method getShardingDataSource.

private static DataSource getShardingDataSource() {
    DataSourceRule dataSourceRule = new DataSourceRule(createDataSourceMap());
    TableRule orderTableRule = TableRule.builder("t_order").actualTables(Arrays.asList("t_order_0", "t_order_1")).dataSourceRule(dataSourceRule).build();
    TableRule orderItemTableRule = TableRule.builder("t_order_item").actualTables(Arrays.asList("t_order_item_0", "t_order_item_1")).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 ModuloDatabaseShardingAlgorithm())).tableShardingStrategy(new TableShardingStrategy("order_id", new ModuloTableShardingAlgorithm())).build();
    return ShardingDataSourceFactory.createDataSource(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) DataSourceRule(com.dangdang.ddframe.rdb.sharding.api.rule.DataSourceRule) BindingTableRule(com.dangdang.ddframe.rdb.sharding.api.rule.BindingTableRule) ShardingRule(com.dangdang.ddframe.rdb.sharding.api.rule.ShardingRule) ModuloDatabaseShardingAlgorithm(com.dangdang.ddframe.rdb.sharding.example.transaction.algorithm.ModuloDatabaseShardingAlgorithm) TableShardingStrategy(com.dangdang.ddframe.rdb.sharding.api.strategy.table.TableShardingStrategy) ModuloTableShardingAlgorithm(com.dangdang.ddframe.rdb.sharding.example.transaction.algorithm.ModuloTableShardingAlgorithm)

Aggregations

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 ModuloDatabaseShardingAlgorithm (com.dangdang.ddframe.rdb.sharding.example.transaction.algorithm.ModuloDatabaseShardingAlgorithm)1 ModuloTableShardingAlgorithm (com.dangdang.ddframe.rdb.sharding.example.transaction.algorithm.ModuloTableShardingAlgorithm)1