private Connection newConnection ( ) throws Exception { final long start = currentTime ( ) ; Connection connection = null ; try { String username = config . getUsername ( ) ; String password = config . getPassword ( ) ; connection = ( username == null ) ? dataSource . getConnection ( ) : dataSource . getConnection ( username , password ) ; setupConnection ( connection ) ; lastConnectionFailure . set ( null ) ; return connection ; } catch ( Exception e ) { if ( connection != null ) { quietlyCloseConnection ( connection , "(Failed to create/setup connection)" ) ; } else if ( getLastConnectionFailure ( ) == null ) { logger . debug ( "{} - Failed to create/setup connection: {}" , poolName , e . getMessage ( ) ) ; } lastConnectionFailure . set ( e ) ; throw e ; } finally { // tracker will be null during failFast check if ( metricsTracker != null ) { metricsTracker . recordConnectionCreated ( elapsedMillis ( start ) ) ; } } }
Obtain connection from data source .