Search in sources :

Example 1 with NoneDatabaseShardingAlgorithm

use of com.dangdang.ddframe.rdb.sharding.api.strategy.database.NoneDatabaseShardingAlgorithm in project sharding-jdbc by dangdangdotcom.

the class ShardingRuleMockBuilder method build.

public ShardingRule build() {
    final DataSourceRule dataSourceRule = new DataSourceRule(ImmutableMap.of("db0", Mockito.mock(DataSource.class), "db1", Mockito.mock(DataSource.class)));
    Collection<TableRule> tableRules = Lists.newArrayList(Iterators.transform(autoIncrementColumnMap.keySet().iterator(), new Function<String, TableRule>() {

        @Override
        public TableRule apply(final String input) {
            TableRule.TableRuleBuilder builder = TableRule.builder(input).actualTables(Collections.singletonList(input)).dataSourceRule(dataSourceRule);
            for (String each : autoIncrementColumnMap.get(input)) {
                builder.autoIncrementColumns(each);
            }
            return builder.build();
        }
    }));
    if (tableRules.isEmpty()) {
        tableRules.add(new TableRule.TableRuleBuilder("mock").actualTables(Collections.singletonList("mock")).dataSourceRule(dataSourceRule).build());
    }
    return new ShardingRule.ShardingRuleBuilder().dataSourceRule(dataSourceRule).idGenerator(IncrementIdGenerator.class).tableRules(tableRules).databaseShardingStrategy(new DatabaseShardingStrategy(shardingColumns, new NoneDatabaseShardingAlgorithm())).build();
}
Also used : TableRule(com.dangdang.ddframe.rdb.sharding.api.rule.TableRule) Function(com.google.common.base.Function) DatabaseShardingStrategy(com.dangdang.ddframe.rdb.sharding.api.strategy.database.DatabaseShardingStrategy) DataSourceRule(com.dangdang.ddframe.rdb.sharding.api.rule.DataSourceRule) ShardingRule(com.dangdang.ddframe.rdb.sharding.api.rule.ShardingRule) NoneDatabaseShardingAlgorithm(com.dangdang.ddframe.rdb.sharding.api.strategy.database.NoneDatabaseShardingAlgorithm) IncrementIdGenerator(com.dangdang.ddframe.rdb.sharding.id.generator.fixture.IncrementIdGenerator)

Example 2 with NoneDatabaseShardingAlgorithm

use of com.dangdang.ddframe.rdb.sharding.api.strategy.database.NoneDatabaseShardingAlgorithm in project sharding-jdbc by dangdangdotcom.

the class TableRuleTest method assertTableRuleForDynamicWithDatabaseStrategy.

@Test
public void assertTableRuleForDynamicWithDatabaseStrategy() {
    TableRule actual = TableRule.builder("logicTable").dynamic(true).dataSourceRule(createDataSourceRule()).databaseShardingStrategy(new DatabaseShardingStrategy("", new NoneDatabaseShardingAlgorithm())).build();
    assertDynamicTable(actual);
    assertNotNull(actual.getDatabaseShardingStrategy());
    assertNull(actual.getTableShardingStrategy());
}
Also used : DatabaseShardingStrategy(com.dangdang.ddframe.rdb.sharding.api.strategy.database.DatabaseShardingStrategy) NoneDatabaseShardingAlgorithm(com.dangdang.ddframe.rdb.sharding.api.strategy.database.NoneDatabaseShardingAlgorithm) Test(org.junit.Test)

Example 3 with NoneDatabaseShardingAlgorithm

use of com.dangdang.ddframe.rdb.sharding.api.strategy.database.NoneDatabaseShardingAlgorithm in project sharding-jdbc by dangdangdotcom.

the class SingleTableRouter method createTableRuleWithDefaultDataSource.

private TableRule createTableRuleWithDefaultDataSource(final String logicTable, final DataSourceRule defaultDataSourceRule) {
    Map<String, DataSource> defaultDataSourceMap = new HashMap<>(1);
    defaultDataSourceMap.put(defaultDataSourceRule.getDefaultDataSourceName(), defaultDataSourceRule.getDefaultDataSource().get());
    return TableRule.builder(logicTable).dataSourceRule(new DataSourceRule(defaultDataSourceMap)).databaseShardingStrategy(new DatabaseShardingStrategy("", new NoneDatabaseShardingAlgorithm())).tableShardingStrategy(new TableShardingStrategy("", new NoneTableShardingAlgorithm())).build();
}
Also used : DatabaseShardingStrategy(com.dangdang.ddframe.rdb.sharding.api.strategy.database.DatabaseShardingStrategy) HashMap(java.util.HashMap) DataSourceRule(com.dangdang.ddframe.rdb.sharding.api.rule.DataSourceRule) NoneDatabaseShardingAlgorithm(com.dangdang.ddframe.rdb.sharding.api.strategy.database.NoneDatabaseShardingAlgorithm) TableShardingStrategy(com.dangdang.ddframe.rdb.sharding.api.strategy.table.TableShardingStrategy) NoneTableShardingAlgorithm(com.dangdang.ddframe.rdb.sharding.api.strategy.table.NoneTableShardingAlgorithm) DataSource(javax.sql.DataSource)

Example 4 with NoneDatabaseShardingAlgorithm

use of com.dangdang.ddframe.rdb.sharding.api.strategy.database.NoneDatabaseShardingAlgorithm in project sharding-jdbc by dangdangdotcom.

the class AbstractShardingTablesOnlyDBUnitTest 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").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();
    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 NoneDatabaseShardingAlgorithm())).tableShardingStrategy(new TableShardingStrategy("order_id", new SingleKeyModuloTableShardingAlgorithm())).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) NoneDatabaseShardingAlgorithm(com.dangdang.ddframe.rdb.sharding.api.strategy.database.NoneDatabaseShardingAlgorithm) TableShardingStrategy(com.dangdang.ddframe.rdb.sharding.api.strategy.table.TableShardingStrategy) SingleKeyModuloTableShardingAlgorithm(com.dangdang.ddframe.rdb.integrate.fixture.SingleKeyModuloTableShardingAlgorithm)

Example 5 with NoneDatabaseShardingAlgorithm

use of com.dangdang.ddframe.rdb.sharding.api.strategy.database.NoneDatabaseShardingAlgorithm in project sharding-jdbc by dangdangdotcom.

the class TableRuleTest method assertTableRuleWithDatabaseShardingStrategyWithoutDataNode.

@Test
public void assertTableRuleWithDatabaseShardingStrategyWithoutDataNode() {
    TableRule actual = TableRule.builder("logicTable").actualTables(Arrays.asList("table_0", "table_1", "table_2")).dataSourceRule(createDataSourceRule()).databaseShardingStrategy(new DatabaseShardingStrategy("", new NoneDatabaseShardingAlgorithm())).build();
    assertActualTable(actual);
    assertNotNull(actual.getDatabaseShardingStrategy());
    assertNull(actual.getTableShardingStrategy());
}
Also used : DatabaseShardingStrategy(com.dangdang.ddframe.rdb.sharding.api.strategy.database.DatabaseShardingStrategy) NoneDatabaseShardingAlgorithm(com.dangdang.ddframe.rdb.sharding.api.strategy.database.NoneDatabaseShardingAlgorithm) Test(org.junit.Test)

Aggregations

DatabaseShardingStrategy (com.dangdang.ddframe.rdb.sharding.api.strategy.database.DatabaseShardingStrategy)6 NoneDatabaseShardingAlgorithm (com.dangdang.ddframe.rdb.sharding.api.strategy.database.NoneDatabaseShardingAlgorithm)6 DataSourceRule (com.dangdang.ddframe.rdb.sharding.api.rule.DataSourceRule)3 TableShardingStrategy (com.dangdang.ddframe.rdb.sharding.api.strategy.table.TableShardingStrategy)3 Test (org.junit.Test)3 ShardingRule (com.dangdang.ddframe.rdb.sharding.api.rule.ShardingRule)2 TableRule (com.dangdang.ddframe.rdb.sharding.api.rule.TableRule)2 NoneTableShardingAlgorithm (com.dangdang.ddframe.rdb.sharding.api.strategy.table.NoneTableShardingAlgorithm)2 SingleKeyModuloTableShardingAlgorithm (com.dangdang.ddframe.rdb.integrate.fixture.SingleKeyModuloTableShardingAlgorithm)1 BindingTableRule (com.dangdang.ddframe.rdb.sharding.api.rule.BindingTableRule)1 IncrementIdGenerator (com.dangdang.ddframe.rdb.sharding.id.generator.fixture.IncrementIdGenerator)1 ShardingDataSource (com.dangdang.ddframe.rdb.sharding.jdbc.ShardingDataSource)1 Function (com.google.common.base.Function)1 HashMap (java.util.HashMap)1 DataSource (javax.sql.DataSource)1