Search in sources :

Example 16 with NoneShardingStrategyConfiguration

use of io.shardingjdbc.core.api.config.strategy.NoneShardingStrategyConfiguration in project sharding-jdbc by shardingjdbc.

the class ShardingRuleTest method assertShardingRuleWithDatabaseStrategy.

@Test
public void assertShardingRuleWithDatabaseStrategy() {
    ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
    TableRuleConfiguration tableRuleConfig = createTableRuleConfig();
    shardingRuleConfig.getTableRuleConfigs().add(tableRuleConfig);
    shardingRuleConfig.setDefaultDatabaseShardingStrategyConfig(new NoneShardingStrategyConfiguration());
    ShardingRule actual = new ShardingRule(shardingRuleConfig, createDataSourceNames());
    assertTrue(actual.getDefaultDatabaseShardingStrategy().getShardingColumns().isEmpty());
    assertTrue(actual.getDefaultTableShardingStrategy().getShardingColumns().isEmpty());
}
Also used : NoneShardingStrategyConfiguration(io.shardingjdbc.core.api.config.strategy.NoneShardingStrategyConfiguration) ShardingRuleConfiguration(io.shardingjdbc.core.api.config.ShardingRuleConfiguration) TableRuleConfiguration(io.shardingjdbc.core.api.config.TableRuleConfiguration) Test(org.junit.Test)

Example 17 with NoneShardingStrategyConfiguration

use of io.shardingjdbc.core.api.config.strategy.NoneShardingStrategyConfiguration in project sharding-jdbc by shardingjdbc.

the class ShardingRuleTest method createTableRuleConfigWithAllStrategies.

private TableRuleConfiguration createTableRuleConfigWithAllStrategies() {
    TableRuleConfiguration result = new TableRuleConfiguration();
    result.setLogicTable("LOGIC_TABLE");
    result.setActualDataNodes("ds${0..1}.table_${0..2}");
    result.setDatabaseShardingStrategyConfig(new StandardShardingStrategyConfiguration("column", new TestPreciseShardingAlgorithm()));
    result.setTableShardingStrategyConfig(new NoneShardingStrategyConfiguration());
    return result;
}
Also used : StandardShardingStrategyConfiguration(io.shardingjdbc.core.api.config.strategy.StandardShardingStrategyConfiguration) TestPreciseShardingAlgorithm(io.shardingjdbc.core.api.algorithm.fixture.TestPreciseShardingAlgorithm) NoneShardingStrategyConfiguration(io.shardingjdbc.core.api.config.strategy.NoneShardingStrategyConfiguration) TableRuleConfiguration(io.shardingjdbc.core.api.config.TableRuleConfiguration)

Example 18 with NoneShardingStrategyConfiguration

use of io.shardingjdbc.core.api.config.strategy.NoneShardingStrategyConfiguration in project sharding-jdbc by shardingjdbc.

the class ShardingRuleTest method assertGetNoDatabaseShardingStrategy.

@Test(expected = ShardingConfigurationException.class)
public void assertGetNoDatabaseShardingStrategy() {
    ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
    TableRuleConfiguration tableRuleConfig = createTableRuleConfigWithDatabaseShardingStrategy(new NoneShardingStrategyConfiguration());
    shardingRuleConfig.getTableRuleConfigs().add(tableRuleConfig);
    ShardingRule actual = new ShardingRule(shardingRuleConfig, createDataSourceNames());
    actual.getDatabaseShardingStrategy(actual.getTableRule("other_Table"));
}
Also used : NoneShardingStrategyConfiguration(io.shardingjdbc.core.api.config.strategy.NoneShardingStrategyConfiguration) ShardingRuleConfiguration(io.shardingjdbc.core.api.config.ShardingRuleConfiguration) TableRuleConfiguration(io.shardingjdbc.core.api.config.TableRuleConfiguration) Test(org.junit.Test)

Example 19 with NoneShardingStrategyConfiguration

use of io.shardingjdbc.core.api.config.strategy.NoneShardingStrategyConfiguration in project sharding-jdbc by shardingjdbc.

the class TableRuleTest method assertCreateFullTableRule.

