@Test public void testGetConnectionPoolEnabledWithPoolProps() throws SQLException { Driver mockDriver = mock(Driver.class); when(DriverManager.getDriver("test-url")).thenReturn(mockDriver); when(mockDriver.connect(anyString(), anyObject())).thenReturn(mockConnection); connProps.setProperty("user", "foo"); connProps.setProperty("password", "foo-password"); connProps.setProperty("some-prop", "some-value"); poolProps.setProperty("maximumPoolSize", "1"); poolProps.setProperty("connectionTimeout", "250"); poolProps.setProperty("dataSource.foo", "123"); Connection conn = manager.getConnection("test-server", "test-url", connProps, true, poolProps, null); assertNotNull(conn); Properties calledWith = (Properties) connProps.clone(); calledWith.setProperty("foo", "123"); verify(mockDriver, times(1)).connect("test-url", calledWith); }
public Connection getConnection(String server, String jdbcUrl, Properties connectionConfiguration, boolean isPoolEnabled, Properties poolConfiguration, String qualifier) throws SQLException { Connection result; if (!isPoolEnabled) { LOG.debug("Requesting DriverManager.getConnection for server={}", server); result = DriverManager.getConnection(jdbcUrl, connectionConfiguration); } else { PoolDescriptor poolDescriptor = new PoolDescriptor(server, jdbcUrl, connectionConfiguration, poolConfiguration, qualifier); DataSource dataSource; try { LOG.debug("Requesting datasource for server={} and {}", server, poolDescriptor); dataSource = dataSources.getUnchecked(poolDescriptor); LOG.debug("Obtained datasource {} for server={} and {}", dataSource.hashCode(), server, poolDescriptor); } catch (UncheckedExecutionException e) { Throwable cause = e.getCause() != null ? e.getCause() : e; throw new SQLException(String.format("Could not obtain datasource for server %s and %s : %s", server, poolDescriptor, cause.getMessage()), cause); } result = dataSource.getConnection(); } LOG.debug("Returning JDBC connection {} for server={}", result, server); return result; }
ConnectionManager { public Connection getConnection(String server, String jdbcUrl, Properties connectionConfiguration, boolean isPoolEnabled, Properties poolConfiguration, String qualifier) throws SQLException { Connection result; if (!isPoolEnabled) { LOG.debug("Requesting DriverManager.getConnection for server={}", server); result = DriverManager.getConnection(jdbcUrl, connectionConfiguration); } else { PoolDescriptor poolDescriptor = new PoolDescriptor(server, jdbcUrl, connectionConfiguration, poolConfiguration, qualifier); DataSource dataSource; try { LOG.debug("Requesting datasource for server={} and {}", server, poolDescriptor); dataSource = dataSources.getUnchecked(poolDescriptor); LOG.debug("Obtained datasource {} for server={} and {}", dataSource.hashCode(), server, poolDescriptor); } catch (UncheckedExecutionException e) { Throwable cause = e.getCause() != null ? e.getCause() : e; throw new SQLException(String.format("Could not obtain datasource for server %s and %s : %s", server, poolDescriptor, cause.getMessage()), cause); } result = dataSource.getConnection(); } LOG.debug("Returning JDBC connection {} for server={}", result, server); return result; } }
ConnectionManager { public Connection getConnection(String server, String jdbcUrl, Properties connectionConfiguration, boolean isPoolEnabled, Properties poolConfiguration, String qualifier) throws SQLException { Connection result; if (!isPoolEnabled) { LOG.debug("Requesting DriverManager.getConnection for server={}", server); result = DriverManager.getConnection(jdbcUrl, connectionConfiguration); } else { PoolDescriptor poolDescriptor = new PoolDescriptor(server, jdbcUrl, connectionConfiguration, poolConfiguration, qualifier); DataSource dataSource; try { LOG.debug("Requesting datasource for server={} and {}", server, poolDescriptor); dataSource = dataSources.getUnchecked(poolDescriptor); LOG.debug("Obtained datasource {} for server={} and {}", dataSource.hashCode(), server, poolDescriptor); } catch (UncheckedExecutionException e) { Throwable cause = e.getCause() != null ? e.getCause() : e; throw new SQLException(String.format("Could not obtain datasource for server %s and %s : %s", server, poolDescriptor, cause.getMessage()), cause); } result = dataSource.getConnection(); } LOG.debug("Returning JDBC connection {} for server={}", result, server); return result; } private  ConnectionManager();   ConnectionManager(DataSourceFactory factory, Ticker ticker, long sleepIntervalNanos); }
ConnectionManager { public Connection getConnection(String server, String jdbcUrl, Properties connectionConfiguration, boolean isPoolEnabled, Properties poolConfiguration, String qualifier) throws SQLException { Connection result; if (!isPoolEnabled) { LOG.debug("Requesting DriverManager.getConnection for server={}", server); result = DriverManager.getConnection(jdbcUrl, connectionConfiguration); } else { PoolDescriptor poolDescriptor = new PoolDescriptor(server, jdbcUrl, connectionConfiguration, poolConfiguration, qualifier); DataSource dataSource; try { LOG.debug("Requesting datasource for server={} and {}", server, poolDescriptor); dataSource = dataSources.getUnchecked(poolDescriptor); LOG.debug("Obtained datasource {} for server={} and {}", dataSource.hashCode(), server, poolDescriptor); } catch (UncheckedExecutionException e) { Throwable cause = e.getCause() != null ? e.getCause() : e; throw new SQLException(String.format("Could not obtain datasource for server %s and %s : %s", server, poolDescriptor, cause.getMessage()), cause); } result = dataSource.getConnection(); } LOG.debug("Returning JDBC connection {} for server={}", result, server); return result; } private  ConnectionManager();   ConnectionManager(DataSourceFactory factory, Ticker ticker, long sleepIntervalNanos); static ConnectionManager getInstance(); Connection getConnection(String server, String jdbcUrl, Properties connectionConfiguration, boolean isPoolEnabled, Properties poolConfiguration, String qualifier); static String maskPassword(String password); }
ConnectionManager { public Connection getConnection(String server, String jdbcUrl, Properties connectionConfiguration, boolean isPoolEnabled, Properties poolConfiguration, String qualifier) throws SQLException { Connection result; if (!isPoolEnabled) { LOG.debug("Requesting DriverManager.getConnection for server={}", server); result = DriverManager.getConnection(jdbcUrl, connectionConfiguration); } else { PoolDescriptor poolDescriptor = new PoolDescriptor(server, jdbcUrl, connectionConfiguration, poolConfiguration, qualifier); DataSource dataSource; try { LOG.debug("Requesting datasource for server={} and {}", server, poolDescriptor); dataSource = dataSources.getUnchecked(poolDescriptor); LOG.debug("Obtained datasource {} for server={} and {}", dataSource.hashCode(), server, poolDescriptor); } catch (UncheckedExecutionException e) { Throwable cause = e.getCause() != null ? e.getCause() : e; throw new SQLException(String.format("Could not obtain datasource for server %s and %s : %s", server, poolDescriptor, cause.getMessage()), cause); } result = dataSource.getConnection(); } LOG.debug("Returning JDBC connection {} for server={}", result, server); return result; } private  ConnectionManager();   ConnectionManager(DataSourceFactory factory, Ticker ticker, long sleepIntervalNanos); static ConnectionManager getInstance(); Connection getConnection(String server, String jdbcUrl, Properties connectionConfiguration, boolean isPoolEnabled, Properties poolConfiguration, String qualifier); static String maskPassword(String password);  }