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 5f6d4c79c0311..10f0a577e9057 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 | '%s.'%s' initialization failed, reason is: %s. | +| 44000 | 10012 | Can not find '%s' algorithm on table '%s'. | | 42S02 | 10020 | Schema \`%s\` does not exist. | | 42S02 | 10021 | Single table \`%s\` does not exist. | | HY000 | 10022 | Can not load table with database name \`%s\` and data source name \`%s\`. | @@ -276,12 +277,6 @@ SQL 错误码以标准的 SQL State,Vendor Code 和详细错误信息提供, |-----------|-------------|-------------------------------------------------------------| | 42S02 | 20990 | Invalid mask algorithm \`%s\` in database \`%s\`. | -### 基础算法 - 分布式序列 - -| SQL State | Vendor Code | 错误信息 | -|-----------|-------------|---------------------------------------------------------------------| -| 44000 | 21180 | Can not find strategy for generate keys with table \`%s\`. | - ### 联邦查询 | SQL State | Vendor Code | 错误信息 | 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 094491b21200d..b1ae0044a31dd 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 | '%s.'%s' initialization failed, reason is: %s. | +| 44000 | 10012 | Can not find '%s' algorithm on table '%s'. | | 42S02 | 10020 | Schema \`%s\` does not exist. | | 42S02 | 10021 | Single table \`%s\` does not exist. | | HY000 | 10022 | Can not load table with database name \`%s\` and data source name \`%s\`. | @@ -291,12 +292,6 @@ SQL error codes provide by standard `SQL State`, `Vendor Code` and `Reason`, whi |-----------|-------------|-------------------------------------------------------------| | 42S02 | 20990 | Invalid mask algorithm \`%s\` in database \`%s\`. | -### Infra algorithm - key generate - -| SQL State | Vendor Code | Reason | -|-----------|-------------|---------------------------------------------------------------------| -| 44000 | 21180 | Can not find strategy for generate keys with table \`%s\`. | - ### SQL Federation | SQL State | Vendor Code | Reason | diff --git a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingRule.java b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingRule.java index f7bfe33d37869..b8a13cf8e47a1 100644 --- a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingRule.java +++ b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingRule.java @@ -23,8 +23,8 @@ import lombok.Getter; import org.apache.shardingsphere.infra.algorithm.core.context.AlgorithmSQLContext; import org.apache.shardingsphere.infra.algorithm.core.exception.AlgorithmInitializationException; +import org.apache.shardingsphere.infra.algorithm.core.exception.AlgorithmNotFoundException; import org.apache.shardingsphere.infra.algorithm.keygen.core.KeyGenerateAlgorithm; -import org.apache.shardingsphere.infra.algorithm.keygen.core.exception.GenerateKeyStrategyNotFoundException; import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext; import org.apache.shardingsphere.infra.binder.context.statement.dml.SelectStatementContext; import org.apache.shardingsphere.infra.database.core.type.DatabaseTypeRegistry; @@ -592,7 +592,7 @@ public Collection> generateKeys(final AlgorithmSQLContex private KeyGenerateAlgorithm getKeyGenerateAlgorithm(final String logicTableName) { Optional shardingTable = findShardingTable(logicTableName); - ShardingSpherePreconditions.checkState(shardingTable.isPresent(), () -> new GenerateKeyStrategyNotFoundException(logicTableName)); + ShardingSpherePreconditions.checkState(shardingTable.isPresent(), () -> new AlgorithmNotFoundException("key generator", logicTableName)); return null == shardingTable.get().getKeyGeneratorName() ? defaultKeyGenerateAlgorithm : keyGenerators.get(shardingTable.get().getKeyGeneratorName()); } diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/ShardingRuleTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/ShardingRuleTest.java index 489905fe24c72..d377826f69a8a 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/ShardingRuleTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/ShardingRuleTest.java @@ -21,7 +21,7 @@ import org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfiguration; import org.apache.shardingsphere.infra.algorithm.core.context.AlgorithmSQLContext; import org.apache.shardingsphere.infra.algorithm.core.exception.AlgorithmInitializationException; -import org.apache.shardingsphere.infra.algorithm.keygen.core.exception.GenerateKeyStrategyNotFoundException; +import org.apache.shardingsphere.infra.algorithm.core.exception.AlgorithmNotFoundException; import org.apache.shardingsphere.infra.algorithm.keygen.snowflake.SnowflakeKeyGenerateAlgorithm; import org.apache.shardingsphere.infra.algorithm.keygen.uuid.UUIDKeyGenerateAlgorithm; import org.apache.shardingsphere.infra.binder.context.segment.table.TablesContext; @@ -336,7 +336,7 @@ void assertNotFindGenerateKeyColumn() { void assertGenerateKeyFailure() { AlgorithmSQLContext generateContext = mock(AlgorithmSQLContext.class); when(generateContext.getTableName()).thenReturn("table_0"); - assertThrows(GenerateKeyStrategyNotFoundException.class, () -> createMaximumShardingRule().generateKeys(generateContext, 1)); + assertThrows(AlgorithmNotFoundException.class, () -> createMaximumShardingRule().generateKeys(generateContext, 1)); } @Test diff --git a/infra/algorithm/key-generator/core/src/main/java/org/apache/shardingsphere/infra/algorithm/keygen/core/exception/GenerateKeyStrategyNotFoundException.java b/infra/algorithm/core/src/main/java/org/apache/shardingsphere/infra/algorithm/core/exception/AlgorithmNotFoundException.java similarity index 61% rename from infra/algorithm/key-generator/core/src/main/java/org/apache/shardingsphere/infra/algorithm/keygen/core/exception/GenerateKeyStrategyNotFoundException.java rename to infra/algorithm/core/src/main/java/org/apache/shardingsphere/infra/algorithm/core/exception/AlgorithmNotFoundException.java index ffa90622cd2a3..38cc5717c63af 100644 --- a/infra/algorithm/key-generator/core/src/main/java/org/apache/shardingsphere/infra/algorithm/keygen/core/exception/GenerateKeyStrategyNotFoundException.java +++ b/infra/algorithm/core/src/main/java/org/apache/shardingsphere/infra/algorithm/core/exception/AlgorithmNotFoundException.java @@ -15,18 +15,19 @@ * limitations under the License. */ -package org.apache.shardingsphere.infra.algorithm.keygen.core.exception; +package org.apache.shardingsphere.infra.algorithm.core.exception; import org.apache.shardingsphere.infra.exception.core.external.sql.sqlstate.XOpenSQLState; +import org.apache.shardingsphere.infra.exception.core.external.sql.type.kernel.category.MetaDataSQLException; /** - * Generate key strategy not found exception. + * Algorithm not found exception. */ -public final class GenerateKeyStrategyNotFoundException extends KeyGenerateSQLException { +public final class AlgorithmNotFoundException extends MetaDataSQLException { - private static final long serialVersionUID = 7456922260524630374L; + private static final long serialVersionUID = -6334833729231404326L; - public GenerateKeyStrategyNotFoundException(final String tableName) { - super(XOpenSQLState.CHECK_OPTION_VIOLATION, 80, "Can not find strategy for generate keys with table `%s`.", tableName); + public AlgorithmNotFoundException(final String algorithmType, final String tableName) { + super(XOpenSQLState.CHECK_OPTION_VIOLATION, 12, "Can not find '%s' algorithm on table '%s'.", algorithmType, tableName); } }