This is an automated email from the ASF dual-hosted git repository.
jianglongtao 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 ed87cb3d399 Refactor AddMigrationSourceResourceException (#21098)
ed87cb3d399 is described below
commit ed87cb3d39962e4fdf24d5105fd1bf740fb3d9b2
Author: Liang Zhang <[email protected]>
AuthorDate: Wed Sep 21 00:18:11 2022 +0800
Refactor AddMigrationSourceResourceException (#21098)
---
.../content/user-manual/error-code/sql-error-code.cn.md | 1 +
.../content/user-manual/error-code/sql-error-code.en.md | 1 +
.../handler/update/AddMigrationSourceResourceUpdater.java | 4 ++--
.../connection/AddMigrationSourceResourceException.java | 15 ++++++++-------
.../pipeline/scenario/migration/MigrationJobAPIImpl.java | 4 +---
5 files changed, 13 insertions(+), 12 deletions(-)
diff --git a/docs/document/content/user-manual/error-code/sql-error-code.cn.md
b/docs/document/content/user-manual/error-code/sql-error-code.cn.md
index 13842ee5484..a6c300f9e25 100644
--- a/docs/document/content/user-manual/error-code/sql-error-code.cn.md
+++ b/docs/document/content/user-manual/error-code/sql-error-code.cn.md
@@ -92,6 +92,7 @@ SQL 错误码以标准的 SQL State,Vendor Code 和详细错误信息提供,
| 44000 | 18001 | Created process configuration already existed |
| 44000 | 18002 | Altered process configuration does not exist |
| HY000 | 18020 | Failed to get DDL for table \`%s\` |
+| 42S01 | 18030 | Duplicate resource names \`%s\` |
| 42S02 | 18031 | Resource names \`%s\` do not exist |
| HY000 | 18050 | Before data record is \`%s\`, after data record is
\`%s\` |
| 08000 | 18051 | Data check table \`%s\` failed |
diff --git a/docs/document/content/user-manual/error-code/sql-error-code.en.md
b/docs/document/content/user-manual/error-code/sql-error-code.en.md
index 849e3e63af5..0f90f91a98c 100644
--- a/docs/document/content/user-manual/error-code/sql-error-code.en.md
+++ b/docs/document/content/user-manual/error-code/sql-error-code.en.md
@@ -92,6 +92,7 @@ SQL error codes provide by standard `SQL State`, `Vendor
Code` and `Reason`, whi
| 44000 | 18001 | Created process configuration already existed |
| 44000 | 18002 | Altered process configuration does not exist |
| HY000 | 18020 | Failed to get DDL for table \`%s\` |
+| 42S01 | 18030 | Duplicate resource names \`%s\` |
| 42S02 | 18031 | Resource names \`%s\` do not exist |
| HY000 | 18050 | Before data record is \`%s\`, after data record is
\`%s\` |
| 08000 | 18051 | Data check table \`%s\` failed |
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/migration/distsql/handler/update/AddMigrationSourceResourceUpdater.java
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/migration/distsql/handler/update/AddMigrationSourceResourceUpdater.java
index f506b6db64f..24af476d34a 100644
---
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/migration/distsql/handler/update/AddMigrationSourceResourceUpdater.java
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/migration/distsql/handler/update/AddMigrationSourceResourceUpdater.java
@@ -19,7 +19,6 @@ package
org.apache.shardingsphere.migration.distsql.handler.update;
import org.apache.shardingsphere.data.pipeline.api.MigrationJobPublicAPI;
import org.apache.shardingsphere.data.pipeline.api.PipelineJobPublicAPIFactory;
-import
org.apache.shardingsphere.data.pipeline.core.exception.connection.AddMigrationSourceResourceException;
import org.apache.shardingsphere.distsql.parser.segment.DataSourceSegment;
import
org.apache.shardingsphere.distsql.parser.segment.HostnameAndPortBasedDataSourceSegment;
import
org.apache.shardingsphere.distsql.parser.segment.URLBasedDataSourceSegment;
@@ -31,6 +30,7 @@ import
org.apache.shardingsphere.infra.distsql.exception.resource.InvalidResourc
import org.apache.shardingsphere.infra.distsql.update.RALUpdater;
import
org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
import
org.apache.shardingsphere.infra.util.exception.external.sql.type.generic.UnsupportedSQLOperationException;
+import
org.apache.shardingsphere.infra.util.exception.external.sql.type.wrapper.SQLWrapperException;
import
org.apache.shardingsphere.migration.distsql.statement.AddMigrationSourceResourceStatement;
import
org.apache.shardingsphere.sharding.distsql.handler.converter.ResourceSegmentsConverter;
@@ -57,7 +57,7 @@ public final class AddMigrationSourceResourceUpdater
implements RALUpdater<AddMi
try {
validator.validate(sourcePropertiesMap, databaseType);
} catch (final InvalidResourcesException ex) {
- throw new AddMigrationSourceResourceException(ex);
+ throw new SQLWrapperException(ex);
}
JOB_API.addMigrationSourceResources(sourcePropertiesMap);
}
diff --git
a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/exception/connection/AddMigrationSourceResourceException.java
b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/exception/connection/AddMigrationSourceResourceException.java
index d9bc8d24883..a66739d0f9a 100644
---
a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/exception/connection/AddMigrationSourceResourceException.java
+++
b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/exception/connection/AddMigrationSourceResourceException.java
@@ -17,18 +17,19 @@
package org.apache.shardingsphere.data.pipeline.core.exception.connection;
+import
org.apache.shardingsphere.data.pipeline.core.exception.PipelineSQLException;
+import
org.apache.shardingsphere.infra.util.exception.external.sql.sqlstate.XOpenSQLState;
+
+import java.util.Collection;
+
/**
* Add migration source resource exception.
*/
-public final class AddMigrationSourceResourceException extends
RuntimeException {
+public final class AddMigrationSourceResourceException extends
PipelineSQLException {
private static final long serialVersionUID = -3952313247315105684L;
- public AddMigrationSourceResourceException(final String message) {
- super(message);
- }
-
- public AddMigrationSourceResourceException(final Throwable cause) {
- super(cause);
+ public AddMigrationSourceResourceException(final Collection<String>
duplicateDataSourceNames) {
+ super(XOpenSQLState.DUPLICATE, 30, "Duplicate resource names `%s`",
duplicateDataSourceNames);
}
}
diff --git
a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/migration/MigrationJobAPIImpl.java
b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/migration/MigrationJobAPIImpl.java
index 7b546d2f9b1..827cc74320a 100644
---
a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/migration/MigrationJobAPIImpl.java
+++
b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/migration/MigrationJobAPIImpl.java
@@ -383,9 +383,7 @@ public final class MigrationJobAPIImpl extends
AbstractPipelineJobAPIImpl implem
duplicateDataSourceNames.add(entry.getKey());
}
}
- if (!duplicateDataSourceNames.isEmpty()) {
- throw new
AddMigrationSourceResourceException(String.format("Duplicate resource names
%s.", duplicateDataSourceNames));
- }
+
ShardingSpherePreconditions.checkState(duplicateDataSourceNames.isEmpty(), ()
-> new AddMigrationSourceResourceException(duplicateDataSourceNames));
Map<String, DataSourceProperties> result = new
LinkedHashMap<>(existDataSources);
result.putAll(dataSourcePropsMap);
dataSourcePersistService.persist(getJobType(), result);