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 2020/07/02 19:04:26 UTC

[GitHub] [shardingsphere] TheOldDriver commented on a change in pull request #6002: AbstractConnectionAdapter implement Connection#isValid(int) method

TheOldDriver commented on a change in pull request #6002:
URL: https://github.com/apache/shardingsphere/pull/6002#discussion_r449214354



##########
File path: shardingsphere-jdbc/shardingsphere-jdbc-orchestration/src/main/java/org/apache/shardingsphere/driver/orchestration/internal/circuit/connection/CircuitBreakerConnection.java
##########
@@ -127,7 +128,12 @@ public PreparedStatement prepareStatement(final String sql, final int[] columnIn
     public PreparedStatement prepareStatement(final String sql, final String[] columnNames) {
         return new CircuitBreakerPreparedStatement();
     }
-    
+
+    @Override
+    public boolean isValid(final int timeout) throws SQLException {
+        return true;

Review comment:
       After upgrading spring-boot to version 2.3.1, I also encountered "new SQLFeatureNotSupportedException("isValid")".
   
    spring-boot-actuator will perform database heartbeat detection according to the configuration file.
   
    In the "org.springframework.boot.actuate.jdbc.DataSourceHealthIndicator#doDataSourceHealthCheck" method, different heartbeats will be detected based on whether the'query' variable in the DataSourceHealthIndicator class has a value.
   
    If'query' is not assigned, it will directly call java .sql.Connection#isValid This specific implementation method.
   Because shardingJDBC does not implement the java.sql.Connection#isValid method, it will directly report the error "new SQLFeatureNotSupportedException("isValid")".
   
   Currently shardingJDBC does not support the java.sql.Connection#isValid method. 
   
   In order to solve the above problem, you can inherit the "DataSourceHealthContributorAutoConfiguration" method, override the createIndicator method, and set the "query" variable in the DataSourceHealthIndicator class, for example, set it to "select 1".
   
   After setting the variable "query",
    the doDataSourceHealthCheck method will call the "org.springframework.jdbc.core.JdbcTemplate#query(java.lang.String, org.springframework.jdbc.core.RowMapper<T>)" method to complete the database Heartbeat detection.




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