Search in sources :

Example 16 with ShardingRuleConfiguration

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));
}
Also used : NoneShardingStrategyConfiguration(io.shardingjdbc.core.api.config.strategy.NoneShardingStrategyConfiguration) ShardingRuleConfiguration(io.shardingjdbc.core.api.config.ShardingRuleConfiguration) NoneShardingStrategy(io.shardingjdbc.core.routing.strategy.none.NoneShardingStrategy) TableRuleConfiguration(io.shardingjdbc.core.api.config.TableRuleConfiguration) Test(org.junit.Test)

Example 17 with ShardingRuleConfiguration

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));
}
Also used : NoneShardingStrategyConfiguration(io.shardingjdbc.core.api.config.strategy.NoneShardingStrategyConfiguration) ShardingRuleConfiguration(io.shardingjdbc.core.api.config.ShardingRuleConfiguration) NoneShardingStrategy(io.shardingjdbc.core.routing.strategy.none.NoneShardingStrategy) TableRuleConfiguration(io.shardingjdbc.core.api.config.TableRuleConfiguration) Test(org.junit.Test)

Example 18 with ShardingRuleConfiguration

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);
}
Also used : ShardingRuleConfiguration(io.shardingjdbc.core.api.config.ShardingRuleConfiguration) Test(org.junit.Test)

Example 19 with ShardingRuleConfiguration

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);
}
Also used : ShardingRuleConfiguration(io.shardingjdbc.core.api.config.ShardingRuleConfiguration) Test(org.junit.Test)

Example 20 with ShardingRuleConfiguration

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);
    }
}
Also used : YamlShardingRuleConfiguration(io.shardingjdbc.core.yaml.sharding.YamlShardingRuleConfiguration) YamlOrchestrationShardingRuleConfiguration(io.shardingjdbc.orchestration.yaml.YamlOrchestrationShardingRuleConfiguration) ShardingRuleConfiguration(io.shardingjdbc.core.api.config.ShardingRuleConfiguration) OrchestrationFacade(io.shardingjdbc.orchestration.internal.OrchestrationFacade) ConfigurationService(io.shardingjdbc.orchestration.internal.config.ConfigurationService)

Aggregations

ShardingRuleConfiguration (io.shardingjdbc.core.api.config.ShardingRuleConfiguration)65 TableRuleConfiguration (io.shardingjdbc.core.api.config.TableRuleConfiguration)43 Test (org.junit.Test)41 ShardingRule (io.shardingjdbc.core.rule.ShardingRule)16 NoneShardingStrategyConfiguration (io.shardingjdbc.core.api.config.strategy.NoneShardingStrategyConfiguration)15 ComplexShardingStrategyConfiguration (io.shardingjdbc.core.api.config.strategy.ComplexShardingStrategyConfiguration)8 StandardShardingStrategyConfiguration (io.shardingjdbc.core.api.config.strategy.StandardShardingStrategyConfiguration)7 ShardingDataSource (io.shardingjdbc.core.jdbc.core.datasource.ShardingDataSource)7 DatabaseType (io.shardingjdbc.core.constant.DatabaseType)6 LinkedList (java.util.LinkedList)6 Map (java.util.Map)6 DataSource (javax.sql.DataSource)6 SQLShardingRule (io.shardingjdbc.core.integrate.jaxb.SQLShardingRule)5 Column (io.shardingjdbc.core.parsing.parser.context.condition.Column)5 NoneShardingStrategy (io.shardingjdbc.core.routing.strategy.none.NoneShardingStrategy)5 Before (org.junit.Before)5 TestComplexKeysShardingAlgorithm (io.shardingjdbc.core.api.algorithm.fixture.TestComplexKeysShardingAlgorithm)4 HintShardingStrategyConfiguration (io.shardingjdbc.core.api.config.strategy.HintShardingStrategyConfiguration)3 ComplexKeysModuloDatabaseShardingAlgorithm (io.shardingjdbc.core.integrate.fixture.ComplexKeysModuloDatabaseShardingAlgorithm)3 TestPreciseShardingAlgorithm (io.shardingjdbc.core.api.algorithm.fixture.TestPreciseShardingAlgorithm)2