@Test public void testCleanDataSources() throws SQLException { DBConnectionManager dbcManagerSpy = getDBConnectionManagerSpyWithPooling(); PooledDataSource dataSourceMock = mock(PooledDataSource.class); Hashtable<String, Hashtable<String, DataSource>> dbmsPoolTable = getHashTableObject1(dataSourceMock); Hashtable<String, PooledDataSourceProvider> providerTable = new Hashtable<>(); PooledDataSourceProvider dataSourceProviderMock = mock(PooledDataSourceProvider.class); doNothing().when(dataSourceProviderMock).closePooledDataSource(any(DataSource.class)); providerTable.put(C3P0PooledDataSourceProvider.C3P0_DATASOURCE_PROVIDER_NAME, dataSourceProviderMock); dbcManagerSpy.providerTable = providerTable; dbcManagerSpy.dbmsPoolTable = dbmsPoolTable; dbcManagerSpy.cleanDataSources(); verify(dataSourceMock, times(1)).getNumConnectionsAllUsers(); verify(dataSourceProviderMock, times(1)).closePooledDataSource(any(DataSource.class)); assertTrue(dbcManagerSpy.dbmsPoolTable.isEmpty()); }
public void cleanDataSources() { Hashtable<String, List<String>> removedDsKeyTable = null; Enumeration<String> allPoolKeys = dbmsPoolTable.keys(); while (allPoolKeys.hasMoreElements()) { String dbPoolKey = allPoolKeys.nextElement(); Hashtable<String, DataSource> dsTable = dbmsPoolTable.get(dbPoolKey); Enumeration<String> allDsKeys = dsTable.keys(); while (allDsKeys.hasMoreElements()) { String dsKey = allDsKeys.nextElement(); DataSource ds = dsTable.get(dsKey); if (ds != null && ds instanceof PooledDataSource) { PooledDataSource pDs = (PooledDataSource) ds; int conCount; try { conCount = pDs.getNumConnectionsAllUsers(); } catch (SQLException e) { continue; } if (conCount == 0) { List<String> removedList = null; if (removedDsKeyTable == null) { removedDsKeyTable = new Hashtable<>(); } else { removedList = removedDsKeyTable.get(dbPoolKey); } if (removedList == null) { removedList = new ArrayList<>(); removedList.add(dsKey); removedDsKeyTable.put(dbPoolKey, removedList); } else { removedList.add(dsKey); } } } } } if (removedDsKeyTable != null && !removedDsKeyTable.isEmpty()) { Enumeration<String> removedPoolKeys = removedDsKeyTable.keys(); while (removedPoolKeys.hasMoreElements()) { String removedPoolKey = removedPoolKeys.nextElement(); PooledDataSourceProvider provider = this.getProvider(removedPoolKey); List<String> removedDsList = removedDsKeyTable.get(removedPoolKey); Hashtable<String, DataSource> dsTable = dbmsPoolTable.get(removedPoolKey); for (String dsKey : removedDsList) { DataSource removedDs = dsTable.remove(dsKey); try { provider.closePooledDataSource(removedDs); } catch (SQLException e) { continue; } } if (dsTable.isEmpty()) { dbmsPoolTable.remove(removedPoolKey); } } } }
DBConnectionManager { public void cleanDataSources() { Hashtable<String, List<String>> removedDsKeyTable = null; Enumeration<String> allPoolKeys = dbmsPoolTable.keys(); while (allPoolKeys.hasMoreElements()) { String dbPoolKey = allPoolKeys.nextElement(); Hashtable<String, DataSource> dsTable = dbmsPoolTable.get(dbPoolKey); Enumeration<String> allDsKeys = dsTable.keys(); while (allDsKeys.hasMoreElements()) { String dsKey = allDsKeys.nextElement(); DataSource ds = dsTable.get(dsKey); if (ds != null && ds instanceof PooledDataSource) { PooledDataSource pDs = (PooledDataSource) ds; int conCount; try { conCount = pDs.getNumConnectionsAllUsers(); } catch (SQLException e) { continue; } if (conCount == 0) { List<String> removedList = null; if (removedDsKeyTable == null) { removedDsKeyTable = new Hashtable<>(); } else { removedList = removedDsKeyTable.get(dbPoolKey); } if (removedList == null) { removedList = new ArrayList<>(); removedList.add(dsKey); removedDsKeyTable.put(dbPoolKey, removedList); } else { removedList.add(dsKey); } } } } } if (removedDsKeyTable != null && !removedDsKeyTable.isEmpty()) { Enumeration<String> removedPoolKeys = removedDsKeyTable.keys(); while (removedPoolKeys.hasMoreElements()) { String removedPoolKey = removedPoolKeys.nextElement(); PooledDataSourceProvider provider = this.getProvider(removedPoolKey); List<String> removedDsList = removedDsKeyTable.get(removedPoolKey); Hashtable<String, DataSource> dsTable = dbmsPoolTable.get(removedPoolKey); for (String dsKey : removedDsList) { DataSource removedDs = dsTable.remove(dsKey); try { provider.closePooledDataSource(removedDs); } catch (SQLException e) { continue; } } if (dsTable.isEmpty()) { dbmsPoolTable.remove(removedPoolKey); } } } } }
DBConnectionManager { public void cleanDataSources() { Hashtable<String, List<String>> removedDsKeyTable = null; Enumeration<String> allPoolKeys = dbmsPoolTable.keys(); while (allPoolKeys.hasMoreElements()) { String dbPoolKey = allPoolKeys.nextElement(); Hashtable<String, DataSource> dsTable = dbmsPoolTable.get(dbPoolKey); Enumeration<String> allDsKeys = dsTable.keys(); while (allDsKeys.hasMoreElements()) { String dsKey = allDsKeys.nextElement(); DataSource ds = dsTable.get(dsKey); if (ds != null && ds instanceof PooledDataSource) { PooledDataSource pDs = (PooledDataSource) ds; int conCount; try { conCount = pDs.getNumConnectionsAllUsers(); } catch (SQLException e) { continue; } if (conCount == 0) { List<String> removedList = null; if (removedDsKeyTable == null) { removedDsKeyTable = new Hashtable<>(); } else { removedList = removedDsKeyTable.get(dbPoolKey); } if (removedList == null) { removedList = new ArrayList<>(); removedList.add(dsKey); removedDsKeyTable.put(dbPoolKey, removedList); } else { removedList.add(dsKey); } } } } } if (removedDsKeyTable != null && !removedDsKeyTable.isEmpty()) { Enumeration<String> removedPoolKeys = removedDsKeyTable.keys(); while (removedPoolKeys.hasMoreElements()) { String removedPoolKey = removedPoolKeys.nextElement(); PooledDataSourceProvider provider = this.getProvider(removedPoolKey); List<String> removedDsList = removedDsKeyTable.get(removedPoolKey); Hashtable<String, DataSource> dsTable = dbmsPoolTable.get(removedPoolKey); for (String dsKey : removedDsList) { DataSource removedDs = dsTable.remove(dsKey); try { provider.closePooledDataSource(removedDs); } catch (SQLException e) { continue; } } if (dsTable.isEmpty()) { dbmsPoolTable.remove(removedPoolKey); } } } } protected  DBConnectionManager(); }
DBConnectionManager { public void cleanDataSources() { Hashtable<String, List<String>> removedDsKeyTable = null; Enumeration<String> allPoolKeys = dbmsPoolTable.keys(); while (allPoolKeys.hasMoreElements()) { String dbPoolKey = allPoolKeys.nextElement(); Hashtable<String, DataSource> dsTable = dbmsPoolTable.get(dbPoolKey); Enumeration<String> allDsKeys = dsTable.keys(); while (allDsKeys.hasMoreElements()) { String dsKey = allDsKeys.nextElement(); DataSource ds = dsTable.get(dsKey); if (ds != null && ds instanceof PooledDataSource) { PooledDataSource pDs = (PooledDataSource) ds; int conCount; try { conCount = pDs.getNumConnectionsAllUsers(); } catch (SQLException e) { continue; } if (conCount == 0) { List<String> removedList = null; if (removedDsKeyTable == null) { removedDsKeyTable = new Hashtable<>(); } else { removedList = removedDsKeyTable.get(dbPoolKey); } if (removedList == null) { removedList = new ArrayList<>(); removedList.add(dsKey); removedDsKeyTable.put(dbPoolKey, removedList); } else { removedList.add(dsKey); } } } } } if (removedDsKeyTable != null && !removedDsKeyTable.isEmpty()) { Enumeration<String> removedPoolKeys = removedDsKeyTable.keys(); while (removedPoolKeys.hasMoreElements()) { String removedPoolKey = removedPoolKeys.nextElement(); PooledDataSourceProvider provider = this.getProvider(removedPoolKey); List<String> removedDsList = removedDsKeyTable.get(removedPoolKey); Hashtable<String, DataSource> dsTable = dbmsPoolTable.get(removedPoolKey); for (String dsKey : removedDsList) { DataSource removedDs = dsTable.remove(dsKey); try { provider.closePooledDataSource(removedDs); } catch (SQLException e) { continue; } } if (dsTable.isEmpty()) { dbmsPoolTable.remove(removedPoolKey); } } } } protected  DBConnectionManager(); static DBConnectionManager getInstance(); void finalize(); synchronized Connection getConnection(DBType aDbType, String aAuthType, String aDbUrl, String aUsername, String aPassword, Properties properties); void cleanDataSources(); synchronized void shutdownDbmsPools(); int getDbmsPoolSize(); int getConnectionSize(DBType aDbType, String aDbUrl); int getCheckedOutConnectionSize(DBType aDbType, String aDbUrl); int getCheckedInConnectionSize(DBType aDbType, String aDbUrl); int getTotalConnectionSize(); int getTotalCheckedOutConnectionSize(); int getTotalCheckedInConnectionSize(); }
DBConnectionManager { public void cleanDataSources() { Hashtable<String, List<String>> removedDsKeyTable = null; Enumeration<String> allPoolKeys = dbmsPoolTable.keys(); while (allPoolKeys.hasMoreElements()) { String dbPoolKey = allPoolKeys.nextElement(); Hashtable<String, DataSource> dsTable = dbmsPoolTable.get(dbPoolKey); Enumeration<String> allDsKeys = dsTable.keys(); while (allDsKeys.hasMoreElements()) { String dsKey = allDsKeys.nextElement(); DataSource ds = dsTable.get(dsKey); if (ds != null && ds instanceof PooledDataSource) { PooledDataSource pDs = (PooledDataSource) ds; int conCount; try { conCount = pDs.getNumConnectionsAllUsers(); } catch (SQLException e) { continue; } if (conCount == 0) { List<String> removedList = null; if (removedDsKeyTable == null) { removedDsKeyTable = new Hashtable<>(); } else { removedList = removedDsKeyTable.get(dbPoolKey); } if (removedList == null) { removedList = new ArrayList<>(); removedList.add(dsKey); removedDsKeyTable.put(dbPoolKey, removedList); } else { removedList.add(dsKey); } } } } } if (removedDsKeyTable != null && !removedDsKeyTable.isEmpty()) { Enumeration<String> removedPoolKeys = removedDsKeyTable.keys(); while (removedPoolKeys.hasMoreElements()) { String removedPoolKey = removedPoolKeys.nextElement(); PooledDataSourceProvider provider = this.getProvider(removedPoolKey); List<String> removedDsList = removedDsKeyTable.get(removedPoolKey); Hashtable<String, DataSource> dsTable = dbmsPoolTable.get(removedPoolKey); for (String dsKey : removedDsList) { DataSource removedDs = dsTable.remove(dsKey); try { provider.closePooledDataSource(removedDs); } catch (SQLException e) { continue; } } if (dsTable.isEmpty()) { dbmsPoolTable.remove(removedPoolKey); } } } } protected  DBConnectionManager(); static DBConnectionManager getInstance(); void finalize(); synchronized Connection getConnection(DBType aDbType, String aAuthType, String aDbUrl, String aUsername, String aPassword, Properties properties); void cleanDataSources(); synchronized void shutdownDbmsPools(); int getDbmsPoolSize(); int getConnectionSize(DBType aDbType, String aDbUrl); int getCheckedOutConnectionSize(DBType aDbType, String aDbUrl); int getCheckedInConnectionSize(DBType aDbType, String aDbUrl); int getTotalConnectionSize(); int getTotalCheckedOutConnectionSize(); int getTotalCheckedInConnectionSize();  }