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 2022/05/09 11:16:40 UTC

[shardingsphere] branch master updated: Move getProps() from SPIPostProcessor to ShardingSphereAlgorithm (#17488)

This is an automated email from the ASF dual-hosted git repository.

zhaojinchao 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 d9899877bfe Move getProps() from SPIPostProcessor to ShardingSphereAlgorithm (#17488)
d9899877bfe is described below

commit d9899877bfeb67a89f095e956946af9ffd5fa12a
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Mon May 9 19:16:32 2022 +0800

    Move getProps() from SPIPostProcessor to ShardingSphereAlgorithm (#17488)
---
 .../infra/config/algorithm/ShardingSphereAlgorithm.java          | 9 +++++++++
 .../standalone/fixture/StandalonePersistRepositoryFixture.java   | 5 -----
 .../mode/repository/standalone/file/FileRepository.java          | 5 -----
 .../mode/repository/standalone/h2/H2Repository.java              | 4 ----
 .../apache/shardingsphere/spi/lifecycle/SPIPostProcessor.java    | 7 -------
 .../shardingsphere/spi/type/typed/TypedSPIRegistryTest.java      | 9 +++++----
 .../spi/type/typed/fixture/TypedSPIFixtureImpl.java              | 4 ++--
 7 files changed, 16 insertions(+), 27 deletions(-)

diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/algorithm/ShardingSphereAlgorithm.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/algorithm/ShardingSphereAlgorithm.java
index 0ec2830496a..062758e9b83 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/algorithm/ShardingSphereAlgorithm.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/algorithm/ShardingSphereAlgorithm.java
@@ -20,8 +20,17 @@ package org.apache.shardingsphere.infra.config.algorithm;
 import org.apache.shardingsphere.spi.lifecycle.SPIPostProcessor;
 import org.apache.shardingsphere.spi.type.typed.TypedSPI;
 
+import java.util.Properties;
+
 /**
  * ShardingSphere algorithm.
  */
 public interface ShardingSphereAlgorithm extends TypedSPI, SPIPostProcessor {
+    
+    /**
+     * Get properties.
+     *
+     * @return properties
+     */
+    Properties getProps();
 }
diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/fixture/StandalonePersistRepositoryFixture.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/fixture/StandalonePersistRepositoryFixture.java
index b2d3f84cabf..06d70734672 100644
--- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/fixture/StandalonePersistRepositoryFixture.java
+++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/fixture/StandalonePersistRepositoryFixture.java
@@ -33,11 +33,6 @@ public final class StandalonePersistRepositoryFixture implements StandalonePersi
     public void init(final Properties props) {
     }
     
-    @Override
-    public Properties getProps() {
-        return new Properties();
-    }
-    
     @Override
     public String get(final String key) {
         return persistMap.get(key);
diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-provider/shardingsphere-standalone-mode-repository-file/src/main/java/org/apache/shardingsphere/mode/repository/standalone/file/FileRepository.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-provider/s [...]
index ecae458681a..bbd48a09d70 100644
--- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-provider/shardingsphere-standalone-mode-repository-file/src/main/java/org/apache/shardingsphere/mode/repository/standalone/file/FileRepository.java
+++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-provider/shardingsphere-standalone-mode-repository-file/src/main/java/org/apache/shardingsphere/mode/repository/standalone/file/FileRepository.java
@@ -19,7 +19,6 @@ package org.apache.shardingsphere.mode.repository.standalone.file;
 
 import com.google.common.base.Joiner;
 import com.google.common.base.Strings;
-import lombok.Getter;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.shardingsphere.mode.repository.standalone.StandalonePersistRepository;
 
@@ -44,14 +43,10 @@ public final class FileRepository implements StandalonePersistRepository {
     
     private static final String DEFAULT_PERSIST_DIRECTORY = ".shardingsphere";
     
-    @Getter
-    private Properties props;
-    
     private String path;
     
     @Override
     public void init(final Properties props) {
-        this.props = props;
         FileRepositoryProperties localRepositoryProps = new FileRepositoryProperties(props);
         path = Optional.ofNullable(
                 Strings.emptyToNull(localRepositoryProps.getValue(FileRepositoryPropertyKey.PATH)))
diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-provider/shardingsphere-standalone-mode-repository-h2/src/main/java/org/apache/shardingsphere/mode/repository/standalone/h2/H2Repository.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-provider/shardin [...]
index 182a6e13ad8..93740dd0b0a 100644
--- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-provider/shardingsphere-standalone-mode-repository-h2/src/main/java/org/apache/shardingsphere/mode/repository/standalone/h2/H2Repository.java
+++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-provider/shardingsphere-standalone-mode-repository-h2/src/main/java/org/apache/shardingsphere/mode/repository/standalone/h2/H2Repository.java
@@ -19,7 +19,6 @@ package org.apache.shardingsphere.mode.repository.standalone.h2;
 
 import com.google.common.base.Strings;
 import com.google.common.collect.Lists;
-import lombok.Getter;
 import lombok.SneakyThrows;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.shardingsphere.mode.repository.standalone.StandalonePersistRepository;
@@ -51,9 +50,6 @@ public final class H2Repository implements StandalonePersistRepository {
     
     private static final String SEPARATOR = "/";
     
-    @Getter
-    private Properties props;
-    
     private String jdbcUrl;
     
     private String user;
diff --git a/shardingsphere-spi/src/main/java/org/apache/shardingsphere/spi/lifecycle/SPIPostProcessor.java b/shardingsphere-spi/src/main/java/org/apache/shardingsphere/spi/lifecycle/SPIPostProcessor.java
index d949b8115e6..a5d15771121 100644
--- a/shardingsphere-spi/src/main/java/org/apache/shardingsphere/spi/lifecycle/SPIPostProcessor.java
+++ b/shardingsphere-spi/src/main/java/org/apache/shardingsphere/spi/lifecycle/SPIPostProcessor.java
@@ -30,11 +30,4 @@ public interface SPIPostProcessor {
      * @param props properties to be initialized
      */
     void init(Properties props);
-    
-    /**
-     * Get properties.
-     *
-     * @return properties
-     */
-    Properties getProps();
 }
diff --git a/shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/type/typed/TypedSPIRegistryTest.java b/shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/type/typed/TypedSPIRegistryTest.java
index 70ad3a9d1bb..f7da6fcac48 100644
--- a/shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/type/typed/TypedSPIRegistryTest.java
+++ b/shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/type/typed/TypedSPIRegistryTest.java
@@ -28,6 +28,7 @@ import java.util.Properties;
 import static org.hamcrest.CoreMatchers.instanceOf;
 import static org.hamcrest.CoreMatchers.is;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
 
@@ -56,14 +57,14 @@ public final class TypedSPIRegistryTest {
     public void assertGetRegisteredServiceWithProperties() {
         Properties props = new Properties();
         props.put("key", 1);
-        TypedSPIFixture actual = TypedSPIRegistry.getRegisteredService(TypedSPIFixture.class, "TYPED.FIXTURE", props);
-        assertThat(actual.getProps().getProperty("key"), is("1"));
+        TypedSPIFixtureImpl actual = (TypedSPIFixtureImpl) TypedSPIRegistry.getRegisteredService(TypedSPIFixture.class, "TYPED.FIXTURE", props);
+        assertThat(actual.getValue(), is("1"));
     }
     
     @Test
     public void assertGetRegisteredServiceWithNullProperties() {
-        TypedSPIFixture actual = TypedSPIRegistry.getRegisteredService(TypedSPIFixture.class, "TYPED.FIXTURE", null);
-        assertTrue(actual.getProps().isEmpty());
+        TypedSPIFixtureImpl actual = (TypedSPIFixtureImpl) TypedSPIRegistry.getRegisteredService(TypedSPIFixture.class, "TYPED.FIXTURE", null);
+        assertNull(actual.getValue());
     }
     
     @Test
diff --git a/shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/type/typed/fixture/TypedSPIFixtureImpl.java b/shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/type/typed/fixture/TypedSPIFixtureImpl.java
index 848a04bb514..3cf5409db7e 100644
--- a/shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/type/typed/fixture/TypedSPIFixtureImpl.java
+++ b/shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/type/typed/fixture/TypedSPIFixtureImpl.java
@@ -26,11 +26,11 @@ import java.util.Properties;
 @Getter
 public final class TypedSPIFixtureImpl implements TypedSPIFixture {
     
-    private Properties props;
+    private String value;
     
     @Override
     public void init(final Properties props) {
-        this.props = props;
+        value = props.getProperty("key");
     }
     
     @Override