tuichenchuxin commented on a change in pull request #15457:
URL: https://github.com/apache/shardingsphere/pull/15457#discussion_r826629911



##########
File path: 
shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/result/query/impl/driver/jdbc/type/memory/JDBCMemoryQueryResult.java
##########
@@ -17,18 +17,35 @@
 
 package 
org.apache.shardingsphere.infra.executor.sql.execute.result.query.impl.driver.jdbc.type.memory;
 
-import 
org.apache.shardingsphere.infra.executor.sql.execute.result.query.impl.driver.jdbc.metadata.JDBCQueryResultMetaData;
-import 
org.apache.shardingsphere.infra.executor.sql.execute.result.query.type.memory.AbstractMemoryQueryResult;
-
 import java.sql.ResultSet;
 import java.sql.SQLException;
+import java.util.Calendar;
+
+import 
org.apache.shardingsphere.infra.executor.sql.execute.result.query.impl.driver.jdbc.metadata.JDBCQueryResultMetaData;
+import 
org.apache.shardingsphere.infra.executor.sql.execute.result.query.type.convert.memory.JDBCMemoryTypeHandlerFactory;
+import 
org.apache.shardingsphere.infra.executor.sql.execute.result.query.type.memory.AbstractMemoryQueryResult;
 
 /**
  * JDBC query result for memory loading.
  */
 public final class JDBCMemoryQueryResult extends AbstractMemoryQueryResult {
-    
+
+    private final JDBCMemoryTypeHandlerFactory typeHandlerFactory;
+
     public JDBCMemoryQueryResult(final ResultSet resultSet) throws 
SQLException {
-        super(new JDBCQueryResultMetaData(resultSet.getMetaData()), 
JDBCRowsLoader.load(resultSet.getMetaData().getColumnCount(), 
resultSet).iterator());
+        super(new JDBCQueryResultMetaData(resultSet.getMetaData()), new 
JDBCMemoryTypeHandlerFactory(resultSet).load().iterator());
+        typeHandlerFactory = new JDBCMemoryTypeHandlerFactory(resultSet);
+    }
+
+    @Override
+    public Object getValue(final int columnIndex, final Class<?> type) {
+        Object value = super.getValue(columnIndex, type);
+        return typeHandlerFactory.getValue(value, columnIndex, type);

Review comment:
       Why we get value again?

##########
File path: 
shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/result/query/type/convert/AbstractJDBCTypeHandlerFactory.java
##########
@@ -0,0 +1,154 @@
+/*
+ * 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.infra.executor.sql.execute.result.query.type.convert;
+
+import com.google.common.base.Preconditions;
+
+import java.lang.reflect.Field;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.SQLException;
+import java.sql.Types;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.stream.Collectors;
+
+import lombok.SneakyThrows;
+import lombok.extern.slf4j.Slf4j;
+
+import org.apache.shardingsphere.infra.exception.ShardingSphereException;
+import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
+
+/**
+ * JDBC type convert factory class.
+ * @author Sirmin
+ */
+@Slf4j
+public abstract class AbstractJDBCTypeHandlerFactory {
+
+    /**
+     * Define a data structure that holds TypeHandler.
+     * JDBC TYPE (int)
+     *      SIGNED (boolean)
+     *          TypeHandler list(by prioritization)
+     */
+    static final Map<Integer, Map<Boolean, List<TypeHandler<?>>>> 
TYPE_HANDLER_MAP = new HashMap<>();
+
+    static {
+        loadTypeHandlers();
+    }
+
+    @SuppressWarnings({"unchecked", "rawtypes"})
+    private static synchronized void loadTypeHandlers() {

Review comment:
       `loadTypeHandlers` looks so complex to me. Is it possible to load 
typeHandlers more easily?

##########
File path: 
shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/result/query/impl/driver/jdbc/type/memory/JDBCMemoryQueryResult.java
##########
@@ -17,18 +17,35 @@
 
 package 
org.apache.shardingsphere.infra.executor.sql.execute.result.query.impl.driver.jdbc.type.memory;
 
-import 
org.apache.shardingsphere.infra.executor.sql.execute.result.query.impl.driver.jdbc.metadata.JDBCQueryResultMetaData;
-import 
org.apache.shardingsphere.infra.executor.sql.execute.result.query.type.memory.AbstractMemoryQueryResult;
-
 import java.sql.ResultSet;
 import java.sql.SQLException;
+import java.util.Calendar;
+
+import 
org.apache.shardingsphere.infra.executor.sql.execute.result.query.impl.driver.jdbc.metadata.JDBCQueryResultMetaData;
+import 
org.apache.shardingsphere.infra.executor.sql.execute.result.query.type.convert.memory.JDBCMemoryTypeHandlerFactory;
+import 
org.apache.shardingsphere.infra.executor.sql.execute.result.query.type.memory.AbstractMemoryQueryResult;
 
 /**
  * JDBC query result for memory loading.
  */
 public final class JDBCMemoryQueryResult extends AbstractMemoryQueryResult {
-    
+
+    private final JDBCMemoryTypeHandlerFactory typeHandlerFactory;
+
     public JDBCMemoryQueryResult(final ResultSet resultSet) throws 
SQLException {
-        super(new JDBCQueryResultMetaData(resultSet.getMetaData()), 
JDBCRowsLoader.load(resultSet.getMetaData().getColumnCount(), 
resultSet).iterator());
+        super(new JDBCQueryResultMetaData(resultSet.getMetaData()), new 
JDBCMemoryTypeHandlerFactory(resultSet).load().iterator());
+        typeHandlerFactory = new JDBCMemoryTypeHandlerFactory(resultSet);

Review comment:
       is JDBCMemoryTypeHandlerFactory(resultSet) can use same object with line 
36?

##########
File path: 
shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/result/query/type/convert/AbstractTypeHandler.java
##########
@@ -0,0 +1,86 @@
+/*
+ * 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.infra.executor.sql.execute.result.query.type.convert;
+
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.lang.reflect.TypeVariable;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+
+public abstract class AbstractTypeHandler<T> implements TypeHandler<T> {

Review comment:
       TypeHandler's Inheritance relationship is a bit complicated for me. Can 
we make it more simple?




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