Skip to content

Commit

Permalink
Refactor UnregisteredAlgorithmException (#30646)
Browse files Browse the repository at this point in the history
* Refactor UnregisteredAlgorithmException

* Refactor UnregisteredAlgorithmException
  • Loading branch information
terrymanu authored Mar 25, 2024
1 parent f807e9a commit 6bb6e16
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ SQL 错误码以标准的 SQL State,Vendor Code 和详细错误信息提供,
| 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'. |
| 42S02 | 10013 | '%s' algorithm '%s' on database.table.column: '%s'.'%s'.'%s' is unregistered. |
| HY000 | 10015 | Algorithm '%s.%s' execute failed, reason is: %s. |
| 42S02 | 10020 | Schema \`%s\` does not exist. |
| 42S02 | 10021 | Single table \`%s\` does not exist. |
Expand Down Expand Up @@ -269,7 +269,6 @@ SQL 错误码以标准的 SQL State,Vendor Code 和详细错误信息提供,
| 44000 | 20705 | Assisted query column of \`%s\` can not be null in database \`%s\`. |
| 44000 | 20707 | Like query column of \`%s\` can not be null in database \`%s\`. |
| 44000 | 20709 | Can not find encrypt table: \`%s\`. |
| 44000 | 20710 | Can not found registered encryptor \`%s\` in database \`%s\`. |

### 影子库

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ SQL error codes provide by standard `SQL State`, `Vendor Code` and `Reason`, whi
| 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'. |
| 42S02 | 10013 | '%s' algorithm '%s' on database.table.column: '%s'.'%s'.'%s' is unregistered. |
| HY000 | 10015 | Algorithm '%s.%s' execute failed, reason is: %s. |
| 42S02 | 10020 | Schema \`%s\` does not exist. |
| 42S02 | 10021 | Single table \`%s\` does not exist. |
Expand Down Expand Up @@ -284,7 +284,6 @@ SQL error codes provide by standard `SQL State`, `Vendor Code` and `Reason`, whi
| 44000 | 20705 | Assisted query column of \`%s\` can not be null in database \`%s\`. |
| 44000 | 20707 | Like query column of \`%s\` can not be null in database \`%s\`. |
| 44000 | 20709 | Can not find encrypt table: \`%s\`. |
| 44000 | 20710 | Can not found registered encryptor \`%s\` in database \`%s\`. |

### Shadow Database

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.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.algorithm.core.exception.UnregisteredAlgorithmException;
import org.apache.shardingsphere.infra.config.rule.checker.RuleConfigurationChecker;
import org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
Expand Down Expand Up @@ -75,16 +75,16 @@ private void checkCipherColumn(final String databaseName, final String tableName
ShardingSpherePreconditions.checkState(!Strings.isNullOrEmpty(cipherColumnConfig.getEncryptorName()),
() -> new EmptyAlgorithmOnColumnException("Standard encrypt", databaseName, tableName, logicColumnName));
ShardingSpherePreconditions.checkState(encryptors.containsKey(cipherColumnConfig.getEncryptorName()),
() -> new UnregisteredEncryptorException(databaseName, cipherColumnConfig.getEncryptorName()));
() -> new UnregisteredAlgorithmException("Standard encrypt", cipherColumnConfig.getEncryptorName(), databaseName, tableName, logicColumnName));
}

private void checkAssistColumn(final String databaseName, final String tableName, final String logicColumnName,
final EncryptColumnItemRuleConfiguration assistedQueryColumnConfig, final Map<String, AlgorithmConfiguration> encryptors) {
ShardingSpherePreconditions.checkState(!Strings.isNullOrEmpty(assistedQueryColumnConfig.getName()), () -> new EncryptAssistedQueryColumnNotFoundException(logicColumnName, databaseName));
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()));
ShardingSpherePreconditions.checkState(encryptors.containsKey(assistedQueryColumnConfig.getEncryptorName()),
() -> new UnregisteredAlgorithmException("Assist query encrypt", assistedQueryColumnConfig.getEncryptorName(), databaseName, tableName, logicColumnName));
}

private void checkLikeColumn(final String databaseName, final String tableName, final String logicColumnName,
Expand All @@ -93,7 +93,7 @@ private void checkLikeColumn(final String databaseName, final String tableName,
ShardingSpherePreconditions.checkState(!Strings.isNullOrEmpty(likeQueryColumnConfig.getEncryptorName()),
() -> new EmptyAlgorithmOnColumnException("Like query", databaseName, tableName, logicColumnName));
ShardingSpherePreconditions.checkState(encryptors.containsKey(likeQueryColumnConfig.getEncryptorName()),
() -> new UnregisteredEncryptorException(databaseName, likeQueryColumnConfig.getEncryptorName()));
() -> new UnregisteredAlgorithmException("Like query encrypt", likeQueryColumnConfig.getEncryptorName(), databaseName, tableName, logicColumnName));
}

@Override
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
import org.apache.shardingsphere.encrypt.api.config.rule.EncryptColumnItemRuleConfiguration;
import org.apache.shardingsphere.encrypt.api.config.rule.EncryptColumnRuleConfiguration;
import org.apache.shardingsphere.encrypt.api.config.rule.EncryptTableRuleConfiguration;
import org.apache.shardingsphere.encrypt.exception.metadata.UnregisteredEncryptorException;
import org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.algorithm.core.exception.UnregisteredAlgorithmException;
import org.apache.shardingsphere.infra.config.rule.checker.RuleConfigurationChecker;
import org.apache.shardingsphere.infra.spi.type.ordered.OrderedSPILoader;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -59,7 +59,7 @@ private EncryptRuleConfiguration createValidConfiguration() {
void assertCheckWhenConfigInvalidCipherColumn() {
EncryptRuleConfiguration config = createInvalidCipherColumnConfig();
RuleConfigurationChecker checker = OrderedSPILoader.getServicesByClass(RuleConfigurationChecker.class, Collections.singleton(config.getClass())).get(config.getClass());
assertThrows(UnregisteredEncryptorException.class, () -> checker.check("test", config, Collections.emptyMap(), Collections.emptyList()));
assertThrows(UnregisteredAlgorithmException.class, () -> checker.check("test", config, Collections.emptyMap(), Collections.emptyList()));
}

private EncryptRuleConfiguration createInvalidCipherColumnConfig() {
Expand All @@ -76,7 +76,7 @@ private EncryptRuleConfiguration createInvalidCipherColumnConfig() {
void assertCheckWhenConfigInvalidAssistColumn() {
EncryptRuleConfiguration config = createInvalidAssistColumnConfig();
RuleConfigurationChecker checker = OrderedSPILoader.getServicesByClass(RuleConfigurationChecker.class, Collections.singleton(config.getClass())).get(config.getClass());
assertThrows(UnregisteredEncryptorException.class, () -> checker.check("test", config, Collections.emptyMap(), Collections.emptyList()));
assertThrows(UnregisteredAlgorithmException.class, () -> checker.check("test", config, Collections.emptyMap(), Collections.emptyList()));
}

private EncryptRuleConfiguration createInvalidAssistColumnConfig() {
Expand All @@ -94,7 +94,7 @@ private EncryptRuleConfiguration createInvalidAssistColumnConfig() {
void assertCheckWhenConfigInvalidLikeColumn() {
EncryptRuleConfiguration config = createInvalidLikeColumnConfig();
RuleConfigurationChecker checker = OrderedSPILoader.getServicesByClass(RuleConfigurationChecker.class, Collections.singleton(config.getClass())).get(config.getClass());
assertThrows(UnregisteredEncryptorException.class, () -> checker.check("test", config, Collections.emptyMap(), Collections.emptyList()));
assertThrows(UnregisteredAlgorithmException.class, () -> checker.check("test", config, Collections.emptyMap(), Collections.emptyList()));
}

private EncryptRuleConfiguration createInvalidLikeColumnConfig() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package org.apache.shardingsphere.mask.checker;

import org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.algorithm.core.exception.AlgorithmNotFoundOnColumnException;
import org.apache.shardingsphere.infra.algorithm.core.exception.UnregisteredAlgorithmException;
import org.apache.shardingsphere.infra.config.rule.checker.RuleConfigurationChecker;
import org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
Expand Down Expand Up @@ -59,7 +59,7 @@ private void checkColumns(final String databaseName, final MaskTableRuleConfigur

private void checkColumn(final String databaseName, final String tableName, final MaskColumnRuleConfiguration columnRuleConfig, final Map<String, AlgorithmConfiguration> maskAlgorithms) {
ShardingSpherePreconditions.checkState(maskAlgorithms.containsKey(columnRuleConfig.getMaskAlgorithm()),
() -> new AlgorithmNotFoundOnColumnException("mask", columnRuleConfig.getMaskAlgorithm(), databaseName, tableName, columnRuleConfig.getLogicColumn()));
() -> new UnregisteredAlgorithmException("Mask", columnRuleConfig.getMaskAlgorithm(), databaseName, tableName, columnRuleConfig.getLogicColumn()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
import org.apache.shardingsphere.infra.exception.core.external.sql.type.kernel.category.MetaDataSQLException;

/**
* Algorithm not found on column exception.
* Unregistered algorithm exception.
*/
public final class AlgorithmNotFoundOnColumnException extends MetaDataSQLException {
public final class UnregisteredAlgorithmException extends MetaDataSQLException {

private static final long serialVersionUID = -4570489906443880879L;

public AlgorithmNotFoundOnColumnException(final String algorithmType, final String algorithmName, final String databaseName, final String tableName, final String columnName) {
public UnregisteredAlgorithmException(final String algorithmType, final String algorithmName, final String databaseName, final String tableName, final String columnName) {
super(XOpenSQLState.NOT_FOUND, 13,
"Can not find '%s' algorithm '%s' on database.table.column: '%s'.'%s'.'%s'.", algorithmType, algorithmName, databaseName, tableName, columnName);
"'%s' algorithm '%s' on database.table.column: '%s'.'%s'.'%s' is unregistered.", algorithmType, algorithmName, databaseName, tableName, columnName);
}
}

0 comments on commit 6bb6e16

Please sign in to comment.