use of io.shardingjdbc.core.api.config.ShardingRuleConfiguration in project sharding-jdbc by shardingjdbc.
the class ShardingRuleTest method assertGetDatabaseShardingStrategyFromDefault.
@Test
public void assertGetDatabaseShardingStrategyFromDefault() {
ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
TableRuleConfiguration tableRuleConfig = createTableRuleConfig();
shardingRuleConfig.getTableRuleConfigs().add(tableRuleConfig);
shardingRuleConfig.setDefaultDatabaseShardingStrategyConfig(new NoneShardingStrategyConfiguration());
ShardingRule actual = new ShardingRule(shardingRuleConfig, createDataSourceNames());
assertThat(actual.getDatabaseShardingStrategy(actual.getTableRule("logic_Table")), instanceOf(NoneShardingStrategy.class));
}
use of io.shardingjdbc.core.api.config.ShardingRuleConfiguration in project sharding-jdbc by shardingjdbc.
the class ShardingRuleTest method assertGetDatabaseShardingStrategyWithDefaultDataSource.
@Test
public void assertGetDatabaseShardingStrategyWithDefaultDataSource() {
ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
shardingRuleConfig.setDefaultDataSourceName("ds0");
TableRuleConfiguration tableRuleConfig = createTableRuleConfigWithDatabaseShardingStrategy(new NoneShardingStrategyConfiguration());
shardingRuleConfig.getTableRuleConfigs().add(tableRuleConfig);
ShardingRule actual = new ShardingRule(shardingRuleConfig, createDataSourceNames());
assertThat(actual.getDatabaseShardingStrategy(actual.getTableRule("other_Table")), instanceOf(NoneShardingStrategy.class));
}
use of io.shardingjdbc.core.api.config.ShardingRuleConfiguration in project sharding-jdbc by shardingjdbc.
the class YamlShardingRuleConfigurationTest method assertGetShardingRuleConfigurationWithoutDefaultStrategy.
@Test
public void assertGetShardingRuleConfigurationWithoutDefaultStrategy() {
ShardingRuleConfiguration actual = createYamlShardingRuleConfigWithoutDefaultStrategy().getShardingRuleConfiguration();
assertShardingRuleConfig(actual);
assertWithoutDefaultStrategy(actual);
}
use of io.shardingjdbc.core.api.config.ShardingRuleConfiguration in project sharding-jdbc by shardingjdbc.
the class YamlShardingRuleConfigurationTest method assertGetShardingRuleConfigurationWithDefaultStrategy.
@Test
public void assertGetShardingRuleConfigurationWithDefaultStrategy() {
ShardingRuleConfiguration actual = createYamlShardingRuleConfigWithDefaultStrategy().getShardingRuleConfiguration();
assertShardingRuleConfig(actual);
assertWithDefaultStrategy(actual);
}
use of io.shardingjdbc.core.api.config.ShardingRuleConfiguration in project sharding-jdbc by shardingjdbc.
the class OrchestrationShardingDataSourceFactory method createDataSource.
/**
* Create sharding data source.
*
* @param dataSourceMap data source map
* @param yamlShardingRuleConfig yaml sharding rule configuration
* @param orchestrationConfig orchestration configuration
* @return sharding data source
* @throws SQLException SQL exception
*/
public static DataSource createDataSource(final Map<String, DataSource> dataSourceMap, final YamlShardingRuleConfiguration yamlShardingRuleConfig, final OrchestrationConfiguration orchestrationConfig) throws SQLException {
OrchestrationFacade orchestrationFacade = new OrchestrationFacade(orchestrationConfig);
if (null == yamlShardingRuleConfig) {
ConfigurationService configService = orchestrationFacade.getConfigService();
final ShardingRuleConfiguration cloudShardingRuleConfig = configService.loadShardingRuleConfiguration();
Preconditions.checkState(null != cloudShardingRuleConfig, "Missing the sharding rule configuration on register center");
return createDataSource(configService.loadDataSourceMap(), cloudShardingRuleConfig, configService.loadShardingConfigMap(), configService.loadShardingProperties(), orchestrationFacade);
} else {
return createDataSource(dataSourceMap, yamlShardingRuleConfig.getShardingRuleConfiguration(), yamlShardingRuleConfig.getConfigMap(), yamlShardingRuleConfig.getProps(), orchestrationFacade);
}
}
Aggregations