use of io.shardingjdbc.core.api.algorithm.sharding.ShardingValue in project sharding-jdbc by shardingjdbc.
the class DatabaseHintRoutingEngine method route.
@Override
public RoutingResult route() {
Optional<ShardingValue> shardingValue = HintManagerHolder.getDatabaseShardingValue(new ShardingKey(HintManagerHolder.DB_TABLE_NAME, HintManagerHolder.DB_COLUMN_NAME));
Preconditions.checkState(shardingValue.isPresent());
log.debug("Before database sharding only db:{} sharding values: {}", dataSourceNames, shardingValue.get());
Collection<String> routingDataSources;
routingDataSources = databaseShardingStrategy.doSharding(dataSourceNames, Collections.singletonList(shardingValue.get()));
Preconditions.checkState(!routingDataSources.isEmpty(), "no database route info");
log.debug("After database sharding only result: {}", routingDataSources);
RoutingResult result = new RoutingResult();
for (String each : routingDataSources) {
result.getTableUnits().getTableUnits().add(new TableUnit(each, "", ""));
}
return result;
}
use of io.shardingjdbc.core.api.algorithm.sharding.ShardingValue in project sharding-jdbc by shardingjdbc.
the class StandardRoutingEngine method route.
@Override
public RoutingResult route() {
TableRule tableRule = shardingRule.getTableRule(logicTableName);
List<ShardingValue> databaseShardingValues = getDatabaseShardingValues(tableRule);
List<ShardingValue> tableShardingValues = getTableShardingValues(tableRule);
Collection<String> routedDataSources = routeDataSources(tableRule, databaseShardingValues);
Collection<DataNode> routedDataNodes = new LinkedList<>();
for (String each : routedDataSources) {
routedDataNodes.addAll(routeTables(tableRule, each, tableShardingValues));
}
return generateRoutingResult(routedDataNodes);
}
use of io.shardingjdbc.core.api.algorithm.sharding.ShardingValue in project sharding-jdbc by shardingjdbc.
the class ShardingStrategyTest method assertDoShardingWithoutShardingColumns.
@Test
public void assertDoShardingWithoutShardingColumns() {
NoneShardingStrategy strategy = new NoneShardingStrategy();
assertThat(strategy.doSharding(targets, Collections.<ShardingValue>emptySet()), is(targets));
}
Aggregations