diff --git a/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/api/MasterSlaveDataSourceFactory.java b/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/api/MasterSlaveDataSourceFactory.java index f926afffdd101..3ed67bf2dd2cc 100644 --- a/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/api/MasterSlaveDataSourceFactory.java +++ b/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/api/MasterSlaveDataSourceFactory.java @@ -35,13 +35,13 @@ public final class MasterSlaveDataSourceFactory { /** * 创建读写分离数据源. * - * @param logicDataSourceName 逻辑数据源名称 + * @param name 读写分离数据源名称 * @param masterDataSource 主节点数据源 * @param slaveDataSource 从节点数据源 * @param otherSlaveDataSources 其他从节点数据源 * @return 读写分离数据源 */ - public static DataSource createDataSource(final String logicDataSourceName, final DataSource masterDataSource, final DataSource slaveDataSource, final DataSource... otherSlaveDataSources) { - return new MasterSlaveDataSource(logicDataSourceName, masterDataSource, Lists.asList(slaveDataSource, otherSlaveDataSources)); + public static DataSource createDataSource(final String name, final DataSource masterDataSource, final DataSource slaveDataSource, final DataSource... otherSlaveDataSources) { + return new MasterSlaveDataSource(name, masterDataSource, Lists.asList(slaveDataSource, otherSlaveDataSources)); } } diff --git a/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/api/strategy/slave/RoundRobinSlaveLoadBalanceStrategy.java b/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/api/strategy/slave/RoundRobinSlaveLoadBalanceStrategy.java index a601cd8a0e2b7..2f5978ea55a76 100644 --- a/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/api/strategy/slave/RoundRobinSlaveLoadBalanceStrategy.java +++ b/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/api/strategy/slave/RoundRobinSlaveLoadBalanceStrategy.java @@ -32,9 +32,9 @@ public final class RoundRobinSlaveLoadBalanceStrategy implements SlaveLoadBalanc private static final ConcurrentHashMap COUNT_MAP = new ConcurrentHashMap<>(); @Override - public DataSource getDataSource(final String logicDataSource, final List slaveDataSources) { - AtomicInteger count = COUNT_MAP.containsKey(logicDataSource) ? COUNT_MAP.get(logicDataSource) : new AtomicInteger(0); - COUNT_MAP.putIfAbsent(logicDataSource, count); + public DataSource getDataSource(final String name, final List slaveDataSources) { + AtomicInteger count = COUNT_MAP.containsKey(name) ? COUNT_MAP.get(name) : new AtomicInteger(0); + COUNT_MAP.putIfAbsent(name, count); count.compareAndSet(slaveDataSources.size(), 0); return slaveDataSources.get(count.getAndIncrement() % slaveDataSources.size()); } diff --git a/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/api/strategy/slave/SlaveLoadBalanceStrategy.java b/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/api/strategy/slave/SlaveLoadBalanceStrategy.java index 88a1076164b27..8180f68e2208e 100644 --- a/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/api/strategy/slave/SlaveLoadBalanceStrategy.java +++ b/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/api/strategy/slave/SlaveLoadBalanceStrategy.java @@ -30,9 +30,9 @@ public interface SlaveLoadBalanceStrategy { /** * 根据负载均衡策略获取从库数据源. * - * @param logicDataSource 逻辑数据源名称 + * @param name 读写分离数据源名称 * @param slaveDataSources 从库数据源列表 * @return 选中的从库数据源 */ - DataSource getDataSource(final String logicDataSource, final List slaveDataSources); + DataSource getDataSource(final String name, final List slaveDataSources); } diff --git a/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/jdbc/MasterSlaveDataSource.java b/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/jdbc/MasterSlaveDataSource.java index 75236074de6cd..d949c0612cd0f 100644 --- a/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/jdbc/MasterSlaveDataSource.java +++ b/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/jdbc/MasterSlaveDataSource.java @@ -45,7 +45,7 @@ protected Boolean initialValue() { } }; - private final String logicDataSourceName; + private final String name; private final DataSource masterDataSource; @@ -64,7 +64,7 @@ public DataSource getDataSource(final SQLStatementType sqlStatementType) { WAS_UPDATED.set(true); return masterDataSource; } - return slaveLoadBalanceStrategy.getDataSource(logicDataSourceName, slaveDataSources); + return slaveLoadBalanceStrategy.getDataSource(name, slaveDataSources); } String getDatabaseProductName() throws SQLException {