lanchengx commented on a change in pull request #13034:
URL: https://github.com/apache/shardingsphere/pull/13034#discussion_r729801679



##########
File path: 
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/information/AbstractSelectInformationExecutor.java
##########
@@ -81,20 +96,18 @@ public final void execute(final BackendConnection 
backendConnection) throws SQLE
      * Get the source object of the row data.
      *
      * @param schemaName schema name
-     * @return source object of row data
-     * @throws SQLException SQLException
+     * @param FunctionWithException callback
      */
-    protected abstract Object getSourceData(String schemaName) throws 
SQLException;
-    
+    protected abstract void getSourceData(String schemaName, 
FunctionWithException<ResultSet, Void, SQLException> callback) throws 
SQLException;
+
     /**
-     * Construct row data from source data.
+     * Get the source object of the row data.
      *
      * @param schemaName schema name
-     * @param sourceData source data of row data
-     * @throws SQLException SQLException
+     * @param Map rows
      */

Review comment:
       Here we should probably use the parameter name instead of the parameter 
type

##########
File path: 
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/information/AbstractSelectInformationExecutor.java
##########
@@ -50,7 +52,7 @@
  * The abstract class of select information schema, used to define the 
template.
  */
 public abstract class AbstractSelectInformationExecutor implements 
DatabaseAdminQueryExecutor {
-    
+
     @Getter

Review comment:
       Sorry for the late reply, Could you adjust your format? We want to 
modify as little as possible.

##########
File path: 
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/information/FunctionWithException.java
##########
@@ -0,0 +1,34 @@
+/*
+ * 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.proxy.backend.text.admin.mysql.executor.information;
+
+/**
+ * FunctionWithException Interface.
+ */
+@FunctionalInterface
+public interface FunctionWithException<T, R, E extends Exception> {
+
+    /**
+     * apply function.

Review comment:
       The first letter of apply may need to be capitalized.

##########
File path: 
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/information/FunctionWithException.java
##########
@@ -0,0 +1,34 @@
+/*
+ * 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.proxy.backend.text.admin.mysql.executor.information;
+
+/**
+ * FunctionWithException Interface.
+ */

Review comment:
       Interface should probably be lowercase.

##########
File path: 
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/information/AbstractSelectInformationExecutor.java
##########
@@ -145,46 +159,26 @@ public DefaultSelectInformationExecutor(final String sql) 
{
          * Get the source data of the row data.
          *
          * @param schemaName schema name
-         * @return source data of row data
          * @throws SQLException SQLException
          */
         @Override
-        protected Object getSourceData(final String schemaName) throws 
SQLException {
+        protected void getSourceData(final String schemaName, final 
FunctionWithException<ResultSet, Void, SQLException> callback) throws 
SQLException {
             ShardingSphereResource resource = 
ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(schemaName).getResource();
             Optional<Entry<String, DataSource>> dataSourceEntry = 
resource.getDataSources().entrySet().stream().findFirst();
             log.info("Actual SQL: {} ::: {}", 
dataSourceEntry.orElseThrow(DatabaseNotExistedException::new).getKey(), sql);
-            return 
dataSourceEntry.get().getValue().getConnection().prepareStatement(sql).executeQuery();
-        }
-        
-        /**
-         * Construct row data from source data.
-         *
-         * @param schemaName schema name
-         * @param sourceData source data of row data
-         * @throws SQLException SQLException
-         */
-        @Override
-        protected void constructRowData(final String schemaName, final Object 
sourceData) throws SQLException {
-            ResultSet resultSet = (ResultSet) sourceData;
-            while (resultSet.next()) {
-                Map<String, Object> row = new HashMap<>();
-                ResultSetMetaData metaData = resultSet.getMetaData();
-                for (int i = 1; i < metaData.getColumnCount() + 1; i++) {
-                    row.put(resultSet.getMetaData().getColumnName(i), 
resultSet.getString(i));
-                }
-                rowPostProcessing(schemaName, row);
-                if (!row.isEmpty()) {
-                    getRows().addFirst(row);
-                }
+            try (Connection conn = 
dataSourceEntry.get().getValue().getConnection();
+                 PreparedStatement ps = conn.prepareStatement(sql)) {
+                callback.apply(ps.executeQuery());
             }
         }
-        
+

Review comment:
       This line should be indented the same as the previous line

##########
File path: 
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/information/AbstractSelectInformationExecutor.java
##########
@@ -81,20 +96,18 @@ public final void execute(final BackendConnection 
backendConnection) throws SQLE
      * Get the source object of the row data.
      *
      * @param schemaName schema name
-     * @return source object of row data
-     * @throws SQLException SQLException
+     * @param FunctionWithException callback

Review comment:
       Here we should probably use the parameter name instead of the parameter 
type.

##########
File path: 
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/information/AbstractSelectInformationExecutor.java
##########
@@ -59,12 +61,25 @@
     
     @Getter
     private final LinkedList<Map<String, Object>> rows = new LinkedList<>();
-    
+

Review comment:
       This line should be indented the same as the previous line




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