Search in sources :

Example 41 with TableRuleConfiguration

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

the class ShardingRuleConfigurationConverterTest method getCommonShardingRuleConfig.

private ShardingRuleConfiguration getCommonShardingRuleConfig(final ShardingStrategyConfiguration strategyConfig) {
    ShardingRuleConfiguration actual = new ShardingRuleConfiguration();
    TableRuleConfiguration orderTableRuleConfig = new TableRuleConfiguration();
    orderTableRuleConfig.setLogicTable("t_order");
    orderTableRuleConfig.setActualDataNodes("t_order_${[0, 1]}");
    actual.getTableRuleConfigs().add(orderTableRuleConfig);
    TableRuleConfiguration orderItemTableRuleConfig = new TableRuleConfiguration();
    orderItemTableRuleConfig.setLogicTable("t_order_item");
    orderItemTableRuleConfig.setActualDataNodes("t_order_item_${[0, 1]}");
    actual.getTableRuleConfigs().add(orderItemTableRuleConfig);
    actual.getBindingTableGroups().add("t_order, t_order_item");
    actual.setDefaultTableShardingStrategyConfig(strategyConfig);
    return actual;
}
Also used : ShardingRuleConfiguration(io.shardingjdbc.core.api.config.ShardingRuleConfiguration) TableRuleConfiguration(io.shardingjdbc.core.api.config.TableRuleConfiguration)

Example 42 with TableRuleConfiguration

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

the class AbstractSoftTransactionIntegrationTest method prepareEnv.

private void prepareEnv() throws SQLException {
    ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
    TableRuleConfiguration tableRuleConfig = new TableRuleConfiguration();
    tableRuleConfig.setLogicTable("transaction_test");
    shardingRuleConfig.getTableRuleConfigs().add(tableRuleConfig);
    Map<String, DataSource> dataSourceMap = createDataSourceMap();
    ShardingRule shardingRule = new ShardingRule(shardingRuleConfig, dataSourceMap.keySet());
    shardingDataSource = new ShardingDataSource(dataSourceMap, shardingRule);
    createTable(shardingDataSource);
    transactionDataSource = createTransactionLogDataSource();
}
Also used : ShardingRuleConfiguration(io.shardingjdbc.core.api.config.ShardingRuleConfiguration) ShardingDataSource(io.shardingjdbc.core.jdbc.core.datasource.ShardingDataSource) ShardingRule(io.shardingjdbc.core.rule.ShardingRule) TableRuleConfiguration(io.shardingjdbc.core.api.config.TableRuleConfiguration) ShardingDataSource(io.shardingjdbc.core.jdbc.core.datasource.ShardingDataSource) BasicDataSource(org.apache.commons.dbcp2.BasicDataSource) DataSource(javax.sql.DataSource)

Example 43 with TableRuleConfiguration

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

the class YamlTableRuleConfigurationTest method assertBuildWithoutShardingStrategy.

@Test
public void assertBuildWithoutShardingStrategy() {
    TableRuleConfiguration actual = createYamlTableRuleConfig().build();
    assertTableRuleConfig(actual);
    assertWithoutShardingStrategy(actual);
}
Also used : TableRuleConfiguration(io.shardingjdbc.core.api.config.TableRuleConfiguration) Test(org.junit.Test)

Example 44 with TableRuleConfiguration

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

the class YamlTableRuleConfigurationTest method assertBuildWithShardingStrategy.

@Test
public void assertBuildWithShardingStrategy() {
    TableRuleConfiguration actual = createYamlTableRuleConfigWithShardingStrategy().build();
    assertTableRuleConfig(actual);
    assertWithShardingStrategy(actual);
}
Also used : TableRuleConfiguration(io.shardingjdbc.core.api.config.TableRuleConfiguration) Test(org.junit.Test)

Example 45 with TableRuleConfiguration

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

the class ShardingRuleTest method assertGetTableShardingStrategyForNullValue.

@Test
public void assertGetTableShardingStrategyForNullValue() {
    ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
    TableRuleConfiguration tableRuleConfig = createTableRuleConfig();
    shardingRuleConfig.getTableRuleConfigs().add(tableRuleConfig);
    shardingRuleConfig.setDefaultDatabaseShardingStrategyConfig(new NoneShardingStrategyConfiguration());
    ShardingRule actual = new ShardingRule(shardingRuleConfig, createDataSourceNames());
    assertNotNull(actual.getTableShardingStrategy(actual.getTableRule("logic_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)

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