You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2019/07/07 04:29:04 UTC

[GitHub] [incubator-shardingsphere] sunbufu commented on issue #2604: The query entity throws an exception when a boolean property exists in the entity

sunbufu commented on issue #2604: The query entity throws an exception when a boolean property exists in the entity
URL: https://github.com/apache/incubator-shardingsphere/issues/2604#issuecomment-508970554
 
 
   In my opinion, the purpose of `JDBC` is resolve different databases's compatibility. so `ResultSet` defined some method like `getBytes()`, `getBoolean()` and etc to help us get object with **expected java type**. 
   `ShardingSphere` work on dataSource, and defined `ResultSet` too, like `ShardingResultSet` and `EncryptResultSet`. but `ShardingSphere` use **database column type** in place of **expected java type**. 
   There are some codes in `StreamQueryResult`, we can see `getValue()` **do nothing** with `final Class<?> type`.
   ```java
   @Override
   public Object getValue(final int columnIndex, final Class<?> type) throws SQLException {
       return decrypt(columnIndex, QueryResultUtil.getValue(resultSet, columnIndex));
   }
   ```
   And in `QueryResultUtil`, `getValueByColumnType()` get **database column type** from `resultSet. metaData` and use it for `getXXX()` selection.
   ```java
   public static Object getValueByColumnType(final ResultSet resultSet, final int columnIndex) throws SQLException {
           ResultSetMetaData metaData = resultSet.getMetaData();
           switch (metaData.getColumnType(columnIndex)) {
               case Types.BIT:
                   return resultSet.getBytes(columnIndex);
               case Types.BOOLEAN:
                   return resultSet.getBoolean(columnIndex);
               case Types.TINYINT:
                   return resultSet.getByte(columnIndex);
               ...
           }
       }
   ```
   Usually it's okay, but when we use mysql and call some special methods such as `getBoolean()`, our **expected java type** is boolean,  **database column type** is not boolean. 
   so I think we should pass on the **expected java type**, and use it for `getXXX()` selection.
   Can I send a PR ?

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services