This is an automated email from the ASF dual-hosted git repository.
sunnianjun 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 d69b3f13d0b Move PrepareTargetSchemasParameter and
PrepareTargetTablesParameter (#29405)
d69b3f13d0b is described below
commit d69b3f13d0b5424f210d852146cb3680108c734b
Author: Liang Zhang <[email protected]>
AuthorDate: Thu Dec 14 23:34:27 2023 +0800
Move PrepareTargetSchemasParameter and PrepareTargetTablesParameter (#29405)
---
.../core/preparer/PipelineJobPreparerUtils.java | 4 +--
.../datasource/AbstractDataSourcePreparer.java | 34 +++++-----------------
.../preparer/datasource/DataSourcePreparer.java | 2 ++
.../{ => param}/PrepareTargetSchemasParameter.java | 2 +-
.../{ => param}/PrepareTargetTablesParameter.java | 2 +-
.../datasource/AbstractDataSourcePreparerTest.java | 1 +
.../datasource/MySQLDataSourcePreparer.java | 4 +--
.../datasource/OpenGaussDataSourcePreparer.java | 6 ++--
.../datasource/PostgreSQLDataSourcePreparer.java | 4 +--
.../migration/preparer/MigrationJobPreparer.java | 4 +--
.../core/fixture/H2DataSourcePreparer.java | 4 +--
11 files changed, 26 insertions(+), 41 deletions(-)
diff --git
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/preparer/PipelineJobPreparerUtils.java
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/preparer/PipelineJobPreparerUtils.java
index 3d9df076335..d17716d8517 100644
---
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/preparer/PipelineJobPreparerUtils.java
+++
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/preparer/PipelineJobPreparerUtils.java
@@ -31,8 +31,8 @@ import
org.apache.shardingsphere.data.pipeline.core.datasource.PipelineDataSourc
import
org.apache.shardingsphere.data.pipeline.core.job.progress.JobItemIncrementalTasksProgress;
import
org.apache.shardingsphere.data.pipeline.core.preparer.datasource.DataSourceCheckEngine;
import
org.apache.shardingsphere.data.pipeline.core.preparer.datasource.DataSourcePreparer;
-import
org.apache.shardingsphere.data.pipeline.core.preparer.datasource.PrepareTargetSchemasParameter;
-import
org.apache.shardingsphere.data.pipeline.core.preparer.datasource.PrepareTargetTablesParameter;
+import
org.apache.shardingsphere.data.pipeline.core.preparer.datasource.param.PrepareTargetSchemasParameter;
+import
org.apache.shardingsphere.data.pipeline.core.preparer.datasource.param.PrepareTargetTablesParameter;
import
org.apache.shardingsphere.data.pipeline.core.spi.ingest.dumper.IncrementalDumperCreator;
import
org.apache.shardingsphere.data.pipeline.core.spi.ingest.position.PositionInitializer;
import
org.apache.shardingsphere.infra.database.core.spi.DatabaseTypedSPILoader;
diff --git
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/preparer/datasource/AbstractDataSourcePreparer.java
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/preparer/datasource/AbstractDataSourcePreparer.java
index eb8c4bab028..e4323adfe8f 100644
---
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/preparer/datasource/AbstractDataSourcePreparer.java
+++
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/preparer/datasource/AbstractDataSourcePreparer.java
@@ -21,8 +21,8 @@ import lombok.extern.slf4j.Slf4j;
import
org.apache.shardingsphere.data.pipeline.api.PipelineDataSourceConfiguration;
import
org.apache.shardingsphere.data.pipeline.core.preparer.CreateTableConfiguration;
import
org.apache.shardingsphere.data.pipeline.core.datasource.PipelineDataSourceManager;
-import
org.apache.shardingsphere.data.pipeline.core.datasource.PipelineDataSourceWrapper;
import
org.apache.shardingsphere.data.pipeline.core.metadata.generator.PipelineDDLGenerator;
+import
org.apache.shardingsphere.data.pipeline.core.preparer.datasource.param.PrepareTargetSchemasParameter;
import
org.apache.shardingsphere.data.pipeline.core.sqlbuilder.PipelineCommonSQLBuilder;
import
org.apache.shardingsphere.infra.database.core.metadata.database.DialectDatabaseMetaData;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
@@ -55,11 +55,10 @@ public abstract class AbstractDataSourcePreparer implements
DataSourcePreparer {
if (!dialectDatabaseMetaData.isSchemaAvailable()) {
return;
}
- Collection<CreateTableConfiguration> createTableConfigs =
param.getCreateTableConfigurations();
String defaultSchema =
dialectDatabaseMetaData.getDefaultSchema().orElse(null);
PipelineCommonSQLBuilder pipelineSQLBuilder = new
PipelineCommonSQLBuilder(targetDatabaseType);
Collection<String> createdSchemaNames = new HashSet<>();
- for (CreateTableConfiguration each : createTableConfigs) {
+ for (CreateTableConfiguration each :
param.getCreateTableConfigurations()) {
String targetSchemaName =
each.getTargetName().getSchemaName().toString();
if (null == targetSchemaName ||
targetSchemaName.equalsIgnoreCase(defaultSchema) ||
createdSchemaNames.contains(targetSchemaName)) {
continue;
@@ -73,38 +72,21 @@ public abstract class AbstractDataSourcePreparer implements
DataSourcePreparer {
}
private void executeCreateSchema(final PipelineDataSourceManager
dataSourceManager, final PipelineDataSourceConfiguration
targetDataSourceConfig, final String sql) throws SQLException {
- log.info("prepareTargetSchemas, sql={}", sql);
- try (Connection connection = getCachedDataSource(dataSourceManager,
targetDataSourceConfig).getConnection()) {
- try (Statement statement = connection.createStatement()) {
- statement.execute(sql);
- }
+ log.info("Prepare target schemas SQL: {}", sql);
+ try (
+ Connection connection =
dataSourceManager.getDataSource(targetDataSourceConfig).getConnection();
+ Statement statement = connection.createStatement()) {
+ statement.execute(sql);
}
}
- protected final PipelineDataSourceWrapper getCachedDataSource(final
PipelineDataSourceManager dataSourceManager, final
PipelineDataSourceConfiguration dataSourceConfig) {
- return dataSourceManager.getDataSource(dataSourceConfig);
- }
-
- /**
- * Execute target table SQL.
- *
- * @param targetConnection target connection
- * @param sql SQL
- * @throws SQLException SQL exception
- */
protected void executeTargetTableSQL(final Connection targetConnection,
final String sql) throws SQLException {
- log.info("execute target table sql: {}", sql);
+ log.info("Execute target table SQL: {}", sql);
try (Statement statement = targetConnection.createStatement()) {
statement.execute(sql);
}
}
- /**
- * Add if not exists for create table SQL.
- *
- * @param createTableSQL create table SQL
- * @return create table if not existed SQL
- */
protected final String addIfNotExistsForCreateTableSQL(final String
createTableSQL) {
if (PATTERN_CREATE_TABLE_IF_NOT_EXISTS.matcher(createTableSQL).find())
{
return createTableSQL;
diff --git
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/preparer/datasource/DataSourcePreparer.java
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/preparer/datasource/DataSourcePreparer.java
index 3851e4babd2..3becc7f8089 100644
---
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/preparer/datasource/DataSourcePreparer.java
+++
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/preparer/datasource/DataSourcePreparer.java
@@ -17,6 +17,8 @@
package org.apache.shardingsphere.data.pipeline.core.preparer.datasource;
+import
org.apache.shardingsphere.data.pipeline.core.preparer.datasource.param.PrepareTargetSchemasParameter;
+import
org.apache.shardingsphere.data.pipeline.core.preparer.datasource.param.PrepareTargetTablesParameter;
import org.apache.shardingsphere.infra.database.core.spi.DatabaseTypedSPI;
import org.apache.shardingsphere.infra.spi.annotation.SingletonSPI;
diff --git
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/preparer/datasource/PrepareTargetSchemasParameter.java
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/preparer/datasource/param/PrepareTargetSchemasParameter.java
similarity index 98%
rename from
kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/preparer/datasource/PrepareTargetSchemasParameter.java
rename to
kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/preparer/datasource/param/PrepareTargetSchemasParameter.java
index a367d5a2bb0..7b4cf8e8d36 100644
---
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/preparer/datasource/PrepareTargetSchemasParameter.java
+++
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/preparer/datasource/param/PrepareTargetSchemasParameter.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.data.pipeline.core.preparer.datasource;
+package org.apache.shardingsphere.data.pipeline.core.preparer.datasource.param;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
diff --git
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/preparer/datasource/PrepareTargetTablesParameter.java
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/preparer/datasource/param/PrepareTargetTablesParameter.java
similarity index 98%
rename from
kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/preparer/datasource/PrepareTargetTablesParameter.java
rename to
kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/preparer/datasource/param/PrepareTargetTablesParameter.java
index cdaac34a2f2..348c931eb0a 100644
---
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/preparer/datasource/PrepareTargetTablesParameter.java
+++
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/preparer/datasource/param/PrepareTargetTablesParameter.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.data.pipeline.core.preparer.datasource;
+package org.apache.shardingsphere.data.pipeline.core.preparer.datasource.param;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
diff --git
a/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/preparer/datasource/AbstractDataSourcePreparerTest.java
b/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/preparer/datasource/AbstractDataSourcePreparerTest.java
index 05081717dd1..d736c7286cf 100644
---
a/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/preparer/datasource/AbstractDataSourcePreparerTest.java
+++
b/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/preparer/datasource/AbstractDataSourcePreparerTest.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.data.pipeline.core.preparer.datasource;
+import
org.apache.shardingsphere.data.pipeline.core.preparer.datasource.param.PrepareTargetTablesParameter;
import org.junit.jupiter.api.Test;
import java.sql.Connection;
diff --git
a/kernel/data-pipeline/dialect/mysql/src/main/java/org/apache/shardingsphere/data/pipeline/mysql/prepare/datasource/MySQLDataSourcePreparer.java
b/kernel/data-pipeline/dialect/mysql/src/main/java/org/apache/shardingsphere/data/pipeline/mysql/prepare/datasource/MySQLDataSourcePreparer.java
index 239ff6704a2..044054b1311 100644
---
a/kernel/data-pipeline/dialect/mysql/src/main/java/org/apache/shardingsphere/data/pipeline/mysql/prepare/datasource/MySQLDataSourcePreparer.java
+++
b/kernel/data-pipeline/dialect/mysql/src/main/java/org/apache/shardingsphere/data/pipeline/mysql/prepare/datasource/MySQLDataSourcePreparer.java
@@ -20,7 +20,7 @@ package
org.apache.shardingsphere.data.pipeline.mysql.prepare.datasource;
import
org.apache.shardingsphere.data.pipeline.core.preparer.CreateTableConfiguration;
import
org.apache.shardingsphere.data.pipeline.core.datasource.PipelineDataSourceManager;
import
org.apache.shardingsphere.data.pipeline.core.preparer.datasource.AbstractDataSourcePreparer;
-import
org.apache.shardingsphere.data.pipeline.core.preparer.datasource.PrepareTargetTablesParameter;
+import
org.apache.shardingsphere.data.pipeline.core.preparer.datasource.param.PrepareTargetTablesParameter;
import java.sql.Connection;
import java.sql.SQLException;
@@ -35,7 +35,7 @@ public final class MySQLDataSourcePreparer extends
AbstractDataSourcePreparer {
PipelineDataSourceManager dataSourceManager =
param.getDataSourceManager();
for (CreateTableConfiguration each :
param.getCreateTableConfigurations()) {
String createTargetTableSQL = getCreateTargetTableSQL(each,
dataSourceManager, param.getSqlParserEngine());
- try (Connection targetConnection =
getCachedDataSource(dataSourceManager,
each.getTargetDataSourceConfig()).getConnection()) {
+ try (Connection targetConnection =
dataSourceManager.getDataSource(each.getTargetDataSourceConfig()).getConnection())
{
executeTargetTableSQL(targetConnection,
addIfNotExistsForCreateTableSQL(createTargetTableSQL));
}
}
diff --git
a/kernel/data-pipeline/dialect/opengauss/src/main/java/org/apache/shardingsphere/data/pipeline/opengauss/prepare/datasource/OpenGaussDataSourcePreparer.java
b/kernel/data-pipeline/dialect/opengauss/src/main/java/org/apache/shardingsphere/data/pipeline/opengauss/prepare/datasource/OpenGaussDataSourcePreparer.java
index 005e13d4b31..f1efbf10832 100644
---
a/kernel/data-pipeline/dialect/opengauss/src/main/java/org/apache/shardingsphere/data/pipeline/opengauss/prepare/datasource/OpenGaussDataSourcePreparer.java
+++
b/kernel/data-pipeline/dialect/opengauss/src/main/java/org/apache/shardingsphere/data/pipeline/opengauss/prepare/datasource/OpenGaussDataSourcePreparer.java
@@ -22,8 +22,8 @@ import lombok.extern.slf4j.Slf4j;
import
org.apache.shardingsphere.data.pipeline.core.preparer.CreateTableConfiguration;
import
org.apache.shardingsphere.data.pipeline.core.datasource.PipelineDataSourceManager;
import
org.apache.shardingsphere.data.pipeline.core.preparer.datasource.AbstractDataSourcePreparer;
-import
org.apache.shardingsphere.data.pipeline.core.preparer.datasource.PrepareTargetSchemasParameter;
-import
org.apache.shardingsphere.data.pipeline.core.preparer.datasource.PrepareTargetTablesParameter;
+import
org.apache.shardingsphere.data.pipeline.core.preparer.datasource.param.PrepareTargetSchemasParameter;
+import
org.apache.shardingsphere.data.pipeline.core.preparer.datasource.param.PrepareTargetTablesParameter;
import java.sql.Connection;
import java.sql.SQLException;
@@ -52,7 +52,7 @@ public final class OpenGaussDataSourcePreparer extends
AbstractDataSourcePrepare
PipelineDataSourceManager dataSourceManager =
param.getDataSourceManager();
for (CreateTableConfiguration each :
param.getCreateTableConfigurations()) {
String createTargetTableSQL = getCreateTargetTableSQL(each,
dataSourceManager, param.getSqlParserEngine());
- try (Connection targetConnection =
getCachedDataSource(dataSourceManager,
each.getTargetDataSourceConfig()).getConnection()) {
+ try (Connection targetConnection =
dataSourceManager.getDataSource(each.getTargetDataSourceConfig()).getConnection())
{
for (String sql :
Splitter.on(";").trimResults().omitEmptyStrings().splitToList(createTargetTableSQL))
{
executeTargetTableSQL(targetConnection,
addIfNotExistsForCreateTableSQL(sql));
}
diff --git
a/kernel/data-pipeline/dialect/postgresql/src/main/java/org/apache/shardingsphere/data/pipeline/postgresql/prepare/datasource/PostgreSQLDataSourcePreparer.java
b/kernel/data-pipeline/dialect/postgresql/src/main/java/org/apache/shardingsphere/data/pipeline/postgresql/prepare/datasource/PostgreSQLDataSourcePreparer.java
index 2f788f7dab0..735cf423b84 100644
---
a/kernel/data-pipeline/dialect/postgresql/src/main/java/org/apache/shardingsphere/data/pipeline/postgresql/prepare/datasource/PostgreSQLDataSourcePreparer.java
+++
b/kernel/data-pipeline/dialect/postgresql/src/main/java/org/apache/shardingsphere/data/pipeline/postgresql/prepare/datasource/PostgreSQLDataSourcePreparer.java
@@ -21,7 +21,7 @@ import com.google.common.base.Splitter;
import
org.apache.shardingsphere.data.pipeline.core.preparer.CreateTableConfiguration;
import
org.apache.shardingsphere.data.pipeline.core.datasource.PipelineDataSourceManager;
import
org.apache.shardingsphere.data.pipeline.core.preparer.datasource.AbstractDataSourcePreparer;
-import
org.apache.shardingsphere.data.pipeline.core.preparer.datasource.PrepareTargetTablesParameter;
+import
org.apache.shardingsphere.data.pipeline.core.preparer.datasource.param.PrepareTargetTablesParameter;
import java.sql.Connection;
import java.sql.SQLException;
@@ -36,7 +36,7 @@ public final class PostgreSQLDataSourcePreparer extends
AbstractDataSourcePrepar
PipelineDataSourceManager dataSourceManager =
param.getDataSourceManager();
for (CreateTableConfiguration each :
param.getCreateTableConfigurations()) {
String createTargetTableSQL = getCreateTargetTableSQL(each,
dataSourceManager, param.getSqlParserEngine());
- try (Connection targetConnection =
getCachedDataSource(dataSourceManager,
each.getTargetDataSourceConfig()).getConnection()) {
+ try (Connection targetConnection =
dataSourceManager.getDataSource(each.getTargetDataSourceConfig()).getConnection())
{
for (String sql :
Splitter.on(";").trimResults().omitEmptyStrings().splitToList(createTargetTableSQL))
{
executeTargetTableSQL(targetConnection, sql);
}
diff --git
a/kernel/data-pipeline/scenario/migration/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/migration/preparer/MigrationJobPreparer.java
b/kernel/data-pipeline/scenario/migration/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/migration/preparer/MigrationJobPreparer.java
index 6dc4aaf4583..69c4780ab64 100644
---
a/kernel/data-pipeline/scenario/migration/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/migration/preparer/MigrationJobPreparer.java
+++
b/kernel/data-pipeline/scenario/migration/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/migration/preparer/MigrationJobPreparer.java
@@ -49,8 +49,8 @@ import
org.apache.shardingsphere.data.pipeline.core.job.api.PipelineAPIFactory;
import
org.apache.shardingsphere.data.pipeline.core.job.service.PipelineJobItemManager;
import
org.apache.shardingsphere.data.pipeline.core.preparer.InventoryTaskSplitter;
import
org.apache.shardingsphere.data.pipeline.core.preparer.PipelineJobPreparerUtils;
-import
org.apache.shardingsphere.data.pipeline.core.preparer.datasource.PrepareTargetSchemasParameter;
-import
org.apache.shardingsphere.data.pipeline.core.preparer.datasource.PrepareTargetTablesParameter;
+import
org.apache.shardingsphere.data.pipeline.core.preparer.datasource.param.PrepareTargetSchemasParameter;
+import
org.apache.shardingsphere.data.pipeline.core.preparer.datasource.param.PrepareTargetTablesParameter;
import org.apache.shardingsphere.data.pipeline.core.task.IncrementalTask;
import org.apache.shardingsphere.data.pipeline.core.task.PipelineTask;
import org.apache.shardingsphere.data.pipeline.core.task.PipelineTaskUtils;
diff --git
a/test/it/pipeline/src/test/java/org/apache/shardingsphere/test/it/data/pipeline/core/fixture/H2DataSourcePreparer.java
b/test/it/pipeline/src/test/java/org/apache/shardingsphere/test/it/data/pipeline/core/fixture/H2DataSourcePreparer.java
index c3c8b5888a2..af256eed7fa 100644
---
a/test/it/pipeline/src/test/java/org/apache/shardingsphere/test/it/data/pipeline/core/fixture/H2DataSourcePreparer.java
+++
b/test/it/pipeline/src/test/java/org/apache/shardingsphere/test/it/data/pipeline/core/fixture/H2DataSourcePreparer.java
@@ -20,7 +20,7 @@ package
org.apache.shardingsphere.test.it.data.pipeline.core.fixture;
import
org.apache.shardingsphere.data.pipeline.core.preparer.CreateTableConfiguration;
import
org.apache.shardingsphere.data.pipeline.core.datasource.PipelineDataSourceManager;
import
org.apache.shardingsphere.data.pipeline.core.preparer.datasource.AbstractDataSourcePreparer;
-import
org.apache.shardingsphere.data.pipeline.core.preparer.datasource.PrepareTargetTablesParameter;
+import
org.apache.shardingsphere.data.pipeline.core.preparer.datasource.param.PrepareTargetTablesParameter;
import java.sql.Connection;
import java.sql.SQLException;
@@ -35,7 +35,7 @@ public final class H2DataSourcePreparer extends
AbstractDataSourcePreparer {
PipelineDataSourceManager dataSourceManager =
param.getDataSourceManager();
for (CreateTableConfiguration each :
param.getCreateTableConfigurations()) {
String createTargetTableSQL = getCreateTargetTableSQL(each,
dataSourceManager, param.getSqlParserEngine());
- try (Connection targetConnection =
getCachedDataSource(dataSourceManager,
each.getTargetDataSourceConfig()).getConnection()) {
+ try (Connection targetConnection =
dataSourceManager.getDataSource(each.getTargetDataSourceConfig()).getConnection())
{
executeTargetTableSQL(targetConnection,
addIfNotExistsForCreateTableSQL(createTargetTableSQL));
}
}