You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2022/04/29 06:05:56 UTC
[shardingsphere] branch master updated: Refactor DynamicDataSourceStrategy (#17202)
This is an automated email from the ASF dual-hosted git repository.
panjuan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new e57d946adc6 Refactor DynamicDataSourceStrategy (#17202)
e57d946adc6 is described below
commit e57d946adc65ba754f225cb7a2b3de1c61642cf0
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Fri Apr 29 14:05:50 2022 +0800
Refactor DynamicDataSourceStrategy (#17202)
---
.../aware/DatabaseDiscoveryDynamicDataSourceStrategy.java | 8 +-------
.../dbdiscovery/rule/DatabaseDiscoveryRule.java | 2 +-
.../strategy/type/DynamicReadwriteSplittingStrategy.java | 3 +--
.../infra/datasource/strategy/DynamicDataSourceStrategy.java | 12 ++----------
4 files changed, 5 insertions(+), 20 deletions(-)
diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/aware/DatabaseDiscoveryDynamicDataSourceStrategy.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/aware/DatabaseDiscoveryDynamicDataSourceStrategy.java
index 0dd7a58a3fc..ca175d20e26 100644
--- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/aware/DatabaseDiscoveryDynamicDataSourceStrategy.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/aware/DatabaseDiscoveryDynamicDataSourceStrategy.java
@@ -22,7 +22,6 @@ import org.apache.shardingsphere.infra.datasource.strategy.DynamicDataSourceStra
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
import java.util.Collection;
-import java.util.Optional;
/**
* Database discovery dynamic data source strategy.
@@ -32,12 +31,7 @@ public final class DatabaseDiscoveryDynamicDataSourceStrategy implements Dynamic
private DatabaseDiscoveryRule rule;
@Override
- public Optional<ShardingSphereRule> getRule() {
- return Optional.ofNullable(rule);
- }
-
- @Override
- public void setRule(final ShardingSphereRule rule) {
+ public void init(final ShardingSphereRule rule) {
this.rule = (DatabaseDiscoveryRule) rule;
}
diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRule.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRule.java
index a79d9f16da3..a8f24c96d21 100644
--- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRule.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRule.java
@@ -116,7 +116,7 @@ public final class DatabaseDiscoveryRule implements SchemaRule, DataSourceContai
}
private void initAware() {
- DynamicDataSourceStrategyFactory.newInstance().ifPresent(optional -> optional.setRule(this));
+ DynamicDataSourceStrategyFactory.newInstance().ifPresent(optional -> optional.init(this));
}
/**
diff --git a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-core/src/main/java/org/apache/shardingsphere/readwritesplitting/strategy/type/DynamicReadwriteSplittingStrategy.java b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-core/src/main/java/org/apache/shardingsphere/readwritesplitting/strategy/type/DynamicReadwriteSplittingStrategy.java
index dd38d687022..13960979619 100644
--- a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-core/src/main/java/org/apache/shardingsphere/readwritesplitting/strategy/type/DynamicReadwriteSplittingStrategy.java
+++ b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-core/src/main/java/org/apache/shardingsphere/readwritesplitting/strategy/type/DynamicReadwriteSplittingStrategy.java
@@ -24,7 +24,6 @@ import org.apache.shardingsphere.readwritesplitting.strategy.ReadwriteSplittingS
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
@@ -46,7 +45,7 @@ public final class DynamicReadwriteSplittingStrategy implements ReadwriteSplitti
@Override
public List<String> getReadDataSources() {
- return dynamicDataSourceStrategy.getRule().isPresent() ? new ArrayList<>(dynamicDataSourceStrategy.getReplicaDataSourceNames(autoAwareDataSourceName)) : Collections.emptyList();
+ return new ArrayList<>(dynamicDataSourceStrategy.getReplicaDataSourceNames(autoAwareDataSourceName));
}
@Override
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/datasource/strategy/DynamicDataSourceStrategy.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/datasource/strategy/DynamicDataSourceStrategy.java
index 8ba8eb69f46..e76ae8c80d3 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/datasource/strategy/DynamicDataSourceStrategy.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/datasource/strategy/DynamicDataSourceStrategy.java
@@ -22,7 +22,6 @@ import org.apache.shardingsphere.spi.annotation.SingletonSPI;
import org.apache.shardingsphere.spi.type.optional.OptionalSPI;
import java.util.Collection;
-import java.util.Optional;
/**
* Dynamic data source strategy.
@@ -31,18 +30,11 @@ import java.util.Optional;
public interface DynamicDataSourceStrategy extends OptionalSPI {
/**
- * Get rule.
+ * Initialize.
*
- * @return ShardingSphere rule
- */
- Optional<ShardingSphereRule> getRule();
-
- /**
- * Set rule.
- *
* @param rule rule
*/
- void setRule(ShardingSphereRule rule);
+ void init(ShardingSphereRule rule);
/**
* Get primary data source name.