This is an automated email from the ASF dual-hosted git repository.

jianglongtao 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 4db7066e7e9 Add UnsupportedEncryptSQLException (#20340)
4db7066e7e9 is described below

commit 4db7066e7e9ae8fd5d2145f29b02c50fc7683509
Author: Liang Zhang <[email protected]>
AuthorDate: Sun Aug 21 23:33:12 2022 +0800

    Add UnsupportedEncryptSQLException (#20340)
---
 .../user-manual/error-code/sql-error-code.cn.md    |  1 +
 .../user-manual/error-code/sql-error-code.en.md    |  1 +
 .../exception/UnsupportedEncryptSQLException.java  | 33 ++++++++++++++++++++++
 .../rewrite/condition/EncryptConditionEngine.java  |  6 ++--
 .../EncryptInsertOnUpdateTokenGenerator.java       | 10 +++----
 5 files changed, 43 insertions(+), 8 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 358d73962bb..a1807652dd1 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,5 +23,6 @@ SQL 错误码以标准的 SQL State,Vendor Code 和详细错误信息提供,
 | HY000     | 16000       | Can not find pipeline job \`%s\` |
 | HY000     | 16001       | Failed to get DDL for table \`%s\` |
 | HY004     | 24000       | Encrypt algorithm \`%s\` initialize failed, reason 
is: %s |
+| HY004     | 24001       | The SQL clause \`%s\` is unsupported in encrypt 
rule |
 | 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 4c1dabe4cb2..832dd3f6e15 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,5 +23,6 @@ SQL error codes provide by standard `SQL State`, `Vendor 
Code` and `Reason`, whi
 | HY000     | 16000       | Can not find pipeline job \`%s\` |
 | HY000     | 16001       | Failed to get DDL for table \`%s\` |
 | HY004     | 24000       | Encrypt algorithm \`%s\` initialize failed, reason 
is: %s |
+| HY004     | 24001       | The SQL clause \`%s\` is unsupported in encrypt 
rule |
 | 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/UnsupportedEncryptSQLException.java
 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/exception/UnsupportedEncryptSQLException.java
new file mode 100644
index 00000000000..1b7dcd170d0
--- /dev/null
+++ 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/exception/UnsupportedEncryptSQLException.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 SQL exception.
+ */
+public final class UnsupportedEncryptSQLException extends 
ShardingSphereSQLException {
+    
+    private static final long serialVersionUID = 8391663664617661217L;
+    
+    public UnsupportedEncryptSQLException(final String sqlClause) {
+        super(XOpenSQLState.SYNTAX_ERROR, 24001, "The SQL clause `%s` is 
unsupported in encrypt rule", sqlClause);
+    }
+}
diff --git 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/condition/EncryptConditionEngine.java
 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/condition/EncryptConditionEngine.java
index 3047c2d99b8..c3655f1afbc 100644
--- 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/condition/EncryptConditionEngine.java
+++ 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/condition/EncryptConditionEngine.java
@@ -18,13 +18,13 @@
 package org.apache.shardingsphere.encrypt.rewrite.condition;
 
 import lombok.RequiredArgsConstructor;
+import 
org.apache.shardingsphere.encrypt.exception.UnsupportedEncryptSQLException;
 import 
org.apache.shardingsphere.encrypt.rewrite.condition.impl.EncryptEqualCondition;
 import 
org.apache.shardingsphere.encrypt.rewrite.condition.impl.EncryptInCondition;
 import org.apache.shardingsphere.encrypt.rule.EncryptColumn;
 import org.apache.shardingsphere.encrypt.rule.EncryptRule;
 import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
 import org.apache.shardingsphere.infra.database.type.DatabaseTypeEngine;
-import org.apache.shardingsphere.infra.exception.ShardingSphereException;
 import 
org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereSchema;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.BetweenExpression;
@@ -148,7 +148,7 @@ public final class EncryptConditionEngine {
             return createInEncryptCondition(tableName, (InExpression) 
expression, ((InExpression) expression).getRight());
         }
         if (expression instanceof BetweenExpression) {
-            throw new ShardingSphereException("The SQL clause 
'BETWEEN...AND...' is unsupported in encrypt rule.");
+            throw new UnsupportedEncryptSQLException("BETWEEN...AND...");
         }
         return Optional.empty();
     }
@@ -159,7 +159,7 @@ public final class EncryptConditionEngine {
             if (SUPPORTED_COMPARE_OPERATOR.contains(operator)) {
                 return createCompareEncryptCondition(tableName, expression, 
expression.getRight());
             }
-            throw new ShardingSphereException("The SQL clause '%s' is 
unsupported in encrypt rule.", operator);
+            throw new UnsupportedEncryptSQLException(operator);
         }
         return Optional.empty();
     }
diff --git 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptInsertOnUpdateTokenGenerator.java
 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptInsertOnUpdateTokenGenerator.java
index 1e6aabc4341..2f73ef067cd 100644
--- 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptInsertOnUpdateTokenGenerator.java
+++ 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptInsertOnUpdateTokenGenerator.java
@@ -19,6 +19,7 @@ package 
org.apache.shardingsphere.encrypt.rewrite.token.generator;
 
 import com.google.common.base.Preconditions;
 import lombok.Setter;
+import 
org.apache.shardingsphere.encrypt.exception.UnsupportedEncryptSQLException;
 import org.apache.shardingsphere.encrypt.rewrite.aware.DatabaseNameAware;
 import 
org.apache.shardingsphere.encrypt.rewrite.token.pojo.EncryptAssignmentToken;
 import 
org.apache.shardingsphere.encrypt.rewrite.token.pojo.EncryptFunctionAssignmentToken;
@@ -29,7 +30,6 @@ import 
org.apache.shardingsphere.encrypt.rule.aware.EncryptRuleAware;
 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.CollectionSQLTokenGenerator;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.assignment.AssignmentSegment;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment;
@@ -133,24 +133,24 @@ public final class EncryptInsertOnUpdateTokenGenerator 
implements CollectionSQLT
             String cipherValueColumn = encryptRule.getCipherColumn(tableName, 
valueColumn);
             result.addAssignment(cipherColumn, "VALUES(" + cipherValueColumn + 
")");
         } else if (cipherColumnPresent != cipherValueColumnPresent) {
-            throw new ShardingSphereException("The SQL clause `%s` is 
unsupported in encrypt rule.", String.format("%s=VALUES(%s)", column, 
valueColumn));
+            throw new 
UnsupportedEncryptSQLException(String.format("%s=VALUES(%s)", column, 
valueColumn));
         }
         Optional<String> assistedQueryColumn = 
encryptRule.findAssistedQueryColumn(tableName, column);
         Optional<String> valueAssistedQueryColumn = 
encryptRule.findAssistedQueryColumn(tableName, valueColumn);
         if (assistedQueryColumn.isPresent() && 
valueAssistedQueryColumn.isPresent()) {
             result.addAssignment(assistedQueryColumn.get(), "VALUES(" + 
valueAssistedQueryColumn.get() + ")");
         } else if (assistedQueryColumn.isPresent() != 
valueAssistedQueryColumn.isPresent()) {
-            throw new ShardingSphereException("The SQL clause `%s` is 
unsupported in encrypt rule.", String.format("%s=VALUES(%s)", column, 
valueColumn));
+            throw new 
UnsupportedEncryptSQLException(String.format("%s=VALUES(%s)", column, 
valueColumn));
         }
         Optional<String> plainColumn = encryptRule.findPlainColumn(tableName, 
column);
         Optional<String> valuePlainColumn = 
encryptRule.findPlainColumn(tableName, valueColumn);
         if (plainColumn.isPresent() && valuePlainColumn.isPresent()) {
             result.addAssignment(plainColumn.get(), "VALUES(" + 
valuePlainColumn.get() + ")");
         } else if (plainColumn.isPresent() != valuePlainColumn.isPresent()) {
-            throw new ShardingSphereException("The SQL clause `%s` is 
unsupported in encrypt rule.", String.format("%s=VALUES(%s)", column, 
valueColumn));
+            throw new 
UnsupportedEncryptSQLException(String.format("%s=VALUES(%s)", column, 
valueColumn));
         }
         if (result.getAssignment().isEmpty()) {
-            throw new ShardingSphereException("The SQL clause `%s` is 
unsupported in encrypt rule.", String.format("%s=VALUES(%s)", column, 
valueColumn));
+            throw new 
UnsupportedEncryptSQLException(String.format("%s=VALUES(%s)", column, 
valueColumn));
         }
         return result;
     }

Reply via email to