This is an automated email from the ASF dual-hosted git repository.
panjuan 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 60beb55d721 Add UnsupportedEncryptInsertValueException (#20412)
60beb55d721 is described below
commit 60beb55d7214c599e9aec601ac6af24f12a862d9
Author: Liang Zhang <[email protected]>
AuthorDate: Mon Aug 22 19:36:04 2022 +0800
Add UnsupportedEncryptInsertValueException (#20412)
---
.../user-manual/error-code/sql-error-code.cn.md | 1 +
.../user-manual/error-code/sql-error-code.en.md | 1 +
.../UnsupportedEncryptInsertValueException.java | 33 ++++++++++++++++++++++
.../EncryptInsertValueParameterRewriter.java | 9 +++---
.../EncryptInsertValuesTokenGenerator.java | 4 +--
5 files changed, 41 insertions(+), 7 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 493bb92362f..b49a776f249 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
@@ -26,5 +26,6 @@ SQL 错误码以标准的 SQL State,Vendor Code 和详细错误信息提供,
| HY004 | 24000 | Encrypt algorithm \`%s\` initialize failed, reason
is: %s |
| HY004 | 24001 | The SQL clause \`%s\` is unsupported in encrypt
rule |
| 44000 | 24002 | Altered column \`%s\` must use same encrypt
algorithm with previous column \`%s\` in table \`%s\` |
+| 42000 | 24003 | Insert value of index \`%s\` can not support for
encrypt |
| HY004 | 25000 | Shadow column \`%s\` of table \`%s\` does not
support \`%s\` type |
| 42000 | 30000 | Unknown exception: %s |
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 161dc4f16b4..716a4d4fe1c 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
@@ -26,5 +26,6 @@ SQL error codes provide by standard `SQL State`, `Vendor
Code` and `Reason`, whi
| HY004 | 24000 | Encrypt algorithm \`%s\` initialize failed, reason
is: %s |
| HY004 | 24001 | The SQL clause \`%s\` is unsupported in encrypt
rule |
| 44000 | 24002 | Altered column \`%s\` must use same encrypt
algorithm with previous column \`%s\` in table \`%s\` |
+| 42000 | 24003 | Insert value of index \`%s\` can not support for
encrypt |
| HY004 | 25000 | Shadow column \`%s\` of table \`%s\` does not
support \`%s\` type |
| 42000 | 30000 | Unknown exception: %s |
diff --git
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/exception/UnsupportedEncryptInsertValueException.java
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/exception/UnsupportedEncryptInsertValueException.java
new file mode 100644
index 00000000000..407a06f79fa
--- /dev/null
+++
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/exception/UnsupportedEncryptInsertValueException.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.encrypt.exception;
+
+import
org.apache.shardingsphere.infra.util.exception.sql.ShardingSphereSQLException;
+import
org.apache.shardingsphere.infra.util.exception.sql.sqlstate.XOpenSQLState;
+
+/**
+ * Unsupported encrypt insert value exception.
+ */
+public final class UnsupportedEncryptInsertValueException extends
ShardingSphereSQLException {
+
+ private static final long serialVersionUID = 5004882561157380582L;
+
+ public UnsupportedEncryptInsertValueException(final int columnIndex) {
+ super(XOpenSQLState.SYNTAX_ERROR, 24003, "Insert value of index `%s`
can not support for encrypt", String.valueOf(columnIndex));
+ }
+}
diff --git
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/parameter/rewriter/EncryptInsertValueParameterRewriter.java
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/parameter/rewriter/EncryptInsertValueParameterRewriter.java
index 8075a3af411..d89ab9caf88 100644
---
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/parameter/rewriter/EncryptInsertValueParameterRewriter.java
+++
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/parameter/rewriter/EncryptInsertValueParameterRewriter.java
@@ -20,6 +20,7 @@ package
org.apache.shardingsphere.encrypt.rewrite.parameter.rewriter;
import com.google.common.base.Preconditions;
import lombok.Setter;
import org.apache.shardingsphere.encrypt.context.EncryptContextBuilder;
+import
org.apache.shardingsphere.encrypt.exception.UnsupportedEncryptInsertValueException;
import org.apache.shardingsphere.encrypt.rewrite.aware.DatabaseNameAware;
import org.apache.shardingsphere.encrypt.rule.EncryptRule;
import org.apache.shardingsphere.encrypt.rule.aware.EncryptRuleAware;
@@ -28,7 +29,6 @@ import
org.apache.shardingsphere.encrypt.spi.context.EncryptContext;
import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
import
org.apache.shardingsphere.infra.binder.statement.dml.InsertStatementContext;
import org.apache.shardingsphere.infra.database.type.DatabaseTypeEngine;
-import org.apache.shardingsphere.infra.exception.ShardingSphereException;
import
org.apache.shardingsphere.infra.rewrite.parameter.builder.ParameterBuilder;
import
org.apache.shardingsphere.infra.rewrite.parameter.builder.impl.GroupedParameterBuilder;
import
org.apache.shardingsphere.infra.rewrite.parameter.builder.impl.StandardParameterBuilder;
@@ -83,10 +83,9 @@ public final class EncryptInsertValueParameterRewriter
implements ParameterRewri
StandardParameterBuilder standardParameterBuilder =
parameterBuilder.getParameterBuilders().get(count);
ExpressionSegment expressionSegment =
insertStatementContext.getInsertValueContexts().get(count).getValueExpressions().get(columnIndex);
if (expressionSegment instanceof
ParameterMarkerExpressionSegment) {
- encryptInsertValue(
- encryptAlgorithm, assistEncryptAlgorithm,
parameterIndex,
insertStatementContext.getInsertValueContexts().get(count).getLiteralValue(columnIndex)
- .orElseThrow(() -> new
ShardingSphereException("Not support for encrypt!")),
- standardParameterBuilder, encryptContext);
+ Object literalValue =
insertStatementContext.getInsertValueContexts().get(count).getLiteralValue(columnIndex)
+ .orElseThrow(() -> new
UnsupportedEncryptInsertValueException(columnIndex));
+ encryptInsertValue(encryptAlgorithm,
assistEncryptAlgorithm, parameterIndex, literalValue, standardParameterBuilder,
encryptContext);
}
}
count++;
diff --git
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptInsertValuesTokenGenerator.java
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptInsertValuesTokenGenerator.java
index adbc722f163..4ccd01303fd 100644
---
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptInsertValuesTokenGenerator.java
+++
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptInsertValuesTokenGenerator.java
@@ -19,6 +19,7 @@ package
org.apache.shardingsphere.encrypt.rewrite.token.generator;
import lombok.Setter;
import org.apache.shardingsphere.encrypt.context.EncryptContextBuilder;
+import
org.apache.shardingsphere.encrypt.exception.UnsupportedEncryptInsertValueException;
import org.apache.shardingsphere.encrypt.rewrite.aware.DatabaseNameAware;
import
org.apache.shardingsphere.encrypt.rewrite.token.pojo.EncryptInsertValuesToken;
import org.apache.shardingsphere.encrypt.rule.EncryptRule;
@@ -32,7 +33,6 @@ import
org.apache.shardingsphere.infra.binder.segment.insert.values.expression.D
import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
import
org.apache.shardingsphere.infra.binder.statement.dml.InsertStatementContext;
import org.apache.shardingsphere.infra.database.type.DatabaseTypeEngine;
-import org.apache.shardingsphere.infra.exception.ShardingSphereException;
import
org.apache.shardingsphere.infra.rewrite.sql.token.generator.OptionalSQLTokenGenerator;
import
org.apache.shardingsphere.infra.rewrite.sql.token.generator.aware.PreviousSQLTokensAware;
import org.apache.shardingsphere.infra.rewrite.sql.token.pojo.SQLToken;
@@ -134,7 +134,7 @@ public final class EncryptInsertValuesTokenGenerator
implements OptionalSQLToken
if (encryptor.isPresent()) {
int columnIndex = useDefaultInsertColumnsToken.map(optional ->
((UseDefaultInsertColumnsToken) optional).getColumns().indexOf(columnName))
.orElseGet(() ->
insertStatementContext.getColumnNames().indexOf(columnName));
- Object originalValue =
insertValueContext.getLiteralValue(columnIndex).orElseThrow(() -> new
ShardingSphereException("Not support for encrypt!"));
+ Object originalValue =
insertValueContext.getLiteralValue(columnIndex).orElseThrow(() -> new
UnsupportedEncryptInsertValueException(columnIndex));
EncryptContext encryptContext =
EncryptContextBuilder.build(databaseName, schemaName, tableName, columnName);
addPlainColumn(insertValueToken, columnIndex, encryptContext,
insertValueContext, originalValue);
if (encryptRule.findAssistedQueryEncryptor(tableName,
columnName).isPresent()) {