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 96db5dc5c73 Refactor UnsupportedPipelineDatabaseTypeException (#21096)
96db5dc5c73 is described below

commit 96db5dc5c73dce87de72de5c9882ac4aebf82ea3
Author: Liang Zhang <[email protected]>
AuthorDate: Tue Sep 20 23:35:41 2022 +0800

    Refactor UnsupportedPipelineDatabaseTypeException (#21096)
    
    * Refactor UnsupportedPipelineDatabaseTypeException
---
 ...va => UnsupportedPipelineDatabaseTypeException.java} | 12 ++++++++----
 .../migration/MigrationDataConsistencyChecker.java      | 17 ++++++-----------
 2 files changed, 14 insertions(+), 15 deletions(-)

diff --git 
a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/exception/data/PipelineDataConsistencyCheckFailedException.java
 
b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/exception/data/UnsupportedPipelineDatabaseTypeException.java
similarity index 62%
rename from 
shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/exception/data/PipelineDataConsistencyCheckFailedException.java
rename to 
shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/exception/data/UnsupportedPipelineDatabaseTypeException.java
index f93ad157cc6..b758f7d6dcd 100644
--- 
a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/exception/data/PipelineDataConsistencyCheckFailedException.java
+++ 
b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/exception/data/UnsupportedPipelineDatabaseTypeException.java
@@ -17,14 +17,18 @@
 
 package org.apache.shardingsphere.data.pipeline.core.exception.data;
 
+import 
org.apache.shardingsphere.data.pipeline.core.exception.PipelineSQLException;
+import org.apache.shardingsphere.infra.database.type.DatabaseType;
+import 
org.apache.shardingsphere.infra.util.exception.external.sql.sqlstate.XOpenSQLState;
+
 /**
- * Pipeline data consistency check failed exception.
+ * Unsupported pipeline database type exception.
  */
-public final class PipelineDataConsistencyCheckFailedException extends 
RuntimeException {
+public final class UnsupportedPipelineDatabaseTypeException extends 
PipelineSQLException {
     
     private static final long serialVersionUID = -4100671584682823997L;
     
-    public PipelineDataConsistencyCheckFailedException(final String message) {
-        super(message);
+    public UnsupportedPipelineDatabaseTypeException(final DatabaseType 
databaseType) {
+        super(XOpenSQLState.FEATURE_NOT_SUPPORTED, 52, "Unsupported pipeline 
database type `%s`", databaseType.getType());
     }
 }
diff --git 
a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/migration/MigrationDataConsistencyChecker.java
 
b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/migration/MigrationDataConsistencyChecker.java
index df72c64d218..a196b56e552 100644
--- 
a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/migration/MigrationDataConsistencyChecker.java
+++ 
b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/migration/MigrationDataConsistencyChecker.java
@@ -32,7 +32,7 @@ import 
org.apache.shardingsphere.data.pipeline.api.metadata.model.PipelineColumn
 import 
org.apache.shardingsphere.data.pipeline.api.metadata.model.PipelineTableMetaData;
 import 
org.apache.shardingsphere.data.pipeline.core.datasource.PipelineDataSourceFactory;
 import 
org.apache.shardingsphere.data.pipeline.core.exception.PipelineSQLException;
-import 
org.apache.shardingsphere.data.pipeline.core.exception.data.PipelineDataConsistencyCheckFailedException;
+import 
org.apache.shardingsphere.data.pipeline.core.exception.data.UnsupportedPipelineDatabaseTypeException;
 import 
org.apache.shardingsphere.data.pipeline.core.exception.data.PipelineTableDataConsistencyCheckLoadingFailedException;
 import 
org.apache.shardingsphere.data.pipeline.core.metadata.loader.StandardPipelineTableMetaDataLoader;
 import 
org.apache.shardingsphere.data.pipeline.core.sqlbuilder.PipelineSQLBuilderFactory;
@@ -170,9 +170,9 @@ public final class MigrationDataConsistencyChecker {
     }
     
     private Map<String, DataConsistencyContentCheckResult> checkData(final 
DataConsistencyCalculateAlgorithm calculator) {
-        decoratePipelineDataSourceConfiguration(calculator, 
jobConfig.getSource());
+        checkPipelineDatabaseType(calculator, jobConfig.getSource());
         PipelineDataSourceConfiguration sourceDataSourceConfig = 
jobConfig.getSource();
-        decoratePipelineDataSourceConfiguration(calculator, 
jobConfig.getTarget());
+        checkPipelineDatabaseType(calculator, jobConfig.getTarget());
         PipelineDataSourceConfiguration targetDataSourceConfig = 
jobConfig.getTarget();
         ThreadFactory threadFactory = 
ExecutorThreadFactoryBuilder.build("job-" + 
getJobIdDigest(jobConfig.getJobId()) + "-data-check-%d");
         ThreadPoolExecutor executor = new ThreadPoolExecutor(2, 2, 60, 
TimeUnit.SECONDS, new ArrayBlockingQueue<>(2), threadFactory);
@@ -220,14 +220,9 @@ public final class MigrationDataConsistencyChecker {
         return result;
     }
     
-    private void decoratePipelineDataSourceConfiguration(final 
DataConsistencyCalculateAlgorithm calculator, final 
PipelineDataSourceConfiguration dataSourceConfig) {
-        checkDatabaseTypeSupported(calculator.getSupportedDatabaseTypes(), 
dataSourceConfig.getDatabaseType().getType());
-    }
-    
-    private void checkDatabaseTypeSupported(final Collection<String> 
supportedDatabaseTypes, final String databaseType) {
-        if (!supportedDatabaseTypes.contains(databaseType)) {
-            throw new PipelineDataConsistencyCheckFailedException("Database 
type " + databaseType + " is not supported in " + supportedDatabaseTypes);
-        }
+    private void checkPipelineDatabaseType(final 
DataConsistencyCalculateAlgorithm calculator, final 
PipelineDataSourceConfiguration dataSourceConfig) {
+        
ShardingSpherePreconditions.checkState(calculator.getSupportedDatabaseTypes().contains(dataSourceConfig.getDatabaseType().getType()),
+                () -> new 
UnsupportedPipelineDatabaseTypeException(dataSourceConfig.getDatabaseType()));
     }
     
     private DataConsistencyCalculateParameter buildParameter(final 
PipelineDataSourceWrapper sourceDataSource, final TableNameSchemaNameMapping 
tableNameSchemaNameMapping,

Reply via email to