JdbcWrapper { boolean rebindDataSources() { boolean ok; try { final boolean rewrapDataSources = Parameter.REWRAP_DATASOURCES.getValueAsBoolean(); if (rewrapDataSources || Parameter.DATASOURCES.getValue() != null) { stop(); } final Map<String, DataSource> jndiDataSources = JdbcWrapperHelper.getJndiDataSources(); LOG.debug("datasources found in JNDI: " + jndiDataSources.keySet()); for (final Map.Entry<String, DataSource> entry : jndiDataSources.entrySet()) { final String jndiName = entry.getKey(); final DataSource dataSource = entry.getValue(); try { if (rewrapDataSources || isServerNeedsRewrap(jndiName)) { rewrapDataSource(jndiName, dataSource); JdbcWrapperHelper.registerRewrappedDataSource(jndiName, dataSource); } else if (!isProxyAlready(dataSource)) { final DataSource dataSourceProxy = createDataSourceProxy(jndiName, dataSource); JdbcWrapperHelper.rebindDataSource(servletContext, jndiName, dataSource, dataSourceProxy); LOG.debug("datasource rebinded: " + jndiName + " from class " + dataSource.getClass().getName() + " to class " + dataSourceProxy.getClass().getName()); } } catch (final Throwable t) { LOG.debug("rebinding datasource " + jndiName + " failed, skipping it", t); } } ok = true; } catch (final Throwable t) { LOG.debug("rebinding datasources failed, skipping", t); ok = false; } return ok; } private  JdbcWrapper(Counter sqlCounter); static int getUsedConnectionCount(); static int getActiveConnectionCount(); static long getTransactionCount(); static int getActiveThreadCount(); static int getRunningBuildCount(); static int getBuildQueueLength(); static long getBuildQueueWaitingDurationsSum(); static List<ConnectionInformations> getConnectionInformationsList(); Counter getSqlCounter(); static int getMaxConnectionCount(); static Map<String, Map<String, Object>> getBasicDataSourceProperties(); static Map<String, DataSource> getJndiAndSpringDataSources(); static void registerSpringDataSource(String name, DataSource dataSource); DataSource createDataSourceProxy(DataSource dataSource); DataSource createDataSourceProxy(String name, final DataSource dataSource); Connection createConnectionProxy(Connection connection); static final JdbcWrapper SINGLETON; }
@Test public void testRebindDataSources() { jdbcWrapper.rebindDataSources(); Utils.setProperty(Parameter.REWRAP_DATASOURCES, "true"); jdbcWrapper.rebindDataSources(); jdbcWrapper.stop(); }