Search in sources :

Example 1 with ShardingStrategyConfiguration

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;
}
Also used : YamlStandardShardingStrategyConfiguration(io.shardingjdbc.core.yaml.sharding.strategy.YamlStandardShardingStrategyConfiguration) StandardShardingStrategyConfiguration(io.shardingjdbc.core.api.config.strategy.StandardShardingStrategyConfiguration) YamlNoneShardingStrategyConfiguration(io.shardingjdbc.core.yaml.sharding.strategy.YamlNoneShardingStrategyConfiguration) NoneShardingStrategyConfiguration(io.shardingjdbc.core.api.config.strategy.NoneShardingStrategyConfiguration) ComplexShardingStrategyConfiguration(io.shardingjdbc.core.api.config.strategy.ComplexShardingStrategyConfiguration) YamlComplexShardingStrategyConfiguration(io.shardingjdbc.core.yaml.sharding.strategy.YamlComplexShardingStrategyConfiguration) YamlHintShardingStrategyConfiguration(io.shardingjdbc.core.yaml.sharding.strategy.YamlHintShardingStrategyConfiguration) ComplexShardingStrategyConfiguration(io.shardingjdbc.core.api.config.strategy.ComplexShardingStrategyConfiguration) YamlNoneShardingStrategyConfiguration(io.shardingjdbc.core.yaml.sharding.strategy.YamlNoneShardingStrategyConfiguration) YamlInlineShardingStrategyConfiguration(io.shardingjdbc.core.yaml.sharding.strategy.YamlInlineShardingStrategyConfiguration) YamlStandardShardingStrategyConfiguration(io.shardingjdbc.core.yaml.sharding.strategy.YamlStandardShardingStrategyConfiguration) YamlComplexShardingStrategyConfiguration(io.shardingjdbc.core.yaml.sharding.strategy.YamlComplexShardingStrategyConfiguration) StandardShardingStrategyConfiguration(io.shardingjdbc.core.api.config.strategy.StandardShardingStrategyConfiguration) ShardingStrategyConfiguration(io.shardingjdbc.core.api.config.strategy.ShardingStrategyConfiguration) InlineShardingStrategyConfiguration(io.shardingjdbc.core.api.config.strategy.InlineShardingStrategyConfiguration) NoneShardingStrategyConfiguration(io.shardingjdbc.core.api.config.strategy.NoneShardingStrategyConfiguration) HintShardingStrategyConfiguration(io.shardingjdbc.core.api.config.strategy.HintShardingStrategyConfiguration) YamlInlineShardingStrategyConfiguration(io.shardingjdbc.core.yaml.sharding.strategy.YamlInlineShardingStrategyConfiguration) InlineShardingStrategyConfiguration(io.shardingjdbc.core.api.config.strategy.InlineShardingStrategyConfiguration) YamlHintShardingStrategyConfiguration(io.shardingjdbc.core.yaml.sharding.strategy.YamlHintShardingStrategyConfiguration) HintShardingStrategyConfiguration(io.shardingjdbc.core.api.config.strategy.HintShardingStrategyConfiguration)

Aggregations

ComplexShardingStrategyConfiguration (io.shardingjdbc.core.api.config.strategy.ComplexShardingStrategyConfiguration)1 HintShardingStrategyConfiguration (io.shardingjdbc.core.api.config.strategy.HintShardingStrategyConfiguration)1 InlineShardingStrategyConfiguration (io.shardingjdbc.core.api.config.strategy.InlineShardingStrategyConfiguration)1 NoneShardingStrategyConfiguration (io.shardingjdbc.core.api.config.strategy.NoneShardingStrategyConfiguration)1 ShardingStrategyConfiguration (io.shardingjdbc.core.api.config.strategy.ShardingStrategyConfiguration)1 StandardShardingStrategyConfiguration (io.shardingjdbc.core.api.config.strategy.StandardShardingStrategyConfiguration)1 YamlComplexShardingStrategyConfiguration (io.shardingjdbc.core.yaml.sharding.strategy.YamlComplexShardingStrategyConfiguration)1 YamlHintShardingStrategyConfiguration (io.shardingjdbc.core.yaml.sharding.strategy.YamlHintShardingStrategyConfiguration)1 YamlInlineShardingStrategyConfiguration (io.shardingjdbc.core.yaml.sharding.strategy.YamlInlineShardingStrategyConfiguration)1 YamlNoneShardingStrategyConfiguration (io.shardingjdbc.core.yaml.sharding.strategy.YamlNoneShardingStrategyConfiguration)1 YamlStandardShardingStrategyConfiguration (io.shardingjdbc.core.yaml.sharding.strategy.YamlStandardShardingStrategyConfiguration)1