Search in sources :

Example 21 with TableRuleConfiguration

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

the class TableRuleTest method createTableRuleConfig.

private TableRuleConfiguration createTableRuleConfig() {
    TableRuleConfiguration result = new TableRuleConfiguration();
    result.setLogicTable("LOGIC_TABLE");
    result.setActualDataNodes("ds${0..1}.table_${0..2}");
    return result;
}
Also used : TableRuleConfiguration(io.shardingjdbc.core.api.config.TableRuleConfiguration)

Example 22 with TableRuleConfiguration

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

the class TableRuleTest method assertGetActualTableNames.

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

Example 23 with TableRuleConfiguration

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

the class TableRuleTest method assertFindActualTableIndex.

@Test
public void assertFindActualTableIndex() {
    TableRuleConfiguration tableRuleConfig = new TableRuleConfiguration();
    tableRuleConfig.setLogicTable("LOGIC_TABLE");
    tableRuleConfig.setActualDataNodes("ds${0..1}.table_${0..2}");
    TableRule actual = new TableRule(tableRuleConfig, createDataSourceNames());
    assertThat(actual.findActualTableIndex("ds1", "table_1"), is(4));
}
Also used : TableRuleConfiguration(io.shardingjdbc.core.api.config.TableRuleConfiguration) Test(org.junit.Test)

Example 24 with TableRuleConfiguration

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

the class TableRuleTest method assertNotFindActualTableIndex.

@Test
public void assertNotFindActualTableIndex() {
    TableRuleConfiguration tableRuleConfig = new TableRuleConfiguration();
    tableRuleConfig.setLogicTable("LOGIC_TABLE");
    tableRuleConfig.setActualDataNodes("ds${0..1}.table_${0..2}");
    TableRule actual = new TableRule(tableRuleConfig, createDataSourceNames());
    assertThat(actual.findActualTableIndex("ds2", "table_2"), is(-1));
}
Also used : TableRuleConfiguration(io.shardingjdbc.core.api.config.TableRuleConfiguration) Test(org.junit.Test)

Example 25 with TableRuleConfiguration

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

the class ShardingRuleConfigurationConverterTest method assertCommon.

private void assertCommon(final ShardingRuleConfiguration actual) {
    assertThat(actual.getTableRuleConfigs().size(), is(2));
    Iterator<TableRuleConfiguration> actualTableRuleConfigs = actual.getTableRuleConfigs().iterator();
    TableRuleConfiguration orderTableRuleConfig = actualTableRuleConfigs.next();
    assertThat(orderTableRuleConfig.getLogicTable(), is("t_order"));
    assertThat(orderTableRuleConfig.getActualDataNodes(), is("t_order_${[0, 1]}"));
    TableRuleConfiguration orderItemTableRuleConfig = actualTableRuleConfigs.next();
    assertThat(orderItemTableRuleConfig.getLogicTable(), is("t_order_item"));
    assertThat(orderItemTableRuleConfig.getActualDataNodes(), is("t_order_item_${[0, 1]}"));
    assertThat(actual.getBindingTableGroups().size(), is(1));
    assertThat(actual.getBindingTableGroups().iterator().next(), is("t_order, t_order_item"));
}
Also used : TableRuleConfiguration(io.shardingjdbc.core.api.config.TableRuleConfiguration)

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