You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2025/08/18 09:27:52 UTC
(shardingsphere) branch master updated: Refactor ShardingSphereYamlRepresenter to TypedSPI (#36340)
This is an automated email from the ASF dual-hosted git repository.
zhangliang 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 851d14e5090 Refactor ShardingSphereYamlRepresenter to TypedSPI (#36340)
851d14e5090 is described below
commit 851d14e5090ec7022cd44f94136032dc3d45d6c9
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Mon Aug 18 17:27:46 2025 +0800
Refactor ShardingSphereYamlRepresenter to TypedSPI (#36340)
* Refactor ShardingSphereYamlRepresenter to TypedSPI
* Refactor ShardingSphereYamlRepresenter to TypedSPI
---
.../util/yaml/representer/ShardingSphereYamlRepresenter.java | 9 +++------
.../representer/processor/ShardingSphereYamlTupleProcessor.java | 9 +++++++--
2 files changed, 10 insertions(+), 8 deletions(-)
diff --git a/infra/util/src/main/java/org/apache/shardingsphere/infra/util/yaml/representer/ShardingSphereYamlRepresenter.java b/infra/util/src/main/java/org/apache/shardingsphere/infra/util/yaml/representer/ShardingSphereYamlRepresenter.java
index 61ac355c5de..8972751a9e2 100644
--- a/infra/util/src/main/java/org/apache/shardingsphere/infra/util/yaml/representer/ShardingSphereYamlRepresenter.java
+++ b/infra/util/src/main/java/org/apache/shardingsphere/infra/util/yaml/representer/ShardingSphereYamlRepresenter.java
@@ -18,6 +18,7 @@
package org.apache.shardingsphere.infra.util.yaml.representer;
import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.infra.util.yaml.representer.processor.DefaultYamlTupleProcessor;
import org.apache.shardingsphere.infra.util.yaml.representer.processor.ShardingSphereYamlTupleProcessor;
import org.apache.shardingsphere.infra.util.yaml.shortcuts.ShardingSphereYamlShortcuts;
@@ -49,12 +50,8 @@ public final class ShardingSphereYamlRepresenter extends Representer {
@Override
protected NodeTuple representJavaBeanProperty(final Object javaBean, final Property property, final Object propertyValue, final Tag customTag) {
NodeTuple nodeTuple = super.representJavaBeanProperty(javaBean, property, propertyValue, customTag);
- for (ShardingSphereYamlTupleProcessor each : ShardingSphereServiceLoader.getServiceInstances(ShardingSphereYamlTupleProcessor.class)) {
- if (property.getName().equals(each.getTupleName())) {
- return each.process(nodeTuple);
- }
- }
- return new DefaultYamlTupleProcessor().process(nodeTuple);
+ return TypedSPILoader.findService(ShardingSphereYamlTupleProcessor.class, property.getName())
+ .map(optional -> optional.process(nodeTuple)).orElse(new DefaultYamlTupleProcessor().process(nodeTuple));
}
@SuppressWarnings({"rawtypes", "unchecked"})
diff --git a/infra/util/src/main/java/org/apache/shardingsphere/infra/util/yaml/representer/processor/ShardingSphereYamlTupleProcessor.java b/infra/util/src/main/java/org/apache/shardingsphere/infra/util/yaml/representer/processor/ShardingSphereYamlTupleProcessor.java
index 31f2afe979d..c91e2bc9833 100644
--- a/infra/util/src/main/java/org/apache/shardingsphere/infra/util/yaml/representer/processor/ShardingSphereYamlTupleProcessor.java
+++ b/infra/util/src/main/java/org/apache/shardingsphere/infra/util/yaml/representer/processor/ShardingSphereYamlTupleProcessor.java
@@ -17,15 +17,15 @@
package org.apache.shardingsphere.infra.util.yaml.representer.processor;
-import org.apache.shardingsphere.infra.spi.ShardingSphereSPI;
import org.apache.shardingsphere.infra.spi.annotation.SingletonSPI;
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPI;
import org.yaml.snakeyaml.nodes.NodeTuple;
/**
* ShardingSphere YAML tuple processor.
*/
@SingletonSPI
-public interface ShardingSphereYamlTupleProcessor extends ShardingSphereSPI {
+public interface ShardingSphereYamlTupleProcessor extends TypedSPI {
/**
* Get tuple name.
@@ -41,4 +41,9 @@ public interface ShardingSphereYamlTupleProcessor extends ShardingSphereSPI {
* @return YAML node tuple after process
*/
NodeTuple process(NodeTuple nodeTuple);
+
+ @Override
+ default String getType() {
+ return getTupleName();
+ }
}