use of io.shardingjdbc.core.api.algorithm.sharding.ListShardingValue 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.ListShardingValue 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.ListShardingValue 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.ListShardingValue in project sharding-jdbc by shardingjdbc.
the class HintManagerTest method assertAddTableShardingValueForIn.
@Test
public void assertAddTableShardingValueForIn() {
try (HintManager hintManager = HintManager.getInstance()) {
hintManager.addTableShardingValue("logicTable", "shardingColumn", ShardingOperator.IN, 1, 3, 5);
ShardingKey shardingKey = new ShardingKey("logicTable", "shardingColumn");
assertTrue(HintManagerHolder.getTableShardingValue(shardingKey).isPresent());
assertThat(hintManager.getTableShardingValue(shardingKey).getColumnName(), is("shardingColumn"));
assertThat(((ListShardingValue) hintManager.getTableShardingValue(shardingKey)).getValues().size(), is(3));
}
}
use of io.shardingjdbc.core.api.algorithm.sharding.ListShardingValue in project sharding-jdbc by shardingjdbc.
the class HintManagerTest method assertAddDatabaseShardingValueForIn.
@Test
public void assertAddDatabaseShardingValueForIn() {
try (HintManager hintManager = HintManager.getInstance()) {
hintManager.addDatabaseShardingValue("logicTable", "shardingColumn", ShardingOperator.IN, 1, 3, 5);
ShardingKey shardingKey = new ShardingKey("logicTable", "shardingColumn");
assertTrue(HintManagerHolder.getDatabaseShardingValue(shardingKey).isPresent());
assertThat(hintManager.getDatabaseShardingValue(shardingKey).getColumnName(), is("shardingColumn"));
assertThat(((ListShardingValue) hintManager.getDatabaseShardingValue(shardingKey)).getValues().size(), is(3));
}
}
Aggregations