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 f771cd70689 Refactor ShadowSQLException's impl (#30839)
f771cd70689 is described below
commit f771cd70689800a9233f1e26bdc975ee5d0c56ad
Author: Liang Zhang <[email protected]>
AuthorDate: Wed Apr 10 22:56:49 2024 +0800
Refactor ShadowSQLException's impl (#30839)
* Refactor UnsupportedShadowInsertValueException
* Refactor ShadowSQLException's impl
---
.../content/user-manual/error-code/sql-error-code.cn.md | 17 ++++++++---------
.../content/user-manual/error-code/sql-error-code.en.md | 17 ++++++++---------
.../shadow/validator/ShadowValueValidator.java | 5 ++---
.../shadow/checker/ShadowRuleConfigurationChecker.java | 2 +-
.../data/UnsupportedShadowColumnTypeException.java | 2 +-
.../NotImplementHintShadowAlgorithmException.java | 4 ++--
.../syntax/UnsupportedShadowInsertValueException.java | 2 +-
7 files changed, 23 insertions(+), 26 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 5b18fb309f7..1f3d6100411 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
@@ -232,15 +232,14 @@ SQL 错误码以标准的 SQL State,Vendor Code 和详细错误信息提供,
### 影子库
-| Vendor Code | SQL State | 错误信息
|
-|-------------|-----------|---------------------------------------------------------------------------------------------------|
-| 22000 | 42S02 | Production data source configuration does not
exist in database '%s'. |
-| 22001 | 42S02 | Shadow data source configuration does not exist in
database '%s'. |
-| 22002 | 42S02 | No available shadow data sources mappings in
shadow table '%s'. |
-| 22003 | 44000 | Column shadow algorithm \`%s\` operation only
supports one column mapping in shadow table \`%s\`. |
-| 22020 | HY004 | Shadow column \`%s\` of table \`%s\` does not
support \`%s\` type. |
-| 22040 | 42000 | Insert value of index \`%s\` can not support for
shadow. |
-| 22081 | 44000 | Default shadow algorithm class should be implement
HintShadowAlgorithm. |
+| Vendor Code | SQL State | 错误信息
|
+|-------------|-----------|-------------------------------------------------------------------------|
+| 22000 | 42S02 | Production data source configuration does not
exist in database '%s'. |
+| 22001 | 42S02 | Shadow data source configuration does not exist in
database '%s'. |
+| 22002 | 42S02 | No available shadow data sources mappings in
shadow table '%s'. |
+| 22003 | 44000 | Default shadow algorithm class should be implement
HintShadowAlgorithm. |
+| 22010 | HY004 | Shadow column '%s' of table '%s' does not support
'%s' type. |
+| 22020 | 42000 | Insert value of index '%d' can not support for
shadow. |
## 其他异常
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 a7da71987f9..6c14bd9067e 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
@@ -233,15 +233,14 @@ SQL error codes provide by standard `SQL State`, `Vendor
Code` and `Reason`, whi
### Shadow Database
-| Vendor Code | SQL State | Reason
|
-|-------------|-----------|---------------------------------------------------------------------------------------------------|
-| 22000 | 42S02 | Production data source configuration does not
exist in database '%s'. |
-| 22001 | 42S02 | Shadow data source configuration does not exist in
database '%s'. |
-| 22002 | 42S02 | No available shadow data sources mappings in
shadow table '%s'. |
-| 22003 | 44000 | Column shadow algorithm \`%s\` operation only
supports one column mapping in shadow table \`%s\`. |
-| 22020 | HY004 | Shadow column \`%s\` of table \`%s\` does not
support \`%s\` type. |
-| 22040 | 42000 | Insert value of index \`%s\` can not support for
shadow. |
-| 22081 | 44000 | Default shadow algorithm class should be implement
HintShadowAlgorithm. |
+| Vendor Code | SQL State | Reason
|
+|-------------|-----------|-------------------------------------------------------------------------|
+| 22000 | 42S02 | Production data source configuration does not
exist in database '%s'. |
+| 22001 | 42S02 | Shadow data source configuration does not exist in
database '%s'. |
+| 22002 | 42S02 | No available shadow data sources mappings in
shadow table '%s'. |
+| 22003 | 44000 | Default shadow algorithm class should be implement
HintShadowAlgorithm. |
+| 22010 | HY004 | Shadow column '%s' of table '%s' does not support
'%s' type. |
+| 22020 | 42000 | Insert value of index '%d' can not support for
shadow. |
## Other Exception
diff --git
a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/algorithm/shadow/validator/ShadowValueValidator.java
b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/algorithm/shadow/validator/ShadowValueValidator.java
index 3e0b66cbb7b..294edb767bc 100644
---
a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/algorithm/shadow/validator/ShadowValueValidator.java
+++
b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/algorithm/shadow/validator/ShadowValueValidator.java
@@ -19,6 +19,7 @@ package
org.apache.shardingsphere.shadow.algorithm.shadow.validator;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
+import
org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
import
org.apache.shardingsphere.shadow.exception.data.UnsupportedShadowColumnTypeException;
import java.util.Date;
@@ -48,9 +49,7 @@ public final class ShadowValueValidator {
*/
public static void validate(final String table, final String column, final
Comparable<?> shadowValue) {
for (Class<?> each : UNSUPPORTED_TYPES) {
- if (each.isAssignableFrom(shadowValue.getClass())) {
- throw new UnsupportedShadowColumnTypeException(table, column,
each);
- }
+
ShardingSpherePreconditions.checkState(!each.isAssignableFrom(shadowValue.getClass()),
() -> new UnsupportedShadowColumnTypeException(table, column, each));
}
}
}
diff --git
a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/checker/ShadowRuleConfigurationChecker.java
b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/checker/ShadowRuleConfigurationChecker.java
index c789240e91a..44163f69f3f 100644
---
a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/checker/ShadowRuleConfigurationChecker.java
+++
b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/checker/ShadowRuleConfigurationChecker.java
@@ -28,7 +28,7 @@ import
org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration;
import
org.apache.shardingsphere.shadow.api.config.datasource.ShadowDataSourceConfiguration;
import
org.apache.shardingsphere.shadow.api.config.table.ShadowTableConfiguration;
import org.apache.shardingsphere.shadow.constant.ShadowOrder;
-import
org.apache.shardingsphere.shadow.exception.algorithm.NotImplementHintShadowAlgorithmException;
+import
org.apache.shardingsphere.shadow.exception.metadata.NotImplementHintShadowAlgorithmException;
import
org.apache.shardingsphere.shadow.exception.metadata.MissingRequiredProductionDataSourceException;
import
org.apache.shardingsphere.shadow.exception.metadata.MissingRequiredShadowDataSourceException;
import
org.apache.shardingsphere.shadow.exception.metadata.ShadowDataSourceMappingNotFoundException;
diff --git
a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/exception/data/UnsupportedShadowColumnTypeException.java
b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/exception/data/UnsupportedShadowColumnTypeException.java
index 9c4890a52b7..8ab12b68f90 100644
---
a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/exception/data/UnsupportedShadowColumnTypeException.java
+++
b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/exception/data/UnsupportedShadowColumnTypeException.java
@@ -28,6 +28,6 @@ public final class UnsupportedShadowColumnTypeException
extends ShadowSQLExcepti
private static final long serialVersionUID = 8144277065388645946L;
public UnsupportedShadowColumnTypeException(final String tableName, final
String columnName, final Class<?> type) {
- super(XOpenSQLState.INVALID_DATA_TYPE, 20, "Shadow column `%s` of
table `%s` does not support `%s` type.", columnName, tableName, type.getName());
+ super(XOpenSQLState.INVALID_DATA_TYPE, 10, "Shadow column '%s' of
table '%s' does not support '%s' type.", columnName, tableName,
type.getSimpleName());
}
}
diff --git
a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/exception/algorithm/NotImplementHintShadowAlgorithmException.java
b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/exception/metadata/NotImplementHintShadowAlgorithmException.java
similarity index 86%
rename from
features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/exception/algorithm/NotImplementHintShadowAlgorithmException.java
rename to
features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/exception/metadata/NotImplementHintShadowAlgorithmException.java
index 8ed6ef20b32..32c37daf9cb 100644
---
a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/exception/algorithm/NotImplementHintShadowAlgorithmException.java
+++
b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/exception/metadata/NotImplementHintShadowAlgorithmException.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.shadow.exception.algorithm;
+package org.apache.shardingsphere.shadow.exception.metadata;
import
org.apache.shardingsphere.infra.exception.core.external.sql.sqlstate.XOpenSQLState;
import org.apache.shardingsphere.shadow.exception.ShadowSQLException;
@@ -28,6 +28,6 @@ public final class NotImplementHintShadowAlgorithmException
extends ShadowSQLExc
private static final long serialVersionUID = -5012158924968675485L;
public NotImplementHintShadowAlgorithmException() {
- super(XOpenSQLState.CHECK_OPTION_VIOLATION, 81, "Default shadow
algorithm class should be implement HintShadowAlgorithm.");
+ super(XOpenSQLState.CHECK_OPTION_VIOLATION, 3, "Default shadow
algorithm class should be implement HintShadowAlgorithm.");
}
}
diff --git
a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/exception/syntax/UnsupportedShadowInsertValueException.java
b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/exception/syntax/UnsupportedShadowInsertValueException.java
index e6fe695df11..45e112618c0 100644
---
a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/exception/syntax/UnsupportedShadowInsertValueException.java
+++
b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/exception/syntax/UnsupportedShadowInsertValueException.java
@@ -28,6 +28,6 @@ public final class UnsupportedShadowInsertValueException
extends ShadowSQLExcept
private static final long serialVersionUID = -5987403907441367171L;
public UnsupportedShadowInsertValueException(final int columnIndex) {
- super(XOpenSQLState.SYNTAX_ERROR, 40, "Insert value of index `%s` can
not support for shadow.", String.valueOf(columnIndex));
+ super(XOpenSQLState.SYNTAX_ERROR, 20, "Insert value of index '%d' can
not support for shadow.", columnIndex);
}
}