strongduanmu commented on a change in pull request #12372:
URL: https://github.com/apache/shardingsphere/pull/12372#discussion_r707813813



##########
File path: 
shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/EncryptPropertiesBuilder.java
##########
@@ -0,0 +1,40 @@
+/*
+ * 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.rewrite.token;

Review comment:
       @cheese8 EncryptPropertiesBuilder seems to have nothing to do with 
token, should it be moved to `rewrite.util` package?

##########
File path: 
shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/EncryptPropertiesBuilder.java
##########
@@ -0,0 +1,40 @@
+/*
+ * 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.rewrite.token;
+
+import java.util.Properties;
+
+import org.apache.commons.collections4.MapUtils;
+
+import com.google.common.collect.ImmutableMap;
+
+public final class EncryptPropertiesBuilder {
+    
+    /**
+     * Construct properties from schema, owner, table and column.
+     * 
+     * @param schema schema
+     * @param owner owner
+     * @param table table
+     * @param column column
+     * @return Properties which include schema, owner, table and column keys.
+     */
+    public static Properties getProperties(final String schema, final String 
owner, final String table, final String column) {
+        return MapUtils.toProperties(ImmutableMap.of("schema", schema, 
"owner", owner, "table", table, "column", column));

Review comment:
       @cheese8 Can we remove guava method?

##########
File path: 
shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptRule.java
##########
@@ -125,24 +127,35 @@ private boolean 
isValidColumnConfigurationWithAlgorithmProvided(final AlgorithmP
     /**
      * Find encryptor.
      *
+     * @param schemaName schema name
      * @param logicTable logic table name
      * @param logicColumn logic column name
      * @return encryptor
      */
-    public Optional<EncryptAlgorithm> findEncryptor(final String logicTable, 
final String logicColumn) {
-        return tables.containsKey(logicTable) ? 
tables.get(logicTable).findEncryptorName(logicColumn).map(encryptors::get) : 
Optional.empty();
+    public Optional<EncryptAlgorithm> findEncryptor(final String schemaName, 
final String logicTable, final String logicColumn) {
+        if (!tables.containsKey(logicTable)) {
+            return Optional.empty();
+        }
+        Optional<EncryptAlgorithm> optionalEncryptor = 
tables.get(logicTable).findEncryptorName(logicColumn).map(encryptors::get);
+        if (optionalEncryptor.isPresent()) {
+            Properties props = optionalEncryptor.get().getProps();

Review comment:
       @cheese8 Maybe it can be simplified to 
`encryptAlgorithm.ifPresent(optional -> 
optional.getProps().putAll(EncryptPropertiesBuilder.getProperties(schemaName, 
"", logicTable, logicColumn)));`.

##########
File path: 
shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/EncryptPropertiesBuilder.java
##########
@@ -0,0 +1,40 @@
+/*
+ * 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.rewrite.token;
+
+import java.util.Properties;
+
+import org.apache.commons.collections4.MapUtils;
+
+import com.google.common.collect.ImmutableMap;
+
+public final class EncryptPropertiesBuilder {

Review comment:
       @cheese8 Please add java doc for `EncryptPropertiesBuilder`.

##########
File path: 
shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/SQLStatementContextFactory.java
##########
@@ -139,12 +139,12 @@
         throw new UnsupportedOperationException(String.format("Unsupported SQL 
statement `%s`", sqlStatement.getClass().getSimpleName()));
     }
     
-    private static SQLStatementContext<?> getDDLStatementContext(final 
DDLStatement sqlStatement) {
+    private static SQLStatementContext<?> getDDLStatementContext(final 
DDLStatement sqlStatement, final String defaultSchemaName) {
         if (sqlStatement instanceof CreateTableStatement) {
-            return new CreateTableStatementContext((CreateTableStatement) 
sqlStatement);
+            return new CreateTableStatementContext((CreateTableStatement) 
sqlStatement, defaultSchemaName);

Review comment:
       @cheese8 Why ddl statement needs defaultSchemaName param?

##########
File path: 
shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptRule.java
##########
@@ -125,24 +127,35 @@ private boolean 
isValidColumnConfigurationWithAlgorithmProvided(final AlgorithmP
     /**
      * Find encryptor.
      *
+     * @param schemaName schema name
      * @param logicTable logic table name
      * @param logicColumn logic column name
      * @return encryptor
      */
-    public Optional<EncryptAlgorithm> findEncryptor(final String logicTable, 
final String logicColumn) {
-        return tables.containsKey(logicTable) ? 
tables.get(logicTable).findEncryptorName(logicColumn).map(encryptors::get) : 
Optional.empty();
+    public Optional<EncryptAlgorithm> findEncryptor(final String schemaName, 
final String logicTable, final String logicColumn) {
+        if (!tables.containsKey(logicTable)) {
+            return Optional.empty();
+        }
+        Optional<EncryptAlgorithm> optionalEncryptor = 
tables.get(logicTable).findEncryptorName(logicColumn).map(encryptors::get);

Review comment:
       @cheese8 `encryptAlgorithm` may be better.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to