RaigorJiang commented on code in PR #23186:
URL: https://github.com/apache/shardingsphere/pull/23186#discussion_r1059272109


##########
features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/update/AlterMaskRuleStatementUpdater.java:
##########
@@ -0,0 +1,102 @@
+/*
+ * 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.mask.distsql.handler.update;
+
+import 
org.apache.shardingsphere.distsql.handler.exception.rule.MissingRequiredRuleException;
+import 
org.apache.shardingsphere.distsql.handler.update.RuleDefinitionAlterUpdater;
+import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
+import 
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
+import 
org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
+import org.apache.shardingsphere.mask.api.config.MaskRuleConfiguration;
+import 
org.apache.shardingsphere.mask.api.config.rule.MaskColumnRuleConfiguration;
+import 
org.apache.shardingsphere.mask.api.config.rule.MaskTableRuleConfiguration;
+import 
org.apache.shardingsphere.mask.distsql.handler.converter.MaskRuleStatementConverter;
+import org.apache.shardingsphere.mask.distsql.parser.segment.MaskRuleSegment;
+import 
org.apache.shardingsphere.mask.distsql.parser.statement.AlterMaskRuleStatement;
+
+import java.util.Collection;
+import java.util.stream.Collectors;
+
+/**
+ * Alter mask rule statement updater.
+ */
+public final class AlterMaskRuleStatementUpdater implements 
RuleDefinitionAlterUpdater<AlterMaskRuleStatement, MaskRuleConfiguration> {
+    
+    @Override
+    public void checkSQLStatement(final ShardingSphereDatabase database, final 
AlterMaskRuleStatement sqlStatement, final MaskRuleConfiguration 
currentRuleConfig) {
+        String databaseName = database.getName();
+        checkCurrentRuleConfiguration(databaseName, currentRuleConfig);
+        checkToBeAlteredRules(databaseName, sqlStatement, currentRuleConfig);
+    }
+    
+    private void checkCurrentRuleConfiguration(final String databaseName, 
final MaskRuleConfiguration currentRuleConfig) throws 
MissingRequiredRuleException {
+        ShardingSpherePreconditions.checkNotNull(currentRuleConfig, () -> new 
MissingRequiredRuleException("Mask", databaseName));
+    }
+    
+    private void checkToBeAlteredRules(final String databaseName, final 
AlterMaskRuleStatement sqlStatement, final MaskRuleConfiguration 
currentRuleConfig) {
+        Collection<String> currentMaskTableNames = 
currentRuleConfig.getTables().stream().map(MaskTableRuleConfiguration::getName).collect(Collectors.toList());
+        Collection<String> notExistedMaskTableNames = 
getToBeAlteredMaskTableNames(sqlStatement).stream().filter(each -> 
!currentMaskTableNames.contains(each)).collect(Collectors.toList());
+        if (!notExistedMaskTableNames.isEmpty()) {

Review Comment:
   Please use `ShardingSpherePreconditions.checkState` to replace `if`



-- 
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