Search in sources :

Example 1 with ModuloDatabaseShardingAlgorithm

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

the class Main method getShardingDataSource.

private static ShardingDataSource 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 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) 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.jdbc.masterslave.algorithm.ModuloDatabaseShardingAlgorithm) TableShardingStrategy(com.dangdang.ddframe.rdb.sharding.api.strategy.table.TableShardingStrategy) ModuloTableShardingAlgorithm(com.dangdang.ddframe.rdb.sharding.example.jdbc.masterslave.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.jdbc.masterslave.algorithm.ModuloDatabaseShardingAlgorithm)1 ModuloTableShardingAlgorithm (com.dangdang.ddframe.rdb.sharding.example.jdbc.masterslave.algorithm.ModuloTableShardingAlgorithm)1 ShardingDataSource (com.dangdang.ddframe.rdb.sharding.jdbc.ShardingDataSource)1