Search in sources :

Example 1 with SingleKeyShardingAlgorithm

use of com.dangdang.ddframe.rdb.sharding.router.strategy.SingleKeyShardingAlgorithm in project sharding-jdbc by dangdangdotcom.

the class ShardingRuleBuilder method buildShardingAlgorithmClassName.

@SuppressWarnings("unchecked")
private <T extends ShardingStrategy> T buildShardingAlgorithmClassName(final List<String> shardingColumns, final String algorithmClassName, final Class<T> returnClass) {
    ShardingAlgorithm shardingAlgorithm;
    try {
        shardingAlgorithm = (ShardingAlgorithm) Class.forName(algorithmClassName).newInstance();
    } catch (final InstantiationException | IllegalAccessException | ClassNotFoundException ex) {
        throw new IllegalArgumentException(ex);
    }
    Preconditions.checkState(shardingAlgorithm instanceof SingleKeyShardingAlgorithm || shardingAlgorithm instanceof MultipleKeysShardingAlgorithm, "Sharding-JDBC: algorithmClassName is illegal");
    if (shardingAlgorithm instanceof SingleKeyShardingAlgorithm) {
        Preconditions.checkArgument(1 == shardingColumns.size(), "Sharding-JDBC: SingleKeyShardingAlgorithm must have only ONE sharding column");
        return returnClass.isAssignableFrom(DatabaseShardingStrategy.class) ? (T) new DatabaseShardingStrategy(shardingColumns.get(0), (SingleKeyDatabaseShardingAlgorithm<?>) shardingAlgorithm) : (T) new TableShardingStrategy(shardingColumns.get(0), (SingleKeyTableShardingAlgorithm<?>) shardingAlgorithm);
    }
    return returnClass.isAssignableFrom(DatabaseShardingStrategy.class) ? (T) new DatabaseShardingStrategy(shardingColumns, (MultipleKeysDatabaseShardingAlgorithm) shardingAlgorithm) : (T) new TableShardingStrategy(shardingColumns, (MultipleKeysTableShardingAlgorithm) shardingAlgorithm);
}
Also used : SingleKeyDatabaseShardingAlgorithm(com.dangdang.ddframe.rdb.sharding.api.strategy.database.SingleKeyDatabaseShardingAlgorithm) ShardingAlgorithm(com.dangdang.ddframe.rdb.sharding.router.strategy.ShardingAlgorithm) MultipleKeysDatabaseShardingAlgorithm(com.dangdang.ddframe.rdb.sharding.api.strategy.database.MultipleKeysDatabaseShardingAlgorithm) MultipleKeysTableShardingAlgorithm(com.dangdang.ddframe.rdb.sharding.api.strategy.table.MultipleKeysTableShardingAlgorithm) ClosureTableShardingAlgorithm(com.dangdang.ddframe.rdb.sharding.config.common.internal.algorithm.ClosureTableShardingAlgorithm) SingleKeyTableShardingAlgorithm(com.dangdang.ddframe.rdb.sharding.api.strategy.table.SingleKeyTableShardingAlgorithm) SingleKeyShardingAlgorithm(com.dangdang.ddframe.rdb.sharding.router.strategy.SingleKeyShardingAlgorithm) MultipleKeysShardingAlgorithm(com.dangdang.ddframe.rdb.sharding.router.strategy.MultipleKeysShardingAlgorithm) ClosureDatabaseShardingAlgorithm(com.dangdang.ddframe.rdb.sharding.config.common.internal.algorithm.ClosureDatabaseShardingAlgorithm) DatabaseShardingStrategy(com.dangdang.ddframe.rdb.sharding.api.strategy.database.DatabaseShardingStrategy) MultipleKeysShardingAlgorithm(com.dangdang.ddframe.rdb.sharding.router.strategy.MultipleKeysShardingAlgorithm) TableShardingStrategy(com.dangdang.ddframe.rdb.sharding.api.strategy.table.TableShardingStrategy) SingleKeyShardingAlgorithm(com.dangdang.ddframe.rdb.sharding.router.strategy.SingleKeyShardingAlgorithm)

Aggregations

DatabaseShardingStrategy (com.dangdang.ddframe.rdb.sharding.api.strategy.database.DatabaseShardingStrategy)1 MultipleKeysDatabaseShardingAlgorithm (com.dangdang.ddframe.rdb.sharding.api.strategy.database.MultipleKeysDatabaseShardingAlgorithm)1 SingleKeyDatabaseShardingAlgorithm (com.dangdang.ddframe.rdb.sharding.api.strategy.database.SingleKeyDatabaseShardingAlgorithm)1 MultipleKeysTableShardingAlgorithm (com.dangdang.ddframe.rdb.sharding.api.strategy.table.MultipleKeysTableShardingAlgorithm)1 SingleKeyTableShardingAlgorithm (com.dangdang.ddframe.rdb.sharding.api.strategy.table.SingleKeyTableShardingAlgorithm)1 TableShardingStrategy (com.dangdang.ddframe.rdb.sharding.api.strategy.table.TableShardingStrategy)1 ClosureDatabaseShardingAlgorithm (com.dangdang.ddframe.rdb.sharding.config.common.internal.algorithm.ClosureDatabaseShardingAlgorithm)1 ClosureTableShardingAlgorithm (com.dangdang.ddframe.rdb.sharding.config.common.internal.algorithm.ClosureTableShardingAlgorithm)1 MultipleKeysShardingAlgorithm (com.dangdang.ddframe.rdb.sharding.router.strategy.MultipleKeysShardingAlgorithm)1 ShardingAlgorithm (com.dangdang.ddframe.rdb.sharding.router.strategy.ShardingAlgorithm)1 SingleKeyShardingAlgorithm (com.dangdang.ddframe.rdb.sharding.router.strategy.SingleKeyShardingAlgorithm)1