You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by du...@apache.org on 2022/04/15 14:30:35 UTC
[shardingsphere] branch master updated: Rename SingleTableDataCalculatorRegistry to SingleTableDataCalculatorFactory (#16870)
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 f0207cc5ed6 Rename SingleTableDataCalculatorRegistry to SingleTableDataCalculatorFactory (#16870)
f0207cc5ed6 is described below
commit f0207cc5ed6a10e142518a9706a379b6c24726d1
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Fri Apr 15 22:30:28 2022 +0800
Rename SingleTableDataCalculatorRegistry to SingleTableDataCalculatorFactory (#16870)
* Refactor SingleTableDataCalculator
* Rename SingleTableDataCalculatorRegistry
---
....java => SingleTableDataCalculatorFactory.java} | 7 ++--
.../AbstractDataConsistencyCheckAlgorithm.java | 4 +--
.../AbstractSingleTableDataCalculator.java | 14 +++-----
.../consistency/SingleTableDataCalculator.java | 40 ++++++++++------------
...a => SingleTableDataCalculatorFactoryTest.java} | 8 ++---
.../FixtureDataConsistencyCheckAlgorithm.java | 4 +--
6 files changed, 35 insertions(+), 42 deletions(-)
diff --git a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/check/consistency/SingleTableDataCalculatorRegistry.java b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/check/consistency/SingleTableDataCalculatorFactory.java
similarity index 96%
rename from shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/check/consistency/SingleTableDataCalculatorRegistry.java
rename to shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/check/consistency/SingleTableDataCalculatorFactory.java
index 08d63c3ca1f..c7f2b238db3 100644
--- a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/check/consistency/SingleTableDataCalculatorRegistry.java
+++ b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/check/consistency/SingleTableDataCalculatorFactory.java
@@ -27,10 +27,10 @@ import java.util.HashMap;
import java.util.Map;
/**
- * Single table data calculator registry.
+ * Single table data calculator factory.
*/
@Slf4j
-public final class SingleTableDataCalculatorRegistry {
+public final class SingleTableDataCalculatorFactory {
private static final Map<String, Map<String, SingleTableDataCalculator>> ALGORITHM_DATABASE_CALCULATOR_MAP = new HashMap<>();
@@ -58,6 +58,9 @@ public final class SingleTableDataCalculatorRegistry {
* @throws ServiceLoaderInstantiationException if new instance by reflection failed
*/
public static SingleTableDataCalculator newServiceInstance(final String algorithmType, final String databaseType) {
+
+
+
Map<String, SingleTableDataCalculator> calculatorMap = ALGORITHM_DATABASE_CALCULATOR_MAP.get(algorithmType);
Preconditions.checkNotNull(calculatorMap, String.format("calculator not found for algorithmType '%s'", algorithmType));
SingleTableDataCalculator calculator = calculatorMap.get(databaseType);
diff --git a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/spi/check/consistency/AbstractDataConsistencyCheckAlgorithm.java b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/spi/check/consistency/AbstractDataConsistencyCheckAlgorithm.java
index 7a01c367d49..1750cfdd0c5 100644
--- a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/spi/check/consistency/AbstractDataConsistencyCheckAlgorithm.java
+++ b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/spi/check/consistency/AbstractDataConsistencyCheckAlgorithm.java
@@ -19,7 +19,7 @@ package org.apache.shardingsphere.data.pipeline.core.spi.check.consistency;
import lombok.Getter;
import lombok.Setter;
-import org.apache.shardingsphere.data.pipeline.core.check.consistency.SingleTableDataCalculatorRegistry;
+import org.apache.shardingsphere.data.pipeline.core.check.consistency.SingleTableDataCalculatorFactory;
import org.apache.shardingsphere.data.pipeline.spi.check.consistency.DataConsistencyCheckAlgorithm;
import org.apache.shardingsphere.data.pipeline.spi.check.consistency.SingleTableDataCalculator;
@@ -40,7 +40,7 @@ public abstract class AbstractDataConsistencyCheckAlgorithm implements DataConsi
@Override
public final SingleTableDataCalculator getSingleTableDataCalculator(final String supportedDatabaseType) {
- SingleTableDataCalculator result = SingleTableDataCalculatorRegistry.newServiceInstance(getType(), supportedDatabaseType);
+ SingleTableDataCalculator result = SingleTableDataCalculatorFactory.newServiceInstance(getType(), supportedDatabaseType);
result.setAlgorithmProps(props);
result.init();
return result;
diff --git a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/spi/check/consistency/AbstractSingleTableDataCalculator.java b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/spi/check/consistency/AbstractSingleTableDataCalculator.java
index a955df5325e..972f9f6779f 100644
--- a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/spi/check/consistency/AbstractSingleTableDataCalculator.java
+++ b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/spi/check/consistency/AbstractSingleTableDataCalculator.java
@@ -17,6 +17,8 @@
package org.apache.shardingsphere.data.pipeline.core.spi.check.consistency;
+import lombok.Getter;
+import lombok.Setter;
import org.apache.shardingsphere.data.pipeline.spi.check.consistency.SingleTableDataCalculator;
import java.util.Properties;
@@ -24,20 +26,12 @@ import java.util.Properties;
/**
* Abstract single table data calculator.
*/
+@Getter
+@Setter
public abstract class AbstractSingleTableDataCalculator implements SingleTableDataCalculator {
private Properties algorithmProps;
- @Override
- public Properties getAlgorithmProps() {
- return algorithmProps;
- }
-
- @Override
- public void setAlgorithmProps(final Properties algorithmProps) {
- this.algorithmProps = algorithmProps;
- }
-
@Override
public void init() {
}
diff --git a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-spi/src/main/java/org/apache/shardingsphere/data/pipeline/spi/check/consistency/SingleTableDataCalculator.java b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-spi/src/main/java/org/apache/shardingsphere/data/pipeline/spi/check/consistency/SingleTableDataCalculator.java
index c14b4220438..85524498d0f 100644
--- a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-spi/src/main/java/org/apache/shardingsphere/data/pipeline/spi/check/consistency/SingleTableDataCalculator.java
+++ b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-spi/src/main/java/org/apache/shardingsphere/data/pipeline/spi/check/consistency/SingleTableDataCalculator.java
@@ -23,27 +23,14 @@ import java.util.Collection;
import java.util.Properties;
/**
- * Single table data calculator interface, SPI.
- *
- * <p>
- * SPI implementation will be initialized as new instance every time.
- * </p>
+ * Single table data calculator.
*/
public interface SingleTableDataCalculator {
/**
- * Get algorithm type.
- *
- * @return algorithm type
- */
- String getAlgorithmType();
-
- /**
- * Get database types.
- *
- * @return database types
+ * Initialize create data calculator.
*/
- Collection<String> getDatabaseTypes();
+ void init();
/**
* Get algorithm properties.
@@ -60,16 +47,25 @@ public interface SingleTableDataCalculator {
*/
void setAlgorithmProps(Properties algorithmProps);
- /**
- * Initialize create data calculator.
- */
- void init();
-
/**
* Calculate table data content, return checksum typically.
*
* @param dataCalculateParameter data calculate parameter
- * @return calculated result, it will be used to check equality.
+ * @return calculated result, it will be used to check equality
*/
Iterable<Object> calculate(DataCalculateParameter dataCalculateParameter);
+
+ /**
+ * Get algorithm type.
+ *
+ * @return algorithm type
+ */
+ String getAlgorithmType();
+
+ /**
+ * Get database types.
+ *
+ * @return database types
+ */
+ Collection<String> getDatabaseTypes();
}
diff --git a/shardingsphere-test/shardingsphere-pipeline-test/src/test/java/org/apache/shardingsphere/data/pipeline/core/check/consistency/SingleTableDataCalculatorRegistryTest.java b/shardingsphere-test/shardingsphere-pipeline-test/src/test/java/org/apache/shardingsphere/data/pipeline/core/check/consistency/SingleTableDataCalculatorFactoryTest.java
similarity index 76%
rename from shardingsphere-test/shardingsphere-pipeline-test/src/test/java/org/apache/shardingsphere/data/pipeline/core/check/consistency/SingleTableDataCalculatorRegistryTest.java
rename to shardingsphere-test/shardingsphere-pipeline-test/src/test/java/org/apache/shardingsphere/data/pipeline/core/check/consistency/SingleTableDataCalculatorFactoryTest.java
index 6b7e5f0a50a..e84c15880b7 100644
--- a/shardingsphere-test/shardingsphere-pipeline-test/src/test/java/org/apache/shardingsphere/data/pipeline/core/check/consistency/SingleTableDataCalculatorRegistryTest.java
+++ b/shardingsphere-test/shardingsphere-pipeline-test/src/test/java/org/apache/shardingsphere/data/pipeline/core/check/consistency/SingleTableDataCalculatorFactoryTest.java
@@ -22,20 +22,20 @@ import org.apache.shardingsphere.infra.database.type.dialect.H2DatabaseType;
import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
import org.junit.Test;
-public final class SingleTableDataCalculatorRegistryTest {
+public final class SingleTableDataCalculatorFactoryTest {
@Test
public void assertNewServiceInstanceSuccess() {
- SingleTableDataCalculatorRegistry.newServiceInstance(FixtureDataConsistencyCheckAlgorithm.TYPE, new H2DatabaseType().getName());
+ SingleTableDataCalculatorFactory.newServiceInstance(FixtureDataConsistencyCheckAlgorithm.TYPE, new H2DatabaseType().getName());
}
@Test(expected = NullPointerException.class)
public void assertNewServiceInstanceFailedNoAlgorithmType() {
- SingleTableDataCalculatorRegistry.newServiceInstance("not-exists-alg", new H2DatabaseType().getName());
+ SingleTableDataCalculatorFactory.newServiceInstance("not-exists-alg", new H2DatabaseType().getName());
}
@Test(expected = NullPointerException.class)
public void assertNewServiceInstanceFailedNoDatabaseType() {
- SingleTableDataCalculatorRegistry.newServiceInstance(FixtureDataConsistencyCheckAlgorithm.TYPE, new MySQLDatabaseType().getName());
+ SingleTableDataCalculatorFactory.newServiceInstance(FixtureDataConsistencyCheckAlgorithm.TYPE, new MySQLDatabaseType().getName());
}
}
diff --git a/shardingsphere-test/shardingsphere-pipeline-test/src/test/java/org/apache/shardingsphere/data/pipeline/core/fixture/FixtureDataConsistencyCheckAlgorithm.java b/shardingsphere-test/shardingsphere-pipeline-test/src/test/java/org/apache/shardingsphere/data/pipeline/core/fixture/FixtureDataConsistencyCheckAlgorithm.java
index 5ba06b55712..c95ef730af1 100644
--- a/shardingsphere-test/shardingsphere-pipeline-test/src/test/java/org/apache/shardingsphere/data/pipeline/core/fixture/FixtureDataConsistencyCheckAlgorithm.java
+++ b/shardingsphere-test/shardingsphere-pipeline-test/src/test/java/org/apache/shardingsphere/data/pipeline/core/fixture/FixtureDataConsistencyCheckAlgorithm.java
@@ -18,7 +18,7 @@
package org.apache.shardingsphere.data.pipeline.core.fixture;
import lombok.Setter;
-import org.apache.shardingsphere.data.pipeline.core.check.consistency.SingleTableDataCalculatorRegistry;
+import org.apache.shardingsphere.data.pipeline.core.check.consistency.SingleTableDataCalculatorFactory;
import org.apache.shardingsphere.data.pipeline.spi.check.consistency.DataConsistencyCheckAlgorithm;
import org.apache.shardingsphere.data.pipeline.spi.check.consistency.SingleTableDataCalculator;
import org.apache.shardingsphere.infra.database.type.dialect.H2DatabaseType;
@@ -41,7 +41,7 @@ public final class FixtureDataConsistencyCheckAlgorithm implements DataConsisten
@Override
public SingleTableDataCalculator getSingleTableDataCalculator(final String supportedDatabaseType) {
- return SingleTableDataCalculatorRegistry.newServiceInstance(TYPE, supportedDatabaseType);
+ return SingleTableDataCalculatorFactory.newServiceInstance(TYPE, supportedDatabaseType);
}
@Override