use of io.shardingjdbc.core.api.config.ShardingRuleConfiguration in project sharding-jdbc by shardingjdbc.
the class ShardingRuleConfigurationConverterTest method assertFromJsonForInlineStrategy.
@Test
public void assertFromJsonForInlineStrategy() {
ShardingRuleConfiguration actual = ShardingRuleConfigurationConverter.fromJson(getJsonForInlineStrategy());
assertCommon(actual);
InlineShardingStrategyConfiguration actualShardingStrategy = (InlineShardingStrategyConfiguration) actual.getDefaultTableShardingStrategyConfig();
assertThat(actualShardingStrategy.getShardingColumn(), is("order_id"));
assertThat(actualShardingStrategy.getAlgorithmExpression(), is("order_${user_id % 2}"));
}
use of io.shardingjdbc.core.api.config.ShardingRuleConfiguration in project sharding-jdbc by shardingjdbc.
the class ShardingRuleConfigurationConverterTest method getCommonShardingRuleConfig.
private ShardingRuleConfiguration getCommonShardingRuleConfig(final ShardingStrategyConfiguration strategyConfig) {
ShardingRuleConfiguration actual = new ShardingRuleConfiguration();
TableRuleConfiguration orderTableRuleConfig = new TableRuleConfiguration();
orderTableRuleConfig.setLogicTable("t_order");
orderTableRuleConfig.setActualDataNodes("t_order_${[0, 1]}");
actual.getTableRuleConfigs().add(orderTableRuleConfig);
TableRuleConfiguration orderItemTableRuleConfig = new TableRuleConfiguration();
orderItemTableRuleConfig.setLogicTable("t_order_item");
orderItemTableRuleConfig.setActualDataNodes("t_order_item_${[0, 1]}");
actual.getTableRuleConfigs().add(orderItemTableRuleConfig);
actual.getBindingTableGroups().add("t_order, t_order_item");
actual.setDefaultTableShardingStrategyConfig(strategyConfig);
return actual;
}
use of io.shardingjdbc.core.api.config.ShardingRuleConfiguration in project sharding-jdbc by shardingjdbc.
the class ShardingRuleConfigurationConverterTest method assertFromJsonForComplexStrategy.
@Test
public void assertFromJsonForComplexStrategy() {
ShardingRuleConfiguration actual = ShardingRuleConfigurationConverter.fromJson(getJsonForComplexStrategy());
assertCommon(actual);
ComplexShardingStrategyConfiguration actualShardingStrategy = (ComplexShardingStrategyConfiguration) actual.getDefaultTableShardingStrategyConfig();
assertThat(actualShardingStrategy.getShardingColumns(), is("order_id,item_id"));
assertThat(actualShardingStrategy.getShardingAlgorithm(), instanceOf(TestComplexKeysShardingAlgorithm.class));
}
use of io.shardingjdbc.core.api.config.ShardingRuleConfiguration in project sharding-jdbc by shardingjdbc.
the class DataSourceService method getAvailableShardingRuleConfiguration.
/**
* Get available sharding rule configuration.
*
* @return available sharding rule configuration
*/
public ShardingRuleConfiguration getAvailableShardingRuleConfiguration() {
ShardingRuleConfiguration result = configService.loadShardingRuleConfiguration();
Collection<String> disabledDataSourceNames = getDisabledDataSourceNames();
for (String each : disabledDataSourceNames) {
for (MasterSlaveRuleConfiguration masterSlaveRuleConfig : result.getMasterSlaveRuleConfigs()) {
masterSlaveRuleConfig.getSlaveDataSourceNames().remove(each);
}
}
return result;
}
use of io.shardingjdbc.core.api.config.ShardingRuleConfiguration in project sharding-jdbc by shardingjdbc.
the class AbstractSoftTransactionIntegrationTest method prepareEnv.
private void prepareEnv() throws SQLException {
ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
TableRuleConfiguration tableRuleConfig = new TableRuleConfiguration();
tableRuleConfig.setLogicTable("transaction_test");
shardingRuleConfig.getTableRuleConfigs().add(tableRuleConfig);
Map<String, DataSource> dataSourceMap = createDataSourceMap();
ShardingRule shardingRule = new ShardingRule(shardingRuleConfig, dataSourceMap.keySet());
shardingDataSource = new ShardingDataSource(dataSourceMap, shardingRule);
createTable(shardingDataSource);
transactionDataSource = createTransactionLogDataSource();
}
Aggregations