1

I'm playing with Sonarqube plugin for Jenkins. How can I effectively solve this trivial violation he is complaining about without changing the logic?

Note: I need to validate the connections separetely ( ConnectionManager, statistics, keepAlive, .. ).

`

public void executeProcedure( final RequestProcessor consumer ) throws SQLException {

    final String procedure = consumer.getProcedure();
    final String idUrl = consumer.getIdUrl();
    final PreparedStatementRegisterer stmRegisterer = consumer.getRegisterer();

    // Autoclosable removed to allow ad hoc connection validation
    Connection conn = null;
    boolean execSuccess = false;

    try{
        conn = newConnection();
        conn = checkOrChangeConnection(conn, false);

        boolean hasResultSet = false;
        try( CallableStatement statement = (OracleCallableStatement)conn.prepareCall(procedure) ){

            ...

            stmRegisterer.prepareStatement(statement, idUrl);
            statement.setQueryTimeout(QUERY_TIMEOUT);
            hasResultSet = statement.execute();
            execSuccess = true;

            if(hasResultSet){
                ...
                try ( ResultSet rs = statement.getResultSet() ) {
                    while ( rs.next() ) {
                        consumer.handleRow( rs );
                    }
                }
            }else{
                ...
                consumer.getFieldsFromResult( statement );
            }
        }

    }catch(Exception ex){

        LOGGER.log( LogEntries.StorProcErr, ex.getMessage() );
        throw new Exception( (!execSuccess ? "Error preparing and executing statement.":"Error during results reading.")+" Cause: "+ex) );

    }finally{

      try {
        if (conn != null) {
            conn.close();
        }
      } catch (SQLException e) {
        System.out.println("\n Error closing connection on executeStoredProc. Cause: "+e+" \n"); // log 
      }
    }

}

My idea is to add some more logging and re-throw the same exception after the log "StorProcErr". Is there a better approach?

Thanks

4

0 回答 0