@Test
public void assertCreateFullTableRule() {
    TableRuleConfiguration tableRuleConfig = new TableRuleConfiguration();
    tableRuleConfig.setLogicTable("LOGIC_TABLE");
    tableRuleConfig.setActualDataNodes("ds${0..1}.table_${0..2}");
    tableRuleConfig.setDatabaseShardingStrategyConfig(new NoneShardingStrategyConfiguration());
    tableRuleConfig.setTableShardingStrategyConfig(new NoneShardingStrategyConfiguration());
    tableRuleConfig.setKeyGeneratorColumnName("col_1");
    tableRuleConfig.setKeyGenerator(new IncrementKeyGenerator());
    tableRuleConfig.setLogicIndex("LOGIC_INDEX");
    TableRule actual = new TableRule(tableRuleConfig, createDataSourceNames());
    assertThat(actual.getLogicTable(), is("logic_table"));
    assertThat(actual.getActualDataNodes().size(), is(6));
    assertTrue(actual.getActualDataNodes().contains(new DataNode("ds0", "table_0")));
    assertTrue(actual.getActualDataNodes().contains(new DataNode("ds0", "table_1")));
    assertTrue(actual.getActualDataNodes().contains(new DataNode("ds0", "table_2")));
    assertTrue(actual.getActualDataNodes().contains(new DataNode("ds1", "table_0")));
    assertTrue(actual.getActualDataNodes().contains(new DataNode("ds1", "table_1")));
    assertTrue(actual.getActualDataNodes().contains(new DataNode("ds1", "table_2")));
    assertNotNull(actual.getDatabaseShardingStrategy());
    assertNotNull(actual.getTableShardingStrategy());
    assertThat(actual.getGenerateKeyColumn(), is("col_1"));
    assertThat(actual.getKeyGenerator(), instanceOf(IncrementKeyGenerator.class));
    assertThat(actual.getLogicIndex(), is("logic_index"));
}
Also used : NoneShardingStrategyConfiguration(io.shardingjdbc.core.api.config.strategy.NoneShardingStrategyConfiguration) IncrementKeyGenerator(io.shardingjdbc.core.keygen.fixture.IncrementKeyGenerator) TableRuleConfiguration(io.shardingjdbc.core.api.config.TableRuleConfiguration) Test(org.junit.Test)

Aggregations

NoneShardingStrategyConfiguration (io.shardingjdbc.core.api.config.strategy.NoneShardingStrategyConfiguration)19 TableRuleConfiguration (io.shardingjdbc.core.api.config.TableRuleConfiguration)16 ShardingRuleConfiguration (io.shardingjdbc.core.api.config.ShardingRuleConfiguration)14 Test (org.junit.Test)13 NoneShardingStrategy (io.shardingjdbc.core.routing.strategy.none.NoneShardingStrategy)5 ComplexShardingStrategyConfiguration (io.shardingjdbc.core.api.config.strategy.ComplexShardingStrategyConfiguration)4 StandardShardingStrategyConfiguration (io.shardingjdbc.core.api.config.strategy.StandardShardingStrategyConfiguration)4 ShardingRule (io.shardingjdbc.core.rule.ShardingRule)3 HintShardingStrategyConfiguration (io.shardingjdbc.core.api.config.strategy.HintShardingStrategyConfiguration)2 InlineShardingStrategyConfiguration (io.shardingjdbc.core.api.config.strategy.InlineShardingStrategyConfiguration)2 DatabaseType (io.shardingjdbc.core.constant.DatabaseType)2 ComplexKeysModuloDatabaseShardingAlgorithm (io.shardingjdbc.core.integrate.fixture.ComplexKeysModuloDatabaseShardingAlgorithm)2 SQLShardingRule (io.shardingjdbc.core.integrate.jaxb.SQLShardingRule)2 ShardingDataSource (io.shardingjdbc.core.jdbc.core.datasource.ShardingDataSource)2 Map (java.util.Map)2 TestPreciseShardingAlgorithm (io.shardingjdbc.core.api.algorithm.fixture.TestPreciseShardingAlgorithm)1 ShardingStrategyConfiguration (io.shardingjdbc.core.api.config.strategy.ShardingStrategyConfiguration)1 IncrementKeyGenerator (io.shardingjdbc.core.fixture.IncrementKeyGenerator)1 PreciseModuloTableShardingAlgorithm (io.shardingjdbc.core.integrate.fixture.PreciseModuloTableShardingAlgorithm)1 RangeModuloTableShardingAlgorithm (io.shardingjdbc.core.integrate.fixture.RangeModuloTableShardingAlgorithm)1