use of io.shardingjdbc.core.api.config.strategy.ShardingStrategyConfiguration in project sharding-jdbc by shardingjdbc.
the class YamlShardingStrategyConfiguration method build.
/**
* Build sharding strategy configuration.
*
* @return sharding strategy configuration
*/
public ShardingStrategyConfiguration build() {
int shardingStrategyConfigCount = 0;
ShardingStrategyConfiguration result = null;
if (null != standard) {
shardingStrategyConfigCount++;
if (null == standard.getRangeAlgorithmClassName()) {
result = new StandardShardingStrategyConfiguration(standard.getShardingColumn(), ShardingAlgorithmFactory.newInstance(standard.getPreciseAlgorithmClassName(), PreciseShardingAlgorithm.class));
} else {
result = new StandardShardingStrategyConfiguration(standard.getShardingColumn(), ShardingAlgorithmFactory.newInstance(standard.getPreciseAlgorithmClassName(), PreciseShardingAlgorithm.class), ShardingAlgorithmFactory.newInstance(standard.getRangeAlgorithmClassName(), RangeShardingAlgorithm.class));
}
}
if (null != complex) {
shardingStrategyConfigCount++;
result = new ComplexShardingStrategyConfiguration(complex.getShardingColumns(), ShardingAlgorithmFactory.newInstance(complex.getAlgorithmClassName(), ComplexKeysShardingAlgorithm.class));
}
if (null != inline) {
shardingStrategyConfigCount++;
result = new InlineShardingStrategyConfiguration(inline.getShardingColumn(), inline.getAlgorithmExpression());
}
if (null != hint) {
shardingStrategyConfigCount++;
result = new HintShardingStrategyConfiguration(ShardingAlgorithmFactory.newInstance(hint.getAlgorithmClassName(), HintShardingAlgorithm.class));
}
if (null != none) {
shardingStrategyConfigCount++;
result = new NoneShardingStrategyConfiguration();
}
Preconditions.checkArgument(shardingStrategyConfigCount <= 1, "Only allowed 0 or 1 sharding strategy configuration.");
return result;
}
Aggregations