You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by du...@apache.org on 2022/06/16 09:30:16 UTC

[shardingsphere] branch master updated: Refactor ShowTrafficRulesStatement (#18392)

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

duanzhengqiang 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 cd3e0b20e9d Refactor ShowTrafficRulesStatement (#18392)
cd3e0b20e9d is described below

commit cd3e0b20e9d85bcb17d5e2ca3a3a7c388384e5e3
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Thu Jun 16 17:30:09 2022 +0800

    Refactor ShowTrafficRulesStatement (#18392)
---
 .../distsql/parser/core/common/CommonDistSQLStatementVisitor.java | 6 +-----
 .../statement/ral/common/queryable/ShowTrafficRulesStatement.java | 8 ++++----
 .../distsql/ral/common/queryable/ShowTrafficRulesHandlerTest.java | 4 +---
 3 files changed, 6 insertions(+), 12 deletions(-)

diff --git a/shardingsphere-distsql/shardingsphere-distsql-parser/src/main/java/org/apache/shardingsphere/distsql/parser/core/common/CommonDistSQLStatementVisitor.java b/shardingsphere-distsql/shardingsphere-distsql-parser/src/main/java/org/apache/shardingsphere/distsql/parser/core/common/CommonDistSQLStatementVisitor.java
index 2e69e7c4695..eb845df3f83 100644
--- a/shardingsphere-distsql/shardingsphere-distsql-parser/src/main/java/org/apache/shardingsphere/distsql/parser/core/common/CommonDistSQLStatementVisitor.java
+++ b/shardingsphere-distsql/shardingsphere-distsql-parser/src/main/java/org/apache/shardingsphere/distsql/parser/core/common/CommonDistSQLStatementVisitor.java
@@ -390,11 +390,7 @@ public final class CommonDistSQLStatementVisitor extends CommonDistSQLStatementB
     
     @Override
     public ASTNode visitShowTrafficRules(final ShowTrafficRulesContext ctx) {
-        ShowTrafficRulesStatement result = new ShowTrafficRulesStatement();
-        if (null != ctx.ruleName()) {
-            result.setRuleName(getIdentifierValue(ctx.ruleName()));
-        }
-        return result;
+        return new ShowTrafficRulesStatement(null == ctx.ruleName() ? null : getIdentifierValue(ctx.ruleName()));
     }
     
     @Override
diff --git a/shardingsphere-distsql/shardingsphere-distsql-statement/src/main/java/org/apache/shardingsphere/distsql/parser/statement/ral/common/queryable/ShowTrafficRulesStatement.java b/shardingsphere-distsql/shardingsphere-distsql-statement/src/main/java/org/apache/shardingsphere/distsql/parser/statement/ral/common/queryable/ShowTrafficRulesStatement.java
index 7064b250e4a..f7dff1b3d93 100644
--- a/shardingsphere-distsql/shardingsphere-distsql-statement/src/main/java/org/apache/shardingsphere/distsql/parser/statement/ral/common/queryable/ShowTrafficRulesStatement.java
+++ b/shardingsphere-distsql/shardingsphere-distsql-statement/src/main/java/org/apache/shardingsphere/distsql/parser/statement/ral/common/queryable/ShowTrafficRulesStatement.java
@@ -18,15 +18,15 @@
 package org.apache.shardingsphere.distsql.parser.statement.ral.common.queryable;
 
 import lombok.Getter;
-import lombok.Setter;
+import lombok.RequiredArgsConstructor;
 import org.apache.shardingsphere.distsql.parser.statement.ral.QueryableRALStatement;
 
 /**
  * Show traffic rules statement.
  */
+@RequiredArgsConstructor
+@Getter
 public final class ShowTrafficRulesStatement extends QueryableRALStatement {
     
-    @Getter
-    @Setter
-    private String ruleName;
+    private final String ruleName;
 }
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ShowTrafficRulesHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ShowTrafficRulesHandlerTest.java
index 4c339386bdc..c705ff719f2 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ShowTrafficRulesHandlerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ShowTrafficRulesHandlerTest.java
@@ -45,10 +45,8 @@ public class ShowTrafficRulesHandlerTest extends ProxyContextRestorer {
     
     @Test
     public void assertExecute() throws SQLException {
-        ShowTrafficRulesStatement showTrafficRuleStatement = new ShowTrafficRulesStatement();
-        showTrafficRuleStatement.setRuleName("rule_name_1");
         ShowTrafficRulesHandler handler = new ShowTrafficRulesHandler();
-        handler.init(showTrafficRuleStatement, null);
+        handler.init(new ShowTrafficRulesStatement("rule_name_1"), null);
         ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS);
         TrafficRule rule = mock(TrafficRule.class);
         when(rule.getConfiguration()).thenReturn(createTrafficRuleConfiguration());