use of com.dangdang.ddframe.rdb.sharding.api.strategy.table.TableShardingStrategy 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);
}
use of com.dangdang.ddframe.rdb.sharding.api.strategy.table.TableShardingStrategy in project sharding-jdbc by dangdangdotcom.
the class StaticShardingBothHelper method getShardingDataSource.
public static ShardingDataSource getShardingDataSource(final Map<String, DataSource> dataSourceMap) {
DataSourceRule dataSourceRule = new DataSourceRule(dataSourceMap, "dataSource_dbtbl_0");
TableRule orderTableRule = TableRule.builder("t_order").actualTables(Arrays.asList("t_order_0", "t_order_1", "t_order_2", "t_order_3", "t_order_4", "t_order_5", "t_order_6", "t_order_7", "t_order_8", "t_order_9")).dataSourceRule(dataSourceRule).build();
TableRule orderItemTableRule = TableRule.builder("t_order_item").actualTables(Arrays.asList("t_order_item_0", "t_order_item_1", "t_order_item_2", "t_order_item_3", "t_order_item_4", "t_order_item_5", "t_order_item_6", "t_order_item_7", "t_order_item_8", "t_order_item_9")).dataSourceRule(dataSourceRule).build();
TableRule configRule = TableRule.builder("t_config").dataSourceRule(dataSourceRule).build();
ShardingRule shardingRule = ShardingRule.builder().dataSourceRule(dataSourceRule).tableRules(Arrays.asList(orderTableRule, orderItemTableRule, configRule)).bindingTableRules(Collections.singletonList(new BindingTableRule(Arrays.asList(orderTableRule, orderItemTableRule)))).databaseShardingStrategy(new DatabaseShardingStrategy("user_id", new SingleKeyModuloDatabaseShardingAlgorithm())).tableShardingStrategy(new TableShardingStrategy("order_id", new SingleKeyModuloTableShardingAlgorithm())).build();
return new ShardingDataSource(shardingRule);
}
use of com.dangdang.ddframe.rdb.sharding.api.strategy.table.TableShardingStrategy in project sharding-jdbc by dangdangdotcom.
the class AbstractShardingNullableDBUnitTest method getShardingDataSource.
protected final ShardingDataSource getShardingDataSource() {
if (null != shardingDataSource && !isShutdown) {
return shardingDataSource;
}
isShutdown = false;
DataSourceRule dataSourceRule = new DataSourceRule(createDataSourceMap("dataSource_%s"));
TableRule orderTableRule = TableRule.builder("t_order").dataSourceRule(dataSourceRule).build();
ShardingRule shardingRule = ShardingRule.builder().dataSourceRule(dataSourceRule).tableRules(Collections.singletonList(orderTableRule)).bindingTableRules(Collections.singletonList(new BindingTableRule(Collections.singletonList(orderTableRule)))).databaseShardingStrategy(new DatabaseShardingStrategy(Collections.singletonList("user_id"), new MultipleKeysModuloDatabaseShardingAlgorithm())).tableShardingStrategy(new TableShardingStrategy(Collections.singletonList("order_id"), new NoneTableShardingAlgorithm())).build();
shardingDataSource = new ShardingDataSource(shardingRule);
return shardingDataSource;
}
use of com.dangdang.ddframe.rdb.sharding.api.strategy.table.TableShardingStrategy in project sharding-jdbc by dangdangdotcom.
the class ShardingRuleTest method assertGetTableShardingStrategyFromDefault.
@Test
public void assertGetTableShardingStrategyFromDefault() {
TableShardingStrategy strategy = createTableShardingStrategy();
TableRule tableRule = createTableRule();
ShardingRule actual = ShardingRule.builder().dataSourceRule(createDataSourceRule()).tableRules(Collections.singletonList(tableRule)).tableShardingStrategy(strategy).build();
assertThat(actual.getTableShardingStrategy(tableRule), is(strategy));
}
use of com.dangdang.ddframe.rdb.sharding.api.strategy.table.TableShardingStrategy in project sharding-jdbc by dangdangdotcom.
the class ShardingRuleTest method assertGetTableShardingStrategyFromTableRule.
@Test
public void assertGetTableShardingStrategyFromTableRule() {
TableShardingStrategy strategy = createTableShardingStrategy();
TableRule tableRule = createTableRule(strategy);
ShardingRule actual = ShardingRule.builder().dataSourceRule(createDataSourceRule()).tableRules(Collections.singletonList(tableRule)).build();
assertThat(actual.getTableShardingStrategy(tableRule), is(strategy));
}
Aggregations