public final List < Connection > getConnections ( final ConnectionMode connectionMode , final String dataSourceName , final int connectionSize ) throws SQLException { DataSource dataSource = getDataSourceMap ( ) . get ( dataSourceName ) ; Preconditions . checkState ( null != dataSource , "Missing the data source name: '%s'" , dataSourceName ) ; Collection < Connection > connections ; synchronized ( cachedConnections ) { connections = cachedConnections . get ( dataSourceName ) ; } List < Connection > result ; if ( connections . size ( ) >= connectionSize ) { result = new ArrayList <> ( connections ) . subList ( 0 , connectionSize ) ; } else if ( ! connections . isEmpty ( ) ) { result = new ArrayList <> ( connectionSize ) ; result . addAll ( connections ) ; List < Connection > newConnections = createConnections ( dataSourceName , connectionMode , dataSource , connectionSize - connections . size ( ) ) ; result . addAll ( newConnections ) ; synchronized ( cachedConnections ) { cachedConnections . putAll ( dataSourceName , newConnections ) ; } } else { result = new ArrayList <> ( createConnections ( dataSourceName , connectionMode , dataSource , connectionSize ) ) ; synchronized ( cachedConnections ) { cachedConnections . putAll ( dataSourceName , result ) ; } } return result ; }
Get database connections .