use of io.shardingjdbc.core.api.config.ShardingRuleConfiguration in project sharding-jdbc by shardingjdbc.
the class ShardingRuleTest method createShardingRule.
private ShardingRule createShardingRule() {
ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
TableRuleConfiguration tableRuleConfig = createTableRuleConfig();
TableRuleConfiguration subTableRuleConfig = createSubTableRuleConfig();
shardingRuleConfig.getTableRuleConfigs().add(tableRuleConfig);
shardingRuleConfig.getTableRuleConfigs().add(subTableRuleConfig);
shardingRuleConfig.getBindingTableGroups().add(createTableRuleConfig().getLogicTable() + "," + createSubTableRuleConfig().getLogicTable());
return new ShardingRule(shardingRuleConfig, createDataSourceNames());
}
use of io.shardingjdbc.core.api.config.ShardingRuleConfiguration in project sharding-jdbc by shardingjdbc.
the class ShardingRuleTest method assertGetBindingTableRuleForNotConfig.
@Test
public void assertGetBindingTableRuleForNotConfig() {
ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
TableRuleConfiguration tableRuleConfig = createTableRuleConfig();
shardingRuleConfig.getTableRuleConfigs().add(tableRuleConfig);
ShardingRule actual = new ShardingRule(shardingRuleConfig, createDataSourceNames());
assertFalse(actual.findBindingTableRule("logic_Table").isPresent());
}
use of io.shardingjdbc.core.api.config.ShardingRuleConfiguration in project sharding-jdbc by shardingjdbc.
the class ShardingRuleTest method assertGenerateKeyWithKeyGenerator.
@Test
public void assertGenerateKeyWithKeyGenerator() {
ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
TableRuleConfiguration tableRuleConfig = createTableRuleConfig();
tableRuleConfig.setKeyGenerator(new IncrementKeyGenerator());
shardingRuleConfig.getTableRuleConfigs().add(tableRuleConfig);
assertThat(new ShardingRule(shardingRuleConfig, createDataSourceNames()).generateKey("logic_table"), instanceOf(Integer.class));
}
use of io.shardingjdbc.core.api.config.ShardingRuleConfiguration in project sharding-jdbc by shardingjdbc.
the class ShardingRuleTest method assertGetGenerateKeyColumn.
@Test
public void assertGetGenerateKeyColumn() {
ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
TableRuleConfiguration tableRuleConfig = createTableRuleConfig();
shardingRuleConfig.getTableRuleConfigs().add(tableRuleConfig);
ShardingRule actual = new ShardingRule(shardingRuleConfig, createDataSourceNames());
assertFalse(actual.getGenerateKeyColumn("table_0").isPresent());
assertFalse(actual.getGenerateKeyColumn("logic_table").isPresent());
}
use of io.shardingjdbc.core.api.config.ShardingRuleConfiguration in project sharding-jdbc by shardingjdbc.
the class ShardingRuleTest method assertGetTableShardingStrategyFromDefault.
@Test
public void assertGetTableShardingStrategyFromDefault() {
ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
TableRuleConfiguration tableRuleConfig = createTableRuleConfig();
shardingRuleConfig.getTableRuleConfigs().add(tableRuleConfig);
shardingRuleConfig.setDefaultDatabaseShardingStrategyConfig(new NoneShardingStrategyConfiguration());
ShardingRule actual = new ShardingRule(shardingRuleConfig, createDataSourceNames());
assertThat(actual.getTableShardingStrategy(actual.getTableRule("logic_Table")), instanceOf(NoneShardingStrategy.class));
}
Aggregations