Search in sources :

Example 61 with TableRuleConfiguration

use of io.shardingjdbc.core.api.config.TableRuleConfiguration 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 62 with TableRuleConfiguration

use of io.shardingjdbc.core.api.config.TableRuleConfiguration 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 63 with TableRuleConfiguration

use of io.shardingjdbc.core.api.config.TableRuleConfiguration 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)

Example 64 with TableRuleConfiguration

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

the class TableRuleTest method assertCreateMinTableRule.

@Test
public void assertCreateMinTableRule() {
    TableRuleConfiguration tableRuleConfig = new TableRuleConfiguration();
    tableRuleConfig.setLogicTable("LOGIC_TABLE");
    TableRule actual = new TableRule(tableRuleConfig, createDataSourceNames());
    assertThat(actual.getLogicTable(), is("logic_table"));
    assertThat(actual.getActualDataNodes().size(), is(2));
    assertTrue(actual.getActualDataNodes().contains(new DataNode("ds0", "LOGIC_TABLE")));
    assertTrue(actual.getActualDataNodes().contains(new DataNode("ds1", "LOGIC_TABLE")));
    assertNull(actual.getDatabaseShardingStrategy());
    assertNull(actual.getTableShardingStrategy());
    assertNull(actual.getLogicIndex());
}
Also used : TableRuleConfiguration(io.shardingjdbc.core.api.config.TableRuleConfiguration) Test(org.junit.Test)

Example 65 with TableRuleConfiguration

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

the class TableRuleTest method assertGetActualDatasourceNames.

@Test
public void assertGetActualDatasourceNames() {
    TableRuleConfiguration tableRuleConfig = new TableRuleConfiguration();
    tableRuleConfig.setLogicTable("LOGIC_TABLE");
    tableRuleConfig.setActualDataNodes("ds${0..1}.table_${0..2}");
    TableRule actual = new TableRule(tableRuleConfig, createDataSourceNames());
    assertThat(actual.getActualDatasourceNames(), is((Collection<String>) Sets.newLinkedHashSet(Arrays.asList("ds0", "ds1"))));
}
Also used : Collection(java.util.Collection) TableRuleConfiguration(io.shardingjdbc.core.api.config.TableRuleConfiguration) Test(org.junit.Test)

Aggregations

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