use of com.dangdang.ddframe.rdb.sharding.hint.ShardingKey in project sharding-jdbc by dangdangdotcom.
the class HintManager method addDatabaseShardingValue.
/**
* 添加分库分片值.
*
* @param logicTable 逻辑表名称
* @param shardingColumn 分片键
* @param binaryOperator 分片操作符
* @param values 分片值
*/
public void addDatabaseShardingValue(final String logicTable, final String shardingColumn, final Condition.BinaryOperator binaryOperator, final Comparable<?>... values) {
shardingHint = true;
databaseShardingValues.put(new ShardingKey(logicTable, shardingColumn), getShardingValue(logicTable, shardingColumn, binaryOperator, values));
}
use of com.dangdang.ddframe.rdb.sharding.hint.ShardingKey in project sharding-jdbc by dangdangdotcom.
the class HintManagerTest method assertAddDatabaseShardingValueForBetween.
@Test
public void assertAddDatabaseShardingValueForBetween() {
try (HintManager hintManager = HintManager.getInstance()) {
hintManager.addDatabaseShardingValue("logicTable", "shardingColumn", Condition.BinaryOperator.BETWEEN, 1, 10);
ShardingKey shardingKey = new ShardingKey("logicTable", "shardingColumn");
assertTrue(HintManagerHolder.getDatabaseShardingValue(shardingKey).isPresent());
assertThat(hintManager.getDatabaseShardingValue(shardingKey).getColumnName(), is("shardingColumn"));
assertThat(hintManager.getDatabaseShardingValue(shardingKey).getType(), is(ShardingValue.ShardingValueType.RANGE));
assertThat(hintManager.getDatabaseShardingValue(shardingKey).getValueRange().lowerEndpoint(), is((Comparable) 1));
assertThat(hintManager.getDatabaseShardingValue(shardingKey).getValueRange().upperEndpoint(), is((Comparable) 10));
}
}
use of com.dangdang.ddframe.rdb.sharding.hint.ShardingKey in project sharding-jdbc by dangdangdotcom.
the class HintManagerTest method assertAddTableShardingValueForBetween.
@Test
public void assertAddTableShardingValueForBetween() {
try (HintManager hintManager = HintManager.getInstance()) {
hintManager.addTableShardingValue("logicTable", "shardingColumn", Condition.BinaryOperator.BETWEEN, 1, 10);
ShardingKey shardingKey = new ShardingKey("logicTable", "shardingColumn");
assertTrue(HintManagerHolder.getTableShardingValue(shardingKey).isPresent());
assertThat(hintManager.getTableShardingValue(shardingKey).getColumnName(), is("shardingColumn"));
assertThat(hintManager.getTableShardingValue(shardingKey).getType(), is(ShardingValue.ShardingValueType.RANGE));
assertThat(hintManager.getTableShardingValue(shardingKey).getValueRange().lowerEndpoint(), is((Comparable) 1));
assertThat(hintManager.getTableShardingValue(shardingKey).getValueRange().upperEndpoint(), is((Comparable) 10));
}
}
use of com.dangdang.ddframe.rdb.sharding.hint.ShardingKey in project sharding-jdbc by dangdangdotcom.
the class HintManagerTest method assertAddTableShardingValueForEquals.
@Test
public void assertAddTableShardingValueForEquals() {
try (HintManager hintManager = HintManager.getInstance()) {
hintManager.addTableShardingValue("logicTable", "shardingColumn", 1);
ShardingKey shardingKey = new ShardingKey("logicTable", "shardingColumn");
assertTrue(HintManagerHolder.getTableShardingValue(shardingKey).isPresent());
assertThat(hintManager.getTableShardingValue(shardingKey).getColumnName(), is("shardingColumn"));
assertThat(hintManager.getTableShardingValue(shardingKey).getType(), is(ShardingValue.ShardingValueType.SINGLE));
assertThat(hintManager.getTableShardingValue(shardingKey).getValue(), is((Comparable) 1));
}
}
Aggregations