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/30 15:07:47 UTC
[shardingsphere] branch master updated: Add DataSourceCheckerFactory (#17238)
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 3764d8b396b Add DataSourceCheckerFactory (#17238)
3764d8b396b is described below
commit 3764d8b396bc7d2a8a29e27b7c00e4ef8945db6e
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Sat Apr 30 23:07:39 2022 +0800
Add DataSourceCheckerFactory (#17238)
---
.../check/datasource/DataSourceCheckerFactory.java | 44 ++++++++++++++++++++++
.../rulealtered/RuleAlteredJobPreparer.java | 11 ++----
2 files changed, 47 insertions(+), 8 deletions(-)
diff --git a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-api/src/main/java/org/apache/shardingsphere/data/pipeline/spi/check/datasource/DataSourceCheckerFactory.java b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-api/src/main/java/org/apache/shardingsphere/data/pipeline/spi/check/datasource/DataSourceCheckerFactory.java
new file mode 100644
index 00000000000..4e4e5dc70cd
--- /dev/null
+++ b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-api/src/main/java/org/apache/shardingsphere/data/pipeline/spi/check/datasource/DataSourceCheckerFactory.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.data.pipeline.spi.check.datasource;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
+import org.apache.shardingsphere.spi.type.typed.TypedSPIRegistry;
+
+/**
+ * Data source checker.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class DataSourceCheckerFactory {
+
+ static {
+ ShardingSphereServiceLoader.register(DataSourceChecker.class);
+ }
+
+ /**
+ * Create new instance of data source checker.
+ *
+ * @param databaseType database type
+ * @return new instance of data source checker
+ */
+ public static DataSourceChecker newInstance(final String databaseType) {
+ return TypedSPIRegistry.getRegisteredService(DataSourceChecker.class, databaseType);
+ }
+}
diff --git a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/rulealtered/RuleAlteredJobPreparer.java b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/rulealtered/RuleAlteredJobPreparer.java
index 5f97ac40df7..0bba76d4b74 100644
--- a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/rulealtered/RuleAlteredJobPreparer.java
+++ b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/rulealtered/RuleAlteredJobPreparer.java
@@ -40,6 +40,7 @@ import org.apache.shardingsphere.data.pipeline.core.task.InventoryTask;
import org.apache.shardingsphere.data.pipeline.core.util.ThreadUtil;
import org.apache.shardingsphere.data.pipeline.scenario.rulealtered.prepare.InventoryTaskSplitter;
import org.apache.shardingsphere.data.pipeline.spi.check.datasource.DataSourceChecker;
+import org.apache.shardingsphere.data.pipeline.spi.check.datasource.DataSourceCheckerFactory;
import org.apache.shardingsphere.data.pipeline.spi.ingest.channel.PipelineChannelFactory;
import org.apache.shardingsphere.data.pipeline.spi.ingest.position.PositionInitializer;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
@@ -49,8 +50,6 @@ import org.apache.shardingsphere.infra.datasource.props.DataSourceProperties;
import org.apache.shardingsphere.infra.lock.ShardingSphereLock;
import org.apache.shardingsphere.infra.yaml.config.swapper.YamlDataSourceConfigurationSwapper;
import org.apache.shardingsphere.scaling.core.job.check.EnvironmentCheckerFactory;
-import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.spi.type.typed.TypedSPIRegistry;
import javax.sql.DataSource;
import java.sql.SQLException;
@@ -66,10 +65,6 @@ import java.util.concurrent.TimeUnit;
@Slf4j
public final class RuleAlteredJobPreparer {
- static {
- ShardingSphereServiceLoader.register(DataSourceChecker.class);
- }
-
private final InventoryTaskSplitter inventoryTaskSplitter = new InventoryTaskSplitter();
/**
@@ -140,7 +135,7 @@ public final class RuleAlteredJobPreparer {
}
private void checkSourceDataSource(final RuleAlteredJobContext jobContext) {
- DataSourceChecker dataSourceChecker = TypedSPIRegistry.getRegisteredService(DataSourceChecker.class, jobContext.getJobConfig().getSourceDatabaseType());
+ DataSourceChecker dataSourceChecker = DataSourceCheckerFactory.newInstance(jobContext.getJobConfig().getSourceDatabaseType());
Collection<PipelineDataSourceWrapper> sourceDataSources = Collections.singleton(jobContext.getSourceDataSource());
dataSourceChecker.checkConnection(sourceDataSources);
dataSourceChecker.checkPrivilege(sourceDataSources);
@@ -148,7 +143,7 @@ public final class RuleAlteredJobPreparer {
}
private void checkTargetDataSource(final RuleAlteredJobContext jobContext, final PipelineDataSourceWrapper targetDataSource) {
- DataSourceChecker dataSourceChecker = TypedSPIRegistry.getRegisteredService(DataSourceChecker.class, jobContext.getJobConfig().getTargetDatabaseType());
+ DataSourceChecker dataSourceChecker = DataSourceCheckerFactory.newInstance(jobContext.getJobConfig().getTargetDatabaseType());
Collection<PipelineDataSourceWrapper> targetDataSources = Collections.singletonList(targetDataSource);
dataSourceChecker.checkConnection(targetDataSources);
dataSourceChecker.checkTargetTable(targetDataSources, jobContext.getTaskConfig().getImporterConfig().getShardingColumnsMap().keySet());