Search in sources :

Example 1 with MultipleKeysModuloDatabaseShardingAlgorithm

use of com.dangdang.ddframe.rdb.integrate.fixture.MultipleKeysModuloDatabaseShardingAlgorithm 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;
}
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) TableShardingStrategy(com.dangdang.ddframe.rdb.sharding.api.strategy.table.TableShardingStrategy) MultipleKeysModuloDatabaseShardingAlgorithm(com.dangdang.ddframe.rdb.integrate.fixture.MultipleKeysModuloDatabaseShardingAlgorithm) NoneTableShardingAlgorithm(com.dangdang.ddframe.rdb.sharding.api.strategy.table.NoneTableShardingAlgorithm)

Example 2 with MultipleKeysModuloDatabaseShardingAlgorithm

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

the class AbstractShardingDataBasesOnlyHintDBUnitTest method initDataSource.

ShardingDataSource initDataSource() {
    DataSourceRule dataSourceRule = new DataSourceRule(createDataSourceMap("dataSource_%s"));
    TableRule orderTableRule = TableRule.builder("t_order").dataSourceRule(dataSourceRule).build();
    TableRule orderItemTableRule = TableRule.builder("t_order_item").dataSourceRule(dataSourceRule).build();
    ShardingRule shardingRule = ShardingRule.builder().dataSourceRule(dataSourceRule).tableRules(Lists.newArrayList(orderTableRule, orderItemTableRule)).bindingTableRules(Collections.singletonList(new BindingTableRule(Arrays.asList(orderTableRule, orderItemTableRule)))).databaseShardingStrategy(new DatabaseShardingStrategy(Collections.singletonList("user_id"), new MultipleKeysModuloDatabaseShardingAlgorithm())).tableShardingStrategy(new TableShardingStrategy(Collections.singletonList("order_id"), new NoneTableShardingAlgorithm())).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) TableShardingStrategy(com.dangdang.ddframe.rdb.sharding.api.strategy.table.TableShardingStrategy) MultipleKeysModuloDatabaseShardingAlgorithm(com.dangdang.ddframe.rdb.integrate.fixture.MultipleKeysModuloDatabaseShardingAlgorithm) NoneTableShardingAlgorithm(com.dangdang.ddframe.rdb.sharding.api.strategy.table.NoneTableShardingAlgorithm)

Example 3 with MultipleKeysModuloDatabaseShardingAlgorithm

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

the class AbstractShardingDataBasesOnlyDBUnitTest 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).autoIncrementColumns("user_id").tableIdGenerator(IncrementIdGenerator.class).build();
    TableRule orderItemTableRule = TableRule.builder("t_order_item").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(Collections.singletonList("user_id"), new MultipleKeysModuloDatabaseShardingAlgorithm())).tableShardingStrategy(new TableShardingStrategy(Collections.singletonList("order_id"), new NoneTableShardingAlgorithm())).build();
    shardingDataSource = new ShardingDataSource(shardingRule);
    return shardingDataSource;
}
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) TableShardingStrategy(com.dangdang.ddframe.rdb.sharding.api.strategy.table.TableShardingStrategy) IncrementIdGenerator(com.dangdang.ddframe.rdb.sharding.id.generator.fixture.IncrementIdGenerator) MultipleKeysModuloDatabaseShardingAlgorithm(com.dangdang.ddframe.rdb.integrate.fixture.MultipleKeysModuloDatabaseShardingAlgorithm) NoneTableShardingAlgorithm(com.dangdang.ddframe.rdb.sharding.api.strategy.table.NoneTableShardingAlgorithm)

Aggregations

MultipleKeysModuloDatabaseShardingAlgorithm (com.dangdang.ddframe.rdb.integrate.fixture.MultipleKeysModuloDatabaseShardingAlgorithm)3 BindingTableRule (com.dangdang.ddframe.rdb.sharding.api.rule.BindingTableRule)3 DataSourceRule (com.dangdang.ddframe.rdb.sharding.api.rule.DataSourceRule)3 ShardingRule (com.dangdang.ddframe.rdb.sharding.api.rule.ShardingRule)3 TableRule (com.dangdang.ddframe.rdb.sharding.api.rule.TableRule)3 DatabaseShardingStrategy (com.dangdang.ddframe.rdb.sharding.api.strategy.database.DatabaseShardingStrategy)3 NoneTableShardingAlgorithm (com.dangdang.ddframe.rdb.sharding.api.strategy.table.NoneTableShardingAlgorithm)3 TableShardingStrategy (com.dangdang.ddframe.rdb.sharding.api.strategy.table.TableShardingStrategy)3 ShardingDataSource (com.dangdang.ddframe.rdb.sharding.jdbc.ShardingDataSource)3 IncrementIdGenerator (com.dangdang.ddframe.rdb.sharding.id.generator.fixture.IncrementIdGenerator)1