Skip to content

Commit

Permalink
Add EmptyAlgorithmOnColumnException (#30645)
Browse files Browse the repository at this point in the history
* Add EmptyAlgorithmOnColumnException

* Add EmptyAlgorithmOnColumnException
  • Loading branch information
terrymanu authored Mar 25, 2024
1 parent e929e05 commit f807e9a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
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.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;
Expand Down Expand Up @@ -72,23 +72,26 @@ 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<String, AlgorithmConfiguration> 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()));
}

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 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()));
}

private void checkLikeColumn(final String databaseName, final String tableName, final String logicColumnName,
final EncryptColumnItemRuleConfiguration likeQueryColumnConfig, final Map<String, AlgorithmConfiguration> 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()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit f807e9a

Please sign in to comment.