use of io.shardingjdbc.core.api.algorithm.sharding.RangeShardingValue in project sharding-jdbc by shardingjdbc.
the class HintManagerTest method assertAddTableShardingValueForBetween.
@Test
public void assertAddTableShardingValueForBetween() {
try (HintManager hintManager = HintManager.getInstance()) {
hintManager.addTableShardingValue("logicTable", "shardingColumn", ShardingOperator.BETWEEN, 1, 10);
ShardingKey shardingKey = new ShardingKey("logicTable", "shardingColumn");
assertTrue(HintManagerHolder.getTableShardingValue(shardingKey).isPresent());
assertThat(hintManager.getTableShardingValue(shardingKey).getColumnName(), is("shardingColumn"));
assertThat(((RangeShardingValue) hintManager.getTableShardingValue(shardingKey)).getValueRange().lowerEndpoint(), is((Comparable) 1));
assertThat(((RangeShardingValue) hintManager.getTableShardingValue(shardingKey)).getValueRange().upperEndpoint(), is((Comparable) 10));
}
}
use of io.shardingjdbc.core.api.algorithm.sharding.RangeShardingValue in project sharding-jdbc by shardingjdbc.
the class HintManagerTest method assertAddDatabaseShardingValueForBetween.
@Test
public void assertAddDatabaseShardingValueForBetween() {
try (HintManager hintManager = HintManager.getInstance()) {
hintManager.addDatabaseShardingValue("logicTable", "shardingColumn", ShardingOperator.BETWEEN, 1, 10);
ShardingKey shardingKey = new ShardingKey("logicTable", "shardingColumn");
assertTrue(HintManagerHolder.getDatabaseShardingValue(shardingKey).isPresent());
assertThat(hintManager.getDatabaseShardingValue(shardingKey).getColumnName(), is("shardingColumn"));
assertThat(((RangeShardingValue) hintManager.getDatabaseShardingValue(shardingKey)).getValueRange().lowerEndpoint(), is((Comparable) 1));
assertThat(((RangeShardingValue) hintManager.getDatabaseShardingValue(shardingKey)).getValueRange().upperEndpoint(), is((Comparable) 10));
}
}
use of io.shardingjdbc.core.api.algorithm.sharding.RangeShardingValue 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.RangeShardingValue in project sharding-jdbc by shardingjdbc.
the class DeleteStatementParserTest method assertDeleteStatementWithoutParameter.
private void assertDeleteStatementWithoutParameter(final DMLStatement deleteStatement) {
assertThat(deleteStatement.getTables().find("TABLE_XXX").get().getName(), is("TABLE_XXX"));
assertThat(deleteStatement.getTables().find("xxx").get().getAlias().get(), is("xxx"));
Condition condition1 = deleteStatement.getConditions().find(new Column("field1", "TABLE_XXX")).get();
assertThat(condition1.getOperator(), is(ShardingOperator.EQUAL));
assertThat(((ListShardingValue) condition1.getShardingValue(Collections.emptyList())).getValues().iterator().next(), is((Object) 1));
Condition condition2 = deleteStatement.getConditions().find(new Column("field2", "TABLE_XXX")).get();
assertThat(condition2.getOperator(), is(ShardingOperator.IN));
Iterator<?> shardingValues2 = ((ListShardingValue) condition2.getShardingValue(Collections.emptyList())).getValues().iterator();
assertThat(shardingValues2.next(), is((Object) 1));
assertThat(shardingValues2.next(), is((Object) 3));
assertFalse(shardingValues2.hasNext());
Condition condition3 = deleteStatement.getConditions().find(new Column("field3", "TABLE_XXX")).get();
assertThat(condition3.getOperator(), is(ShardingOperator.BETWEEN));
Range shardingValues3 = ((RangeShardingValue) condition3.getShardingValue(Collections.emptyList())).getValueRange();
assertThat(shardingValues3.lowerEndpoint(), is((Comparable) 5));
assertThat(shardingValues3.upperEndpoint(), is((Comparable) 20));
}
Aggregations