use of io.shardingjdbc.core.hint.ShardingKey in project sharding-jdbc by shardingjdbc.
the class HintManager method addTableShardingValue.
/**
* Add sharding value for table.
*
* @param logicTable logic table name
* @param shardingColumn sharding column name
* @param operator sharding operator
* @param values sharding value
*/
public void addTableShardingValue(final String logicTable, final String shardingColumn, final ShardingOperator operator, final Comparable<?>... values) {
shardingHint = true;
tableShardingValues.put(new ShardingKey(logicTable, shardingColumn), getShardingValue(logicTable, shardingColumn, operator, values));
}
use of io.shardingjdbc.core.hint.ShardingKey in project sharding-jdbc by shardingjdbc.
the class HintManager method addDatabaseShardingValue.
/**
* Add sharding value for database.
*
* @param logicTable logic table name
* @param shardingColumn sharding column name
* @param operator sharding operator
* @param values sharding value
*/
public void addDatabaseShardingValue(final String logicTable, final String shardingColumn, final ShardingOperator operator, final Comparable<?>... values) {
shardingHint = true;
databaseShardingValues.put(new ShardingKey(logicTable, shardingColumn), getShardingValue(logicTable, shardingColumn, operator, values));
}
use of io.shardingjdbc.core.hint.ShardingKey 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;
}
use of io.shardingjdbc.core.hint.ShardingKey in project sharding-jdbc by shardingjdbc.
the class HintManagerTest method assertAddTableShardingValueForEquals.
@SuppressWarnings("unchecked")
@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(((ListShardingValue<? extends Comparable>) hintManager.getTableShardingValue(shardingKey)).getValues().iterator().next(), is((Comparable) 1));
}
}
Aggregations