This is an automated email from the ASF dual-hosted git repository.
duanzhengqiang 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 ca402eb9c34 Reduce repeated calls to DataSourceMapperRuleAttribute
(#31617)
ca402eb9c34 is described below
commit ca402eb9c343fbc5f56e95a5d192cdf16f26af04
Author: ZhangCheng <[email protected]>
AuthorDate: Fri Jun 7 15:05:21 2024 +0800
Reduce repeated calls to DataSourceMapperRuleAttribute (#31617)
---
.../datanode/ReadwriteSplittingDataNodeBuilder.java | 4 +++-
.../apache/shardingsphere/shadow/datanode/ShadowDataNodeBuilder.java | 4 +++-
.../main/java/org/apache/shardingsphere/infra/datanode/DataNodes.java | 3 +--
3 files changed, 7 insertions(+), 4 deletions(-)
diff --git
a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/datanode/ReadwriteSplittingDataNodeBuilder.java
b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/datanode/ReadwriteSplittingDataNodeBuilder.java
index 98a6a3cabe5..35ee19a16bd 100644
---
a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/datanode/ReadwriteSplittingDataNodeBuilder.java
+++
b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/datanode/ReadwriteSplittingDataNodeBuilder.java
@@ -26,6 +26,7 @@ import
org.apache.shardingsphere.readwritesplitting.rule.ReadwriteSplittingRule;
import java.util.Collection;
import java.util.LinkedList;
+import java.util.Map;
/**
* Readwrite-splitting data node builder.
@@ -35,8 +36,9 @@ public final class ReadwriteSplittingDataNodeBuilder
implements DataNodeBuilder<
@Override
public Collection<DataNode> build(final Collection<DataNode> dataNodes,
final ReadwriteSplittingRule rule) {
Collection<DataNode> result = new LinkedList<>();
+ Map<String, Collection<String>> dataSourceMapper =
rule.getAttributes().getAttribute(DataSourceMapperRuleAttribute.class).getDataSourceMapper();
for (DataNode each : dataNodes) {
- result.addAll(DataNodeUtils.buildDataNode(each,
rule.getAttributes().getAttribute(DataSourceMapperRuleAttribute.class).getDataSourceMapper()));
+ result.addAll(DataNodeUtils.buildDataNode(each, dataSourceMapper));
}
return result;
}
diff --git
a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/datanode/ShadowDataNodeBuilder.java
b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/datanode/ShadowDataNodeBuilder.java
index ffbd8fe6ebd..bbd0e9e642d 100644
---
a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/datanode/ShadowDataNodeBuilder.java
+++
b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/datanode/ShadowDataNodeBuilder.java
@@ -26,6 +26,7 @@ import org.apache.shardingsphere.shadow.rule.ShadowRule;
import java.util.Collection;
import java.util.LinkedList;
+import java.util.Map;
/**
* Shadow data node builder.
@@ -35,8 +36,9 @@ public final class ShadowDataNodeBuilder implements
DataNodeBuilder<ShadowRule>
@Override
public Collection<DataNode> build(final Collection<DataNode> dataNodes,
final ShadowRule rule) {
Collection<DataNode> result = new LinkedList<>();
+ Map<String, Collection<String>> dataSourceMapper =
rule.getAttributes().getAttribute(DataSourceMapperRuleAttribute.class).getDataSourceMapper();
for (DataNode each : dataNodes) {
- result.addAll(DataNodeUtils.buildDataNode(each,
rule.getAttributes().getAttribute(DataSourceMapperRuleAttribute.class).getDataSourceMapper()));
+ result.addAll(DataNodeUtils.buildDataNode(each, dataSourceMapper));
}
return result;
}
diff --git
a/infra/common/src/main/java/org/apache/shardingsphere/infra/datanode/DataNodes.java
b/infra/common/src/main/java/org/apache/shardingsphere/infra/datanode/DataNodes.java
index 0e130720b51..453b52e019b 100644
---
a/infra/common/src/main/java/org/apache/shardingsphere/infra/datanode/DataNodes.java
+++
b/infra/common/src/main/java/org/apache/shardingsphere/infra/datanode/DataNodes.java
@@ -22,7 +22,6 @@ import
org.apache.shardingsphere.infra.rule.ShardingSphereRule;
import
org.apache.shardingsphere.infra.rule.attribute.datanode.DataNodeRuleAttribute;
import org.apache.shardingsphere.infra.spi.type.ordered.OrderedSPILoader;
-import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
@@ -66,7 +65,7 @@ public final class DataNodes {
for (ShardingSphereRule each : rules) {
Collection<DataNode> dataNodes = getDataNodesByTableName(each,
tableName);
if (!dataNodes.isEmpty()) {
- return new ArrayList<>(dataNodes);
+ return Collections.unmodifiableCollection(dataNodes);
}
}
return Collections.emptyList();