RaigorJiang commented on a change in pull request #15415:
URL: https://github.com/apache/shardingsphere/pull/15415#discussion_r806702912



##########
File path: 
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/RALBackendHandlerFactory.java
##########
@@ -24,22 +24,42 @@
 import 
org.apache.shardingsphere.distsql.parser.statement.ral.QueryableRALStatement;
 import org.apache.shardingsphere.distsql.parser.statement.ral.RALStatement;
 import 
org.apache.shardingsphere.distsql.parser.statement.ral.UpdatableRALStatement;
+import 
org.apache.shardingsphere.distsql.parser.statement.ral.common.alter.AlterSQLParserRuleStatement;
+import 
org.apache.shardingsphere.distsql.parser.statement.ral.common.alter.AlterTransactionRuleStatement;
+import 
org.apache.shardingsphere.distsql.parser.statement.rdl.create.AlterTrafficRuleStatement;
+import 
org.apache.shardingsphere.distsql.parser.statement.rdl.create.CreateTrafficRuleStatement;
 import org.apache.shardingsphere.infra.database.type.DatabaseType;
 import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
 import org.apache.shardingsphere.proxy.backend.text.TextProtocolBackendHandler;
+import 
org.apache.shardingsphere.proxy.backend.text.distsql.ral.RALBackendHandler.HandlerParameter;
 import 
org.apache.shardingsphere.proxy.backend.text.distsql.ral.advanced.AdvancedDistSQLBackendHandlerFactory;
-import 
org.apache.shardingsphere.proxy.backend.text.distsql.ral.query.QueryableRALBackendHandlerFactory;
 import 
org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.CommonDistSQLBackendHandlerFactory;
-import 
org.apache.shardingsphere.proxy.backend.text.distsql.ral.update.UpdatableRALBackendHandlerFactory;
+import 
org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.updatable.AlterSQLParserRuleHandler;
+import 
org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.updatable.AlterTrafficRuleHandler;
+import 
org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.updatable.AlterTransactionRuleHandler;
+import 
org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.updatable.CreateTrafficRuleHandler;
+import 
org.apache.shardingsphere.proxy.backend.text.distsql.ral.query.ScalingQueryableRALBackendHandlerFactory;
+import 
org.apache.shardingsphere.proxy.backend.text.distsql.ral.update.ScalingUpdatableRALBackendHandlerFactory;
 
 import java.sql.SQLException;
