use of io.shardingjdbc.core.api.config.TableRuleConfiguration in project sharding-jdbc by shardingjdbc.
the class ShardingDataSourceTest method createShardingRuleConfig.
private ShardingRuleConfiguration createShardingRuleConfig(final Map<String, DataSource> dataSourceMap) {
final ShardingRuleConfiguration result = new ShardingRuleConfiguration();
TableRuleConfiguration tableRuleConfig = new TableRuleConfiguration();
tableRuleConfig.setLogicTable("logicTable");
List<String> orderActualDataNodes = new LinkedList<>();
for (String each : dataSourceMap.keySet()) {
orderActualDataNodes.add(each + ".table_${0..2}");
}
tableRuleConfig.setActualDataNodes(Joiner.on(",").join(orderActualDataNodes));
result.getTableRuleConfigs().add(tableRuleConfig);
return result;
}
use of io.shardingjdbc.core.api.config.TableRuleConfiguration in project sharding-jdbc by shardingjdbc.
the class YamlTableRuleConfiguration method build.
/**
* Build table rule configuration.
*
* @return table rule configuration
*/
public TableRuleConfiguration build() {
Preconditions.checkNotNull(logicTable, "Logic table cannot be null.");
TableRuleConfiguration result = new TableRuleConfiguration();
result.setLogicTable(logicTable);
result.setActualDataNodes(actualDataNodes);
if (null != databaseStrategy) {
result.setDatabaseShardingStrategyConfig(databaseStrategy.build());
}
if (null != tableStrategy) {
result.setTableShardingStrategyConfig(tableStrategy.build());
}
if (!Strings.isNullOrEmpty(keyGeneratorClass)) {
result.setKeyGenerator(KeyGeneratorFactory.newInstance(keyGeneratorClass));
}
result.setKeyGeneratorColumnName(keyGeneratorColumnName);
result.setLogicIndex(logicIndex);
return result;
}
use of io.shardingjdbc.core.api.config.TableRuleConfiguration in project sharding-jdbc by shardingjdbc.
the class ShardingDataSourceFactoryTest method createShardingRuleConfig.
private ShardingRuleConfiguration createShardingRuleConfig() {
ShardingRuleConfiguration result = new ShardingRuleConfiguration();
TableRuleConfiguration tableRuleConfig = new TableRuleConfiguration();
tableRuleConfig.setLogicTable("logicTable");
tableRuleConfig.setActualDataNodes("ds.table_${0..2}");
result.getTableRuleConfigs().add(tableRuleConfig);
return result;
}
use of io.shardingjdbc.core.api.config.TableRuleConfiguration in project sharding-jdbc by shardingjdbc.
the class AbstractShardingDatabaseOnlyWithHintTest method getShardingRule.
@Override
protected ShardingRule getShardingRule(final Map.Entry<DatabaseType, Map<String, DataSource>> dataSourceEntry) {
ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
TableRuleConfiguration orderTableRuleConfig = new TableRuleConfiguration();
orderTableRuleConfig.setLogicTable("t_order");
shardingRuleConfig.getTableRuleConfigs().add(orderTableRuleConfig);
TableRuleConfiguration orderItemTableRuleConfig = new TableRuleConfiguration();
orderItemTableRuleConfig.setLogicTable("t_order_item");
shardingRuleConfig.getTableRuleConfigs().add(orderItemTableRuleConfig);
shardingRuleConfig.getBindingTableGroups().add("t_order, t_order_item");
shardingRuleConfig.setDefaultDatabaseShardingStrategyConfig(new ComplexShardingStrategyConfiguration("user_id", new ComplexKeysModuloDatabaseShardingAlgorithm()));
shardingRuleConfig.setDefaultTableShardingStrategyConfig(new NoneShardingStrategyConfiguration());
return new ShardingRule(shardingRuleConfig, dataSourceEntry.getValue().keySet());
}
use of io.shardingjdbc.core.api.config.TableRuleConfiguration in project sharding-jdbc by shardingjdbc.
the class AbstractShardingDatabaseOnlyTest method getDataSources.
@Override
protected Map<DatabaseType, ShardingDataSource> getDataSources() throws SQLException {
if (!getShardingDataSources().isEmpty()) {
return getShardingDataSources();
}
Map<DatabaseType, Map<String, DataSource>> dataSourceMap = createDataSourceMap();
for (Map.Entry<DatabaseType, Map<String, DataSource>> each : dataSourceMap.entrySet()) {
final ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
TableRuleConfiguration orderTableRuleConfig = new TableRuleConfiguration();
orderTableRuleConfig.setLogicTable("t_order");
orderTableRuleConfig.setLogicIndex("t_order_index");
orderTableRuleConfig.setKeyGeneratorColumnName("order_id");
orderTableRuleConfig.setKeyGenerator(new IncrementKeyGenerator());
shardingRuleConfig.getTableRuleConfigs().add(orderTableRuleConfig);
TableRuleConfiguration orderItemTableRuleConfig = new TableRuleConfiguration();
orderItemTableRuleConfig.setLogicTable("t_order_item");
TableRuleConfiguration logTableRuleConfig = new TableRuleConfiguration();
logTableRuleConfig.setLogicIndex("t_log_index");
logTableRuleConfig.setLogicTable("t_log");
TableRuleConfiguration tempLogTableRuleConfig = new TableRuleConfiguration();
tempLogTableRuleConfig.setLogicTable("t_temp_log");
shardingRuleConfig.getTableRuleConfigs().add(logTableRuleConfig);
shardingRuleConfig.getTableRuleConfigs().add(tempLogTableRuleConfig);
shardingRuleConfig.getTableRuleConfigs().add(orderItemTableRuleConfig);
shardingRuleConfig.getBindingTableGroups().add("t_order, t_order_item");
shardingRuleConfig.setDefaultDatabaseShardingStrategyConfig(new ComplexShardingStrategyConfiguration("user_id", new ComplexKeysModuloDatabaseShardingAlgorithm()));
shardingRuleConfig.setDefaultTableShardingStrategyConfig(new NoneShardingStrategyConfiguration());
getShardingDataSources().put(each.getKey(), new ShardingDataSource(each.getValue(), new ShardingRule(shardingRuleConfig, each.getValue().keySet())));
}
return getShardingDataSources();
}
Aggregations