use of io.shardingjdbc.core.integrate.fixture.RangeModuloTableShardingAlgorithm in project sharding-jdbc by shardingjdbc.
the class AbstractShardingDatabaseAndTableTest method getDataSources.
@Override
protected final 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>> entry : dataSourceMap.entrySet()) {
ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
shardingRuleConfig.setDefaultDataSourceName("dataSource_dbtbl_0");
TableRuleConfiguration orderTableRuleConfig = new TableRuleConfiguration();
orderTableRuleConfig.setLogicTable("t_order");
orderTableRuleConfig.setLogicIndex("t_order_index");
List<String> orderActualDataNodes = new LinkedList<>();
for (String dataSourceName : entry.getValue().keySet()) {
orderActualDataNodes.add(dataSourceName + ".t_order_${0..9}");
}
orderTableRuleConfig.setActualDataNodes(Joiner.on(",").join(orderActualDataNodes));
shardingRuleConfig.getTableRuleConfigs().add(orderTableRuleConfig);
TableRuleConfiguration orderItemTableRuleConfig = new TableRuleConfiguration();
orderItemTableRuleConfig.setLogicTable("t_order_item");
List<String> orderItemActualDataNodes = new LinkedList<>();
for (String dataSourceName : entry.getValue().keySet()) {
orderItemActualDataNodes.add(dataSourceName + ".t_order_item_${0..9}");
}
orderItemTableRuleConfig.setActualDataNodes(Joiner.on(",").join(orderItemActualDataNodes));
shardingRuleConfig.getTableRuleConfigs().add(orderItemTableRuleConfig);
TableRuleConfiguration configTableRuleConfig = new TableRuleConfiguration();
configTableRuleConfig.setLogicTable("t_config");
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(configTableRuleConfig);
shardingRuleConfig.getBindingTableGroups().add("t_order, t_order_item");
shardingRuleConfig.setDefaultTableShardingStrategyConfig(new StandardShardingStrategyConfiguration("order_id", new PreciseModuloTableShardingAlgorithm(), new RangeModuloTableShardingAlgorithm()));
shardingRuleConfig.setDefaultDatabaseShardingStrategyConfig(new StandardShardingStrategyConfiguration("user_id", new PreciseModuloDatabaseShardingAlgorithm(), new RangeModuloDatabaseShardingAlgorithm()));
getShardingDataSources().put(entry.getKey(), new ShardingDataSource(entry.getValue(), new ShardingRule(shardingRuleConfig, entry.getValue().keySet())));
}
return getShardingDataSources();
}
use of io.shardingjdbc.core.integrate.fixture.RangeModuloTableShardingAlgorithm in project sharding-jdbc by shardingjdbc.
the class AbstractShardingTableOnlyTest method getDataSources.
@Override
protected final 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>> entry : dataSourceMap.entrySet()) {
final ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
TableRuleConfiguration orderTableRuleConfig = new TableRuleConfiguration();
orderTableRuleConfig.setLogicTable("t_order");
orderTableRuleConfig.setLogicIndex("t_order_index");
List<String> orderActualDataNodes = new LinkedList<>();
for (String dataSourceName : entry.getValue().keySet()) {
orderActualDataNodes.add(dataSourceName + ".t_order_${0..9}");
}
orderTableRuleConfig.setActualDataNodes(Joiner.on(",").join(orderActualDataNodes));
shardingRuleConfig.getTableRuleConfigs().add(orderTableRuleConfig);
TableRuleConfiguration orderItemTableRuleConfig = new TableRuleConfiguration();
List<String> orderItemActualDataNodes = new LinkedList<>();
for (String dataSourceName : entry.getValue().keySet()) {
orderItemActualDataNodes.add(dataSourceName + ".t_order_item_${0..9}");
}
orderItemTableRuleConfig.setActualDataNodes(Joiner.on(",").join(orderItemActualDataNodes));
orderItemTableRuleConfig.setLogicTable("t_order_item");
orderItemTableRuleConfig.setKeyGeneratorColumnName("item_id");
shardingRuleConfig.getTableRuleConfigs().add(orderItemTableRuleConfig);
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.getBindingTableGroups().add("t_order, t_order_item");
shardingRuleConfig.setDefaultDatabaseShardingStrategyConfig(new NoneShardingStrategyConfiguration());
shardingRuleConfig.setDefaultTableShardingStrategyConfig(new StandardShardingStrategyConfiguration("order_id", new PreciseModuloTableShardingAlgorithm(), new RangeModuloTableShardingAlgorithm()));
getShardingDataSources().put(entry.getKey(), new ShardingDataSource(entry.getValue(), new ShardingRule(shardingRuleConfig, entry.getValue().keySet())));
}
return getShardingDataSources();
}
Aggregations