use of io.shardingjdbc.core.api.algorithm.sharding.ShardingValue in project sharding-jdbc by shardingjdbc.
the class InlineShardingStrategy method doSharding.
@Override
public Collection<String> doSharding(final Collection<String> availableTargetNames, final Collection<ShardingValue> shardingValues) {
ShardingValue shardingValue = shardingValues.iterator().next();
Preconditions.checkState(shardingValue instanceof ListShardingValue, "Inline strategy cannot support range sharding.");
Collection<String> shardingResult = doSharding((ListShardingValue) shardingValue);
Collection<String> result = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
result.addAll(shardingResult);
return result;
}
use of io.shardingjdbc.core.api.algorithm.sharding.ShardingValue in project sharding-jdbc by shardingjdbc.
the class StandardShardingStrategy method doSharding.
@Override
public Collection<String> doSharding(final Collection<String> availableTargetNames, final Collection<ShardingValue> shardingValues) {
ShardingValue shardingValue = shardingValues.iterator().next();
Collection<String> shardingResult = shardingValue instanceof ListShardingValue ? doSharding(availableTargetNames, (ListShardingValue) shardingValue) : doSharding(availableTargetNames, (RangeShardingValue) shardingValue);
Collection<String> result = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
result.addAll(shardingResult);
return result;
}
use of io.shardingjdbc.core.api.algorithm.sharding.ShardingValue in project sharding-jdbc by shardingjdbc.
the class ConditionTest method assertGetShardingValue.
@Test
public void assertGetShardingValue() {
Condition condition = new Condition(new Column("test", "test"), new SQLNumberExpression(1));
ShardingValue shardingValue = condition.getShardingValue(Collections.emptyList());
assertThat((Integer) ((ListShardingValue) shardingValue).getValues().iterator().next(), is(1));
condition = new Condition(new Column("test", "test"), Arrays.<SQLExpression>asList(new SQLNumberExpression(1), new SQLNumberExpression(2)));
shardingValue = condition.getShardingValue(Collections.emptyList());
Iterator<?> iterator = ((ListShardingValue) shardingValue).getValues().iterator();
assertThat((Integer) iterator.next(), is(1));
assertThat((Integer) iterator.next(), is(2));
condition = new Condition(new Column("test", "test"), new SQLNumberExpression(1), new SQLNumberExpression(2));
shardingValue = condition.getShardingValue(Collections.emptyList());
assertThat((Integer) ((RangeShardingValue) shardingValue).getValueRange().lowerEndpoint(), is(1));
assertThat((Integer) ((RangeShardingValue) shardingValue).getValueRange().upperEndpoint(), is(2));
}
use of io.shardingjdbc.core.api.algorithm.sharding.ShardingValue in project sharding-jdbc by shardingjdbc.
the class ShardingStrategyTest method assertDoShardingForBetweenSingleKey.
@Test
public void assertDoShardingForBetweenSingleKey() {
StandardShardingStrategy strategy = new StandardShardingStrategy(new StandardShardingStrategyConfiguration("column", new TestPreciseShardingAlgorithm(), new TestRangeShardingAlgorithm()));
assertThat(strategy.doSharding(targets, Collections.<ShardingValue>singletonList(new RangeShardingValue<>("logicTable", "column", Range.open("1", "3")))), is((Collection<String>) Sets.newHashSet("1", "2", "3")));
}
use of io.shardingjdbc.core.api.algorithm.sharding.ShardingValue in project sharding-jdbc by shardingjdbc.
the class ShardingStrategyTest method assertDoShardingForMultipleKeys.
@Test
public void assertDoShardingForMultipleKeys() {
ComplexShardingStrategy strategy = new ComplexShardingStrategy(new ComplexShardingStrategyConfiguration("column", new TestComplexKeysShardingAlgorithm()));
assertThat(strategy.doSharding(targets, Collections.<ShardingValue>singletonList(new PreciseShardingValue<>("logicTable", "column", "1"))), is((Collection<String>) Sets.newHashSet("1", "2", "3")));
}
Aggregations