Search in sources :

Example 1 with OrderAttrShardingAlgorithm

use of com.dangdang.ddframe.rdb.sharding.router.fixture.OrderAttrShardingAlgorithm in project sharding-jdbc by dangdangdotcom.

the class AbstractBaseRouteSqlTest method setRouteRuleContext.

@Before
public void setRouteRuleContext() {
    Map<String, DataSource> dataSourceMap = new HashMap<>();
    dataSourceMap.put("ds_0", null);
    dataSourceMap.put("ds_1", null);
    DataSourceRule dataSourceRule = new DataSourceRule(dataSourceMap);
    TableRule orderTableRule = TableRule.builder("order").actualTables(Lists.newArrayList("order_0", "order_1")).dataSourceRule(dataSourceRule).build();
    TableRule orderItemTableRule = TableRule.builder("order_item").actualTables(Lists.newArrayList("order_item_0", "order_item_1")).dataSourceRule(dataSourceRule).build();
    TableRule orderAttrTableRule = TableRule.builder("order_attr").actualTables(Lists.newArrayList("ds_0.order_attr_a", "ds_1.order_attr_b")).dataSourceRule(dataSourceRule).tableShardingStrategy(new TableShardingStrategy("order_id", new OrderAttrShardingAlgorithm())).build();
    shardingRule = ShardingRule.builder().dataSourceRule(dataSourceRule).tableRules(Lists.newArrayList(orderTableRule, orderItemTableRule, orderAttrTableRule)).bindingTableRules(Collections.singletonList(new BindingTableRule(Arrays.asList(orderTableRule, orderItemTableRule)))).databaseShardingStrategy(new DatabaseShardingStrategy("order_id", new OrderShardingAlgorithm())).tableShardingStrategy(new TableShardingStrategy("order_id", new OrderShardingAlgorithm())).build();
}
Also used : TableRule(com.dangdang.ddframe.rdb.sharding.api.rule.TableRule) BindingTableRule(com.dangdang.ddframe.rdb.sharding.api.rule.BindingTableRule) OrderAttrShardingAlgorithm(com.dangdang.ddframe.rdb.sharding.router.fixture.OrderAttrShardingAlgorithm) DatabaseShardingStrategy(com.dangdang.ddframe.rdb.sharding.api.strategy.database.DatabaseShardingStrategy) HashMap(java.util.HashMap) DataSourceRule(com.dangdang.ddframe.rdb.sharding.api.rule.DataSourceRule) BindingTableRule(com.dangdang.ddframe.rdb.sharding.api.rule.BindingTableRule) OrderShardingAlgorithm(com.dangdang.ddframe.rdb.sharding.router.fixture.OrderShardingAlgorithm) TableShardingStrategy(com.dangdang.ddframe.rdb.sharding.api.strategy.table.TableShardingStrategy) DataSource(javax.sql.DataSource) Before(org.junit.Before)

Aggregations

BindingTableRule (com.dangdang.ddframe.rdb.sharding.api.rule.BindingTableRule)1 DataSourceRule (com.dangdang.ddframe.rdb.sharding.api.rule.DataSourceRule)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 OrderAttrShardingAlgorithm (com.dangdang.ddframe.rdb.sharding.router.fixture.OrderAttrShardingAlgorithm)1 OrderShardingAlgorithm (com.dangdang.ddframe.rdb.sharding.router.fixture.OrderShardingAlgorithm)1 HashMap (java.util.HashMap)1 DataSource (javax.sql.DataSource)1 Before (org.junit.Before)1