This is an automated email from the ASF dual-hosted git repository.
jianglongtao 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 8f370cc `getAutoAwareDataSources` adds the judgment of whether the
rule exists. (#13993)
8f370cc is described below
commit 8f370cc6c48e66abac001c6fd5b4551a24fadc21
Author: lanchengx <[email protected]>
AuthorDate: Wed Dec 8 16:05:04 2021 +0800
`getAutoAwareDataSources` adds the judgment of whether the rule exists.
(#13993)
* `getAutoAwareDataSources` adds the judgment of whether the rule exists.
* `getAutoAwareDataSources` adds the judgment of whether the rule exists.
* `getAutoAwareDataSources` adds the judgment of whether the rule exists.
---
.../dbdiscovery/aware/DatabaseDiscoveryDataSourceNameAware.java | 6 ++++++
.../readwritesplitting/rule/ReadwriteSplittingDataSourceRule.java | 2 +-
.../apache/shardingsphere/infra/aware/DataSourceNameAware.java | 8 ++++++++
3 files changed, 15 insertions(+), 1 deletion(-)
diff --git
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/aware/DatabaseDiscoveryDataSourceNameAware.java
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/aware/DatabaseDiscoveryDataSourceNameAware.java
index d33ead9..eaf66b3 100644
---
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/aware/DatabaseDiscoveryDataSourceNameAware.java
+++
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/aware/DatabaseDiscoveryDataSourceNameAware.java
@@ -22,6 +22,7 @@ import
org.apache.shardingsphere.infra.aware.DataSourceNameAware;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
import java.util.Collection;
+import java.util.Optional;
/**
* Database discovery data source name aware.
@@ -31,6 +32,11 @@ public final class DatabaseDiscoveryDataSourceNameAware
implements DataSourceNam
private DatabaseDiscoveryRule rule;
@Override
+ public Optional<ShardingSphereRule> getRule() {
+ return Optional.ofNullable(rule);
+ }
+
+ @Override
public void setRule(final ShardingSphereRule rule) {
this.rule = (DatabaseDiscoveryRule) rule;
}
diff --git
a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingDataSourceRule.java
b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingDataSourceRule.java
index df53ac0..ebc23d8 100644
---
a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingDataSourceRule.java
+++
b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingDataSourceRule.java
@@ -125,7 +125,7 @@ public final class ReadwriteSplittingDataSourceRule {
*/
public Map<String, String> getAutoAwareDataSources() {
Optional<DataSourceNameAware> dataSourceNameAware =
DataSourceNameAwareFactory.getInstance().getDataSourceNameAware();
- if (dataSourceNameAware.isPresent()) {
+ if (dataSourceNameAware.isPresent() &&
dataSourceNameAware.get().getRule().isPresent()) {
Map<String, String> result = new HashMap<>(2, 1);
result.put(ReadwriteSplittingRuleConstants.PRIMARY_DATA_SOURCE_NAME,
dataSourceNameAware.get().getPrimaryDataSourceName(autoAwareDataSourceName));
result.put(ReadwriteSplittingRuleConstants.REPLICA_DATA_SOURCE_NAMES,
String.join(",",
dataSourceNameAware.get().getReplicaDataSourceNames(autoAwareDataSourceName)));
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/aware/DataSourceNameAware.java
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/aware/DataSourceNameAware.java
index bc736c9..b01a5c8 100644
---
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/aware/DataSourceNameAware.java
+++
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/aware/DataSourceNameAware.java
@@ -21,6 +21,7 @@ import
org.apache.shardingsphere.infra.rule.ShardingSphereRule;
import org.apache.shardingsphere.spi.optional.OptionalSPI;
import java.util.Collection;
+import java.util.Optional;
/**
* Data source name aware.
@@ -28,6 +29,13 @@ import java.util.Collection;
public interface DataSourceNameAware extends OptionalSPI {
/**
+ * Get rule.
+ *
+ * @return ShardingSphere rule
+ */
+ Optional<ShardingSphereRule> getRule();
+
+ /**
* Set rule.
*
* @param rule rule