+import java.util.LinkedHashMap;
+import java.util.Map;
 
 /**
  * RAL backend handler factory.
  */
 @NoArgsConstructor(access = AccessLevel.PRIVATE)
 public final class RALBackendHandlerFactory {
     
+    private static Map<String, Class<? extends RALBackendHandler>> handlerClz 
= new LinkedHashMap<>();

Review comment:
       Is handlerMap better?  (than handlerClz)

##########
File path: 
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/RALBackendHandlerFactory.java
##########
@@ -50,18 +70,39 @@
      * @throws SQLException SQL exception
      */
     public static TextProtocolBackendHandler newInstance(final DatabaseType 
databaseType, final RALStatement sqlStatement, final ConnectionSession 
connectionSession) throws SQLException {
+        TextProtocolBackendHandler result = null;
         if (sqlStatement instanceof QueryableRALStatement) {
-            return 
QueryableRALBackendHandlerFactory.newInstance((QueryableRALStatement) 
sqlStatement, connectionSession);
+            result = 
ScalingQueryableRALBackendHandlerFactory.newInstance((QueryableRALStatement) 
sqlStatement, connectionSession);
         }
         if (sqlStatement instanceof UpdatableRALStatement) {
-            return 
UpdatableRALBackendHandlerFactory.newInstance((UpdatableRALStatement) 
sqlStatement);
+            result = 
ScalingUpdatableRALBackendHandlerFactory.newInstance((UpdatableRALStatement) 
sqlStatement);
         }
         if (sqlStatement instanceof CommonDistSQLStatement) {
-            return 
CommonDistSQLBackendHandlerFactory.newInstance((CommonDistSQLStatement) 
sqlStatement, connectionSession);
+            result = 
CommonDistSQLBackendHandlerFactory.newInstance((CommonDistSQLStatement) 
sqlStatement, connectionSession);
         }
         if (sqlStatement instanceof AdvancedDistSQLStatement) {
-            return 
AdvancedDistSQLBackendHandlerFactory.newInstance(databaseType, 
(AdvancedDistSQLStatement) sqlStatement, connectionSession);
+            result = 
AdvancedDistSQLBackendHandlerFactory.newInstance(databaseType, 
(AdvancedDistSQLStatement) sqlStatement, connectionSession);
+        }
+        if (result == null) {
+            HandlerParameter parameter = new 
HandlerParameter().setStatement(sqlStatement).setConnectionSession(connectionSession).setDatabaseType(databaseType);

Review comment:
       Could it be more concise if using the constructor?

##########
File path: 
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/RALBackendHandlerFactory.java
##########
@@ -50,18 +70,39 @@
      * @throws SQLException SQL exception
      */
     public static TextProtocolBackendHandler newInstance(final DatabaseType 
databaseType, final RALStatement sqlStatement, final ConnectionSession 
connectionSession) throws SQLException {
+        TextProtocolBackendHandler result = null;
         if (sqlStatement instanceof QueryableRALStatement) {
-            return 
QueryableRALBackendHandlerFactory.newInstance((QueryableRALStatement) 
sqlStatement, connectionSession);
+            result = 
ScalingQueryableRALBackendHandlerFactory.newInstance((QueryableRALStatement) 
sqlStatement, connectionSession);
         }
         if (sqlStatement instanceof UpdatableRALStatement) {
-            return 
UpdatableRALBackendHandlerFactory.newInstance((UpdatableRALStatement) 
sqlStatement);
+            result = 
ScalingUpdatableRALBackendHandlerFactory.newInstance((UpdatableRALStatement) 
sqlStatement);
         }
         if (sqlStatement instanceof CommonDistSQLStatement) {
-            return 
CommonDistSQLBackendHandlerFactory.newInstance((CommonDistSQLStatement) 
sqlStatement, connectionSession);
+            result = 
CommonDistSQLBackendHandlerFactory.newInstance((CommonDistSQLStatement) 
sqlStatement, connectionSession);
         }
         if (sqlStatement instanceof AdvancedDistSQLStatement) {
-            return 
AdvancedDistSQLBackendHandlerFactory.newInstance(databaseType, 
(AdvancedDistSQLStatement) sqlStatement, connectionSession);
+            result = 
AdvancedDistSQLBackendHandlerFactory.newInstance(databaseType, 
(AdvancedDistSQLStatement) sqlStatement, connectionSession);
+        }
+        if (result == null) {
+            HandlerParameter parameter = new 
HandlerParameter().setStatement(sqlStatement).setConnectionSession(connectionSession).setDatabaseType(databaseType);
+            result = getHandler(sqlStatement, parameter);
+        }
+        return result;
+    }
+    
+    private static RALBackendHandler newInstance(final Class<? extends 
RALBackendHandler> clazz) {
+        try {
+            return clazz.newInstance();
+        } catch (final InstantiationException | IllegalAccessException ex) {
+            throw new UnsupportedOperationException(String.format("Can not 
find public constructor for class `%s`", clazz.getName()));
+        }
+    }
+    
+    private static RALBackendHandler getHandler(final RALStatement 
sqlStatement, final HandlerParameter<RALStatement> parameter) {
+        Class<? extends RALBackendHandler> clz = 
handlerClz.get(sqlStatement.getClass().getName());
+        if (null == clz) {

Review comment:
       `clazz` may be a more common name

##########
File path: 
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/query/ScalingQueryableRALBackendHandler.java
##########
@@ -32,13 +32,13 @@
 import java.util.List;
 
 /**
- * Queryable RAL backend handler.
+ * Scaling queryable RAL backend handler.

Review comment:
       If `Queryable  Scaling RAL backend handler` will 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