Search in sources :

Example 1 with ComplexKeysModuloDatabaseShardingAlgorithm

use of io.shardingjdbc.core.integrate.fixture.ComplexKeysModuloDatabaseShardingAlgorithm in project sharding-jdbc by shardingjdbc.

the class AbstractNullableShardingTableOnlyTest method getDataSources.

@Override
protected final Map<DatabaseType, ShardingDataSource> getDataSources() throws SQLException {
    if (!getShardingDataSources().isEmpty()) {
        return getShardingDataSources();
    }
    Map<DatabaseType, Map<String, DataSource>> dataSourceMap = createDataSourceMap();
    for (Map.Entry<DatabaseType, Map<String, DataSource>> each : dataSourceMap.entrySet()) {
        ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
        TableRuleConfiguration tableRuleConfig = new TableRuleConfiguration();
        tableRuleConfig.setLogicTable("t_order");
        shardingRuleConfig.getTableRuleConfigs().add(tableRuleConfig);
        shardingRuleConfig.setDefaultDatabaseShardingStrategyConfig(new ComplexShardingStrategyConfiguration("user_id", new ComplexKeysModuloDatabaseShardingAlgorithm()));
        ShardingRule shardingRule = new ShardingRule(shardingRuleConfig, each.getValue().keySet());
        getShardingDataSources().put(each.getKey(), new ShardingDataSource(each.getValue(), shardingRule));
    }
    return getShardingDataSources();
}
Also used : DatabaseType(io.shardingjdbc.core.constant.DatabaseType) ShardingRuleConfiguration(io.shardingjdbc.core.api.config.ShardingRuleConfiguration) ShardingDataSource(io.shardingjdbc.core.jdbc.core.datasource.ShardingDataSource) ComplexShardingStrategyConfiguration(io.shardingjdbc.core.api.config.strategy.ComplexShardingStrategyConfiguration) ComplexKeysModuloDatabaseShardingAlgorithm(io.shardingjdbc.core.integrate.fixture.ComplexKeysModuloDatabaseShardingAlgorithm) SQLShardingRule(io.shardingjdbc.core.integrate.jaxb.SQLShardingRule) ShardingRule(io.shardingjdbc.core.rule.ShardingRule) Map(java.util.Map) TableRuleConfiguration(io.shardingjdbc.core.api.config.TableRuleConfiguration)

Example 2 with ComplexKeysModuloDatabaseShardingAlgorithm

use of io.shardingjdbc.core.integrate.fixture.ComplexKeysModuloDatabaseShardingAlgorithm in project sharding-jdbc by shardingjdbc.

the class AbstractShardingDatabaseOnlyWithHintTest method getShardingRule.

@Override
protected ShardingRule getShardingRule(final Map.Entry<DatabaseType, Map<String, DataSource>> dataSourceEntry) {
    ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
    TableRuleConfiguration orderTableRuleConfig = new TableRuleConfiguration();
    orderTableRuleConfig.setLogicTable("t_order");
    shardingRuleConfig.getTableRuleConfigs().add(orderTableRuleConfig);
    TableRuleConfiguration orderItemTableRuleConfig = new TableRuleConfiguration();
    orderItemTableRuleConfig.setLogicTable("t_order_item");
    shardingRuleConfig.getTableRuleConfigs().add(orderItemTableRuleConfig);
    shardingRuleConfig.getBindingTableGroups().add("t_order, t_order_item");
    shardingRuleConfig.setDefaultDatabaseShardingStrategyConfig(new ComplexShardingStrategyConfiguration("user_id", new ComplexKeysModuloDatabaseShardingAlgorithm()));
    shardingRuleConfig.setDefaultTableShardingStrategyConfig(new NoneShardingStrategyConfiguration());
    return new ShardingRule(shardingRuleConfig, dataSourceEntry.getValue().keySet());
}
Also used : NoneShardingStrategyConfiguration(io.shardingjdbc.core.api.config.strategy.NoneShardingStrategyConfiguration) ShardingRuleConfiguration(io.shardingjdbc.core.api.config.ShardingRuleConfiguration) ComplexShardingStrategyConfiguration(io.shardingjdbc.core.api.config.strategy.ComplexShardingStrategyConfiguration) ComplexKeysModuloDatabaseShardingAlgorithm(io.shardingjdbc.core.integrate.fixture.ComplexKeysModuloDatabaseShardingAlgorithm) ShardingRule(io.shardingjdbc.core.rule.ShardingRule) TableRuleConfiguration(io.shardingjdbc.core.api.config.TableRuleConfiguration)

Example 3 with ComplexKeysModuloDatabaseShardingAlgorithm

use of io.shardingjdbc.core.integrate.fixture.ComplexKeysModuloDatabaseShardingAlgorithm in project sharding-jdbc by shardingjdbc.

the class AbstractShardingDatabaseOnlyTest method getDataSources.

@Override
protected Map<DatabaseType, ShardingDataSource> getDataSources() throws SQLException {
    if (!getShardingDataSources().isEmpty()) {
        return getShardingDataSources();
    }
    Map<DatabaseType, Map<String, DataSource>> dataSourceMap = createDataSourceMap();
    for (Map.Entry<DatabaseType, Map<String, DataSource>> each : dataSourceMap.entrySet()) {
        final ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
        TableRuleConfiguration orderTableRuleConfig = new TableRuleConfiguration();
        orderTableRuleConfig.setLogicTable("t_order");
        orderTableRuleConfig.setLogicIndex("t_order_index");
        orderTableRuleConfig.setKeyGeneratorColumnName("order_id");
        orderTableRuleConfig.setKeyGenerator(new IncrementKeyGenerator());
        shardingRuleConfig.getTableRuleConfigs().add(orderTableRuleConfig);
        TableRuleConfiguration orderItemTableRuleConfig = new TableRuleConfiguration();
        orderItemTableRuleConfig.setLogicTable("t_order_item");
        TableRuleConfiguration logTableRuleConfig = new TableRuleConfiguration();
        logTableRuleConfig.setLogicIndex("t_log_index");
        logTableRuleConfig.setLogicTable("t_log");
        TableRuleConfiguration tempLogTableRuleConfig = new TableRuleConfiguration();
        tempLogTableRuleConfig.setLogicTable("t_temp_log");
        shardingRuleConfig.getTableRuleConfigs().add(logTableRuleConfig);
        shardingRuleConfig.getTableRuleConfigs().add(tempLogTableRuleConfig);
        shardingRuleConfig.getTableRuleConfigs().add(orderItemTableRuleConfig);
        shardingRuleConfig.getBindingTableGroups().add("t_order, t_order_item");
        shardingRuleConfig.setDefaultDatabaseShardingStrategyConfig(new ComplexShardingStrategyConfiguration("user_id", new ComplexKeysModuloDatabaseShardingAlgorithm()));
        shardingRuleConfig.setDefaultTableShardingStrategyConfig(new NoneShardingStrategyConfiguration());
        getShardingDataSources().put(each.getKey(), new ShardingDataSource(each.getValue(), new ShardingRule(shardingRuleConfig, each.getValue().keySet())));
    }
    return getShardingDataSources();
}
Also used : DatabaseType(io.shardingjdbc.core.constant.DatabaseType) NoneShardingStrategyConfiguration(io.shardingjdbc.core.api.config.strategy.NoneShardingStrategyConfiguration) ShardingRuleConfiguration(io.shardingjdbc.core.api.config.ShardingRuleConfiguration) ShardingDataSource(io.shardingjdbc.core.jdbc.core.datasource.ShardingDataSource) ComplexShardingStrategyConfiguration(io.shardingjdbc.core.api.config.strategy.ComplexShardingStrategyConfiguration) ComplexKeysModuloDatabaseShardingAlgorithm(io.shardingjdbc.core.integrate.fixture.ComplexKeysModuloDatabaseShardingAlgorithm) SQLShardingRule(io.shardingjdbc.core.integrate.jaxb.SQLShardingRule) ShardingRule(io.shardingjdbc.core.rule.ShardingRule) IncrementKeyGenerator(io.shardingjdbc.core.fixture.IncrementKeyGenerator) Map(java.util.Map) TableRuleConfiguration(io.shardingjdbc.core.api.config.TableRuleConfiguration)

Aggregations

ShardingRuleConfiguration (io.shardingjdbc.core.api.config.ShardingRuleConfiguration)3 TableRuleConfiguration (io.shardingjdbc.core.api.config.TableRuleConfiguration)3 ComplexShardingStrategyConfiguration (io.shardingjdbc.core.api.config.strategy.ComplexShardingStrategyConfiguration)3 ComplexKeysModuloDatabaseShardingAlgorithm (io.shardingjdbc.core.integrate.fixture.ComplexKeysModuloDatabaseShardingAlgorithm)3 ShardingRule (io.shardingjdbc.core.rule.ShardingRule)3 NoneShardingStrategyConfiguration (io.shardingjdbc.core.api.config.strategy.NoneShardingStrategyConfiguration)2 DatabaseType (io.shardingjdbc.core.constant.DatabaseType)2 SQLShardingRule (io.shardingjdbc.core.integrate.jaxb.SQLShardingRule)2 ShardingDataSource (io.shardingjdbc.core.jdbc.core.datasource.ShardingDataSource)2 Map (java.util.Map)2 IncrementKeyGenerator (io.shardingjdbc.core.fixture.IncrementKeyGenerator)1