Search in sources :

Example 6 with ShardingValue

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;
}
Also used : RoutingResult(io.shardingjdbc.core.routing.type.RoutingResult) ShardingKey(io.shardingjdbc.core.hint.ShardingKey) ShardingValue(io.shardingjdbc.core.api.algorithm.sharding.ShardingValue) TableUnit(io.shardingjdbc.core.routing.type.TableUnit)

Example 7 with ShardingValue

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);
}
Also used : TableRule(io.shardingjdbc.core.rule.TableRule) DataNode(io.shardingjdbc.core.rule.DataNode) ShardingValue(io.shardingjdbc.core.api.algorithm.sharding.ShardingValue) LinkedList(java.util.LinkedList)

Example 8 with ShardingValue

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));
}
Also used : NoneShardingStrategy(io.shardingjdbc.core.routing.strategy.none.NoneShardingStrategy) PreciseShardingValue(io.shardingjdbc.core.api.algorithm.sharding.PreciseShardingValue) ShardingValue(io.shardingjdbc.core.api.algorithm.sharding.ShardingValue) RangeShardingValue(io.shardingjdbc.core.api.algorithm.sharding.RangeShardingValue) Test(org.junit.Test)

Aggregations

ShardingValue (io.shardingjdbc.core.api.algorithm.sharding.ShardingValue)8 PreciseShardingValue (io.shardingjdbc.core.api.algorithm.sharding.PreciseShardingValue)5 RangeShardingValue (io.shardingjdbc.core.api.algorithm.sharding.RangeShardingValue)5 Test (org.junit.Test)4 ListShardingValue (io.shardingjdbc.core.api.algorithm.sharding.ListShardingValue)3 Collection (java.util.Collection)2 TreeSet (java.util.TreeSet)2 TestComplexKeysShardingAlgorithm (io.shardingjdbc.core.api.algorithm.fixture.TestComplexKeysShardingAlgorithm)1 TestPreciseShardingAlgorithm (io.shardingjdbc.core.api.algorithm.fixture.TestPreciseShardingAlgorithm)1 TestRangeShardingAlgorithm (io.shardingjdbc.core.api.algorithm.fixture.TestRangeShardingAlgorithm)1 ComplexShardingStrategyConfiguration (io.shardingjdbc.core.api.config.strategy.ComplexShardingStrategyConfiguration)1 StandardShardingStrategyConfiguration (io.shardingjdbc.core.api.config.strategy.StandardShardingStrategyConfiguration)1 ShardingKey (io.shardingjdbc.core.hint.ShardingKey)1 SQLExpression (io.shardingjdbc.core.parsing.parser.expression.SQLExpression)1 SQLNumberExpression (io.shardingjdbc.core.parsing.parser.expression.SQLNumberExpression)1 ComplexShardingStrategy (io.shardingjdbc.core.routing.strategy.complex.ComplexShardingStrategy)1 NoneShardingStrategy (io.shardingjdbc.core.routing.strategy.none.NoneShardingStrategy)1 StandardShardingStrategy (io.shardingjdbc.core.routing.strategy.standard.StandardShardingStrategy)1 RoutingResult (io.shardingjdbc.core.routing.type.RoutingResult)1 TableUnit (io.shardingjdbc.core.routing.type.TableUnit)1