private Connection createRealConnection ( final long timeoutMillis ) throws SQLException { if ( timeoutMillis < 1L ) { String usePassword = getPassword ( ) ; Connection conn = dbConnection . datasource == null ? DriverManager . getConnection ( dbConnection . connectionString , dbConnection . user , usePassword ) : dbConnection . datasource . getConnection ( dbConnection . user , usePassword ) ; if ( conn != null ) { return conn ; } else { throw new SQLException ( "Unable to create connection: driver/datasource returned [null]" ) ; } } else { try { return connectionTimeLimiter . callWithTimeout ( ( ) -> createRealConnection ( 0L ) , timeoutMillis , TimeUnit . MILLISECONDS ) ; } catch ( UncheckedTimeoutException ute ) { throw new SQLException ( "Unable to create connection after waiting " + timeoutMillis + " ms" ) ; } catch ( Exception e ) { throw new SQLException ( "Unable to create connection: driver/datasource" , e ) ; } } }
Creates a real database connection failing if one is not obtained in the specified time .