From f807e9ad0624460a3f8f87509db32f3a838b9277 Mon Sep 17 00:00:00 2001 From: Liang Zhang Date: Mon, 25 Mar 2024 23:17:48 +0800 Subject: [PATCH] Add EmptyAlgorithmOnColumnException (#30645) * Add EmptyAlgorithmOnColumnException * Add EmptyAlgorithmOnColumnException --- .../user-manual/error-code/sql-error-code.cn.md | 1 + .../user-manual/error-code/sql-error-code.en.md | 1 + .../checker/EncryptRuleConfigurationChecker.java | 11 +++++++---- .../exception/EmptyAlgorithmOnColumnException.java | 14 +++++++------- 4 files changed, 16 insertions(+), 11 deletions(-) rename features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/exception/metadata/MissingEncryptorException.java => infra/algorithm/core/src/main/java/org/apache/shardingsphere/infra/algorithm/core/exception/EmptyAlgorithmOnColumnException.java (57%) 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 4ba68b6ebed9b..300e85e1b4ad8 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 @@ -23,6 +23,7 @@ SQL 错误码以标准的 SQL State,Vendor Code 和详细错误信息提供, | 42S02 | 10007 | Table or view \`%s\` does not exist. | | 42000 | 10010 | Rule does not exist. | | 44000 | 10011 | Algorithm '%s.'%s' initialization failed, reason is: %s. | +| 44000 | 10012 | '%s' algorithm on database.table.column: '%s'.'%s'.'%s' is required. | | 42S02 | 10013 | Can not find '%s' algorithm '%s' on database.table.column: '%s'.'%s'.'%s'. | | HY000 | 10015 | Algorithm '%s.%s' execute failed, reason is: %s. | | 42S02 | 10020 | Schema \`%s\` does not exist. | 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 a9296db14803b..5370722c3e086 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 @@ -23,6 +23,7 @@ SQL error codes provide by standard `SQL State`, `Vendor Code` and `Reason`, whi | 42S02 | 10007 | Table or view \`%s\` does not exist. | | 42000 | 10010 | Rule does not exist. | | 44000 | 10011 | Algorithm '%s.'%s' initialization failed, reason is: %s. | +| 44000 | 10012 | '%s' algorithm on database.table.column: '%s'.'%s'.'%s' is required. | | 42S02 | 10013 | Can not find '%s' algorithm '%s' on database.table.column: '%s'.'%s'.'%s'. | | HY000 | 10015 | Algorithm '%s.%s' execute failed, reason is: %s. | | 42S02 | 10020 | Schema \`%s\` does not exist. | diff --git a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/checker/EncryptRuleConfigurationChecker.java b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/checker/EncryptRuleConfigurationChecker.java index c0f0abe98b4d6..32cbd77d4f137 100644 --- a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/checker/EncryptRuleConfigurationChecker.java +++ b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/checker/EncryptRuleConfigurationChecker.java @@ -26,10 +26,10 @@ import org.apache.shardingsphere.encrypt.exception.metadata.EncryptAssistedQueryColumnNotFoundException; import org.apache.shardingsphere.encrypt.exception.metadata.EncryptCipherColumnNotFoundException; import org.apache.shardingsphere.encrypt.exception.metadata.EncryptLikeQueryColumnNotFoundException; -import org.apache.shardingsphere.encrypt.exception.metadata.MissingEncryptorException; import org.apache.shardingsphere.encrypt.exception.metadata.UnregisteredEncryptorException; import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm; import org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfiguration; +import org.apache.shardingsphere.infra.algorithm.core.exception.EmptyAlgorithmOnColumnException; import org.apache.shardingsphere.infra.config.rule.checker.RuleConfigurationChecker; import org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions; import org.apache.shardingsphere.infra.rule.ShardingSphereRule; @@ -72,7 +72,8 @@ private void checkColumn(final String databaseName, final String tableName, fina private void checkCipherColumn(final String databaseName, final String tableName, final String logicColumnName, final EncryptColumnItemRuleConfiguration cipherColumnConfig, final Map encryptors) { ShardingSpherePreconditions.checkState(!Strings.isNullOrEmpty(cipherColumnConfig.getName()), () -> new EncryptCipherColumnNotFoundException(logicColumnName, databaseName)); - ShardingSpherePreconditions.checkState(!Strings.isNullOrEmpty(cipherColumnConfig.getEncryptorName()), () -> new MissingEncryptorException(tableName, logicColumnName, "STANDARD")); + ShardingSpherePreconditions.checkState(!Strings.isNullOrEmpty(cipherColumnConfig.getEncryptorName()), + () -> new EmptyAlgorithmOnColumnException("Standard encrypt", databaseName, tableName, logicColumnName)); ShardingSpherePreconditions.checkState(encryptors.containsKey(cipherColumnConfig.getEncryptorName()), () -> new UnregisteredEncryptorException(databaseName, cipherColumnConfig.getEncryptorName())); } @@ -80,7 +81,8 @@ private void checkCipherColumn(final String databaseName, final String tableName private void checkAssistColumn(final String databaseName, final String tableName, final String logicColumnName, final EncryptColumnItemRuleConfiguration assistedQueryColumnConfig, final Map encryptors) { ShardingSpherePreconditions.checkState(!Strings.isNullOrEmpty(assistedQueryColumnConfig.getName()), () -> new EncryptAssistedQueryColumnNotFoundException(logicColumnName, databaseName)); - ShardingSpherePreconditions.checkState(!Strings.isNullOrEmpty(assistedQueryColumnConfig.getEncryptorName()), () -> new MissingEncryptorException(tableName, logicColumnName, "ASSIST_QUERY")); + ShardingSpherePreconditions.checkState(!Strings.isNullOrEmpty(assistedQueryColumnConfig.getEncryptorName()), + () -> new EmptyAlgorithmOnColumnException("Assist query encrypt", databaseName, tableName, logicColumnName)); ShardingSpherePreconditions.checkState( encryptors.containsKey(assistedQueryColumnConfig.getEncryptorName()), () -> new UnregisteredEncryptorException(databaseName, assistedQueryColumnConfig.getEncryptorName())); } @@ -88,7 +90,8 @@ private void checkAssistColumn(final String databaseName, final String tableName private void checkLikeColumn(final String databaseName, final String tableName, final String logicColumnName, final EncryptColumnItemRuleConfiguration likeQueryColumnConfig, final Map encryptors) { ShardingSpherePreconditions.checkState(!Strings.isNullOrEmpty(likeQueryColumnConfig.getName()), () -> new EncryptLikeQueryColumnNotFoundException(logicColumnName, databaseName)); - ShardingSpherePreconditions.checkState(!Strings.isNullOrEmpty(likeQueryColumnConfig.getEncryptorName()), () -> new MissingEncryptorException(tableName, logicColumnName, "LIKE_QUERY")); + ShardingSpherePreconditions.checkState(!Strings.isNullOrEmpty(likeQueryColumnConfig.getEncryptorName()), + () -> new EmptyAlgorithmOnColumnException("Like query", databaseName, tableName, logicColumnName)); ShardingSpherePreconditions.checkState(encryptors.containsKey(likeQueryColumnConfig.getEncryptorName()), () -> new UnregisteredEncryptorException(databaseName, likeQueryColumnConfig.getEncryptorName())); } diff --git a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/exception/metadata/MissingEncryptorException.java b/infra/algorithm/core/src/main/java/org/apache/shardingsphere/infra/algorithm/core/exception/EmptyAlgorithmOnColumnException.java similarity index 57% rename from features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/exception/metadata/MissingEncryptorException.java rename to infra/algorithm/core/src/main/java/org/apache/shardingsphere/infra/algorithm/core/exception/EmptyAlgorithmOnColumnException.java index a52cf6989a69a..b2de509faf7ea 100644 --- a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/exception/metadata/MissingEncryptorException.java +++ b/infra/algorithm/core/src/main/java/org/apache/shardingsphere/infra/algorithm/core/exception/EmptyAlgorithmOnColumnException.java @@ -15,19 +15,19 @@ * limitations under the License. */ -package org.apache.shardingsphere.encrypt.exception.metadata; +package org.apache.shardingsphere.infra.algorithm.core.exception; -import org.apache.shardingsphere.encrypt.exception.EncryptSQLException; import org.apache.shardingsphere.infra.exception.core.external.sql.sqlstate.XOpenSQLState; +import org.apache.shardingsphere.infra.exception.core.external.sql.type.kernel.category.MetaDataSQLException; /** - * Missing encryptor exception. + * Empty algorithm on column exception. */ -public final class MissingEncryptorException extends EncryptSQLException { +public final class EmptyAlgorithmOnColumnException extends MetaDataSQLException { - private static final long serialVersionUID = -4847495252826650747L; + private static final long serialVersionUID = 8128067899672436211L; - public MissingEncryptorException(final String tableName, final String logicColumnName, final String encryptorType) { - super(XOpenSQLState.CHECK_OPTION_VIOLATION, 4, "Can not find %s encryptor in table `%s` and column `%s`.", encryptorType, tableName, logicColumnName); + public EmptyAlgorithmOnColumnException(final String algorithmType, final String databaseName, final String tableName, final String columnName) { + super(XOpenSQLState.NOT_FOUND, 12, "'%s' algorithm on database.table.column: '%s'.'%s'.'%s' is required.", algorithmType, databaseName, tableName, columnName); } }