@Test public void testRewrapDataSource() throws Exception { final BasicDataSource tomcatDataSource = new BasicDataSource(); tomcatDataSource.setUrl(H2_DATABASE_URL); rewrapDataSource(tomcatDataSource); final org.apache.commons.dbcp.BasicDataSource dbcpDataSource = new org.apache.commons.dbcp.BasicDataSource(); dbcpDataSource.setUrl(H2_DATABASE_URL); rewrapDataSource(dbcpDataSource); final org.apache.tomcat.dbcp.dbcp2.BasicDataSource tomcat2DataSource = new org.apache.tomcat.dbcp.dbcp2.BasicDataSource(); tomcat2DataSource.setUrl(H2_DATABASE_URL); rewrapDataSource(tomcat2DataSource); final org.apache.commons.dbcp2.BasicDataSource dbcp2DataSource = new org.apache.commons.dbcp2.BasicDataSource(); dbcp2DataSource.setUrl(H2_DATABASE_URL); rewrapDataSource(dbcp2DataSource); final DataSource dataSource = createNiceMock(DataSource.class); rewrapDataSource(dataSource); }
private void rewrapDataSource(String jndiName, DataSource dataSource) throws IllegalAccessException { final String dataSourceClassName = dataSource.getClass().getName(); LOG.debug("Datasource needs rewrap: " + jndiName + " of class " + dataSourceClassName); final String dataSourceRewrappedMessage = "Datasource rewrapped: " + jndiName; if (isJBossOrGlassfishDataSource(dataSourceClassName)) { Object javaxConnectionManager = JdbcWrapperHelper.getFieldValue(dataSource, "cm"); javaxConnectionManager = createJavaxConnectionManagerProxy(javaxConnectionManager); JdbcWrapperHelper.setFieldValue(dataSource, "cm", javaxConnectionManager); LOG.debug(dataSourceRewrappedMessage); } else if (isWildfly9DataSource(dataSourceClassName)) { Object delegateDataSource = JdbcWrapperHelper.getFieldValue(dataSource, "delegate"); delegateDataSource = createDataSourceProxy((DataSource) delegateDataSource); JdbcWrapperHelper.setFieldValue(dataSource, "delegate", delegateDataSource); LOG.debug(dataSourceRewrappedMessage); } else if (weblogic && "weblogic.jdbc.common.internal.RmiDataSource".equals(dataSourceClassName)) { rewrapWebLogicDataSource(dataSource); LOG.debug(dataSourceRewrappedMessage); } else if (isDbcpDataSource(dataSourceClassName)) { rewrapBasicDataSource(dataSource); LOG.debug(dataSourceRewrappedMessage); } else if ("org.apache.openejb.resource.jdbc.managed.local.ManagedDataSource" .equals(dataSourceClassName)) { rewrapTomEEDataSource(dataSource); LOG.debug(dataSourceRewrappedMessage); } else { LOG.info("Datasource can't be rewrapped: " + jndiName + " of class " + dataSourceClassName); } }
JdbcWrapper { private void rewrapDataSource(String jndiName, DataSource dataSource) throws IllegalAccessException { final String dataSourceClassName = dataSource.getClass().getName(); LOG.debug("Datasource needs rewrap: " + jndiName + " of class " + dataSourceClassName); final String dataSourceRewrappedMessage = "Datasource rewrapped: " + jndiName; if (isJBossOrGlassfishDataSource(dataSourceClassName)) { Object javaxConnectionManager = JdbcWrapperHelper.getFieldValue(dataSource, "cm"); javaxConnectionManager = createJavaxConnectionManagerProxy(javaxConnectionManager); JdbcWrapperHelper.setFieldValue(dataSource, "cm", javaxConnectionManager); LOG.debug(dataSourceRewrappedMessage); } else if (isWildfly9DataSource(dataSourceClassName)) { Object delegateDataSource = JdbcWrapperHelper.getFieldValue(dataSource, "delegate"); delegateDataSource = createDataSourceProxy((DataSource) delegateDataSource); JdbcWrapperHelper.setFieldValue(dataSource, "delegate", delegateDataSource); LOG.debug(dataSourceRewrappedMessage); } else if (weblogic && "weblogic.jdbc.common.internal.RmiDataSource".equals(dataSourceClassName)) { rewrapWebLogicDataSource(dataSource); LOG.debug(dataSourceRewrappedMessage); } else if (isDbcpDataSource(dataSourceClassName)) { rewrapBasicDataSource(dataSource); LOG.debug(dataSourceRewrappedMessage); } else if ("org.apache.openejb.resource.jdbc.managed.local.ManagedDataSource" .equals(dataSourceClassName)) { rewrapTomEEDataSource(dataSource); LOG.debug(dataSourceRewrappedMessage); } else { LOG.info("Datasource can't be rewrapped: " + jndiName + " of class " + dataSourceClassName); } } }
JdbcWrapper { private void rewrapDataSource(String jndiName, DataSource dataSource) throws IllegalAccessException { final String dataSourceClassName = dataSource.getClass().getName(); LOG.debug("Datasource needs rewrap: " + jndiName + " of class " + dataSourceClassName); final String dataSourceRewrappedMessage = "Datasource rewrapped: " + jndiName; if (isJBossOrGlassfishDataSource(dataSourceClassName)) { Object javaxConnectionManager = JdbcWrapperHelper.getFieldValue(dataSource, "cm"); javaxConnectionManager = createJavaxConnectionManagerProxy(javaxConnectionManager); JdbcWrapperHelper.setFieldValue(dataSource, "cm", javaxConnectionManager); LOG.debug(dataSourceRewrappedMessage); } else if (isWildfly9DataSource(dataSourceClassName)) { Object delegateDataSource = JdbcWrapperHelper.getFieldValue(dataSource, "delegate"); delegateDataSource = createDataSourceProxy((DataSource) delegateDataSource); JdbcWrapperHelper.setFieldValue(dataSource, "delegate", delegateDataSource); LOG.debug(dataSourceRewrappedMessage); } else if (weblogic && "weblogic.jdbc.common.internal.RmiDataSource".equals(dataSourceClassName)) { rewrapWebLogicDataSource(dataSource); LOG.debug(dataSourceRewrappedMessage); } else if (isDbcpDataSource(dataSourceClassName)) { rewrapBasicDataSource(dataSource); LOG.debug(dataSourceRewrappedMessage); } else if ("org.apache.openejb.resource.jdbc.managed.local.ManagedDataSource" .equals(dataSourceClassName)) { rewrapTomEEDataSource(dataSource); LOG.debug(dataSourceRewrappedMessage); } else { LOG.info("Datasource can't be rewrapped: " + jndiName + " of class " + dataSourceClassName); } } private  JdbcWrapper(Counter sqlCounter); }
JdbcWrapper { private void rewrapDataSource(String jndiName, DataSource dataSource) throws IllegalAccessException { final String dataSourceClassName = dataSource.getClass().getName(); LOG.debug("Datasource needs rewrap: " + jndiName + " of class " + dataSourceClassName); final String dataSourceRewrappedMessage = "Datasource rewrapped: " + jndiName; if (isJBossOrGlassfishDataSource(dataSourceClassName)) { Object javaxConnectionManager = JdbcWrapperHelper.getFieldValue(dataSource, "cm"); javaxConnectionManager = createJavaxConnectionManagerProxy(javaxConnectionManager); JdbcWrapperHelper.setFieldValue(dataSource, "cm", javaxConnectionManager); LOG.debug(dataSourceRewrappedMessage); } else if (isWildfly9DataSource(dataSourceClassName)) { Object delegateDataSource = JdbcWrapperHelper.getFieldValue(dataSource, "delegate"); delegateDataSource = createDataSourceProxy((DataSource) delegateDataSource); JdbcWrapperHelper.setFieldValue(dataSource, "delegate", delegateDataSource); LOG.debug(dataSourceRewrappedMessage); } else if (weblogic && "weblogic.jdbc.common.internal.RmiDataSource".equals(dataSourceClassName)) { rewrapWebLogicDataSource(dataSource); LOG.debug(dataSourceRewrappedMessage); } else if (isDbcpDataSource(dataSourceClassName)) { rewrapBasicDataSource(dataSource); LOG.debug(dataSourceRewrappedMessage); } else if ("org.apache.openejb.resource.jdbc.managed.local.ManagedDataSource" .equals(dataSourceClassName)) { rewrapTomEEDataSource(dataSource); LOG.debug(dataSourceRewrappedMessage); } else { LOG.info("Datasource can't be rewrapped: " + jndiName + " of class " + dataSourceClassName); } } 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); }
JdbcWrapper { private void rewrapDataSource(String jndiName, DataSource dataSource) throws IllegalAccessException { final String dataSourceClassName = dataSource.getClass().getName(); LOG.debug("Datasource needs rewrap: " + jndiName + " of class " + dataSourceClassName); final String dataSourceRewrappedMessage = "Datasource rewrapped: " + jndiName; if (isJBossOrGlassfishDataSource(dataSourceClassName)) { Object javaxConnectionManager = JdbcWrapperHelper.getFieldValue(dataSource, "cm"); javaxConnectionManager = createJavaxConnectionManagerProxy(javaxConnectionManager); JdbcWrapperHelper.setFieldValue(dataSource, "cm", javaxConnectionManager); LOG.debug(dataSourceRewrappedMessage); } else if (isWildfly9DataSource(dataSourceClassName)) { Object delegateDataSource = JdbcWrapperHelper.getFieldValue(dataSource, "delegate"); delegateDataSource = createDataSourceProxy((DataSource) delegateDataSource); JdbcWrapperHelper.setFieldValue(dataSource, "delegate", delegateDataSource); LOG.debug(dataSourceRewrappedMessage); } else if (weblogic && "weblogic.jdbc.common.internal.RmiDataSource".equals(dataSourceClassName)) { rewrapWebLogicDataSource(dataSource); LOG.debug(dataSourceRewrappedMessage); } else if (isDbcpDataSource(dataSourceClassName)) { rewrapBasicDataSource(dataSource); LOG.debug(dataSourceRewrappedMessage); } else if ("org.apache.openejb.resource.jdbc.managed.local.ManagedDataSource" .equals(dataSourceClassName)) { rewrapTomEEDataSource(dataSource); LOG.debug(dataSourceRewrappedMessage); } else { LOG.info("Datasource can't be rewrapped: " + jndiName + " of class " + dataSourceClassName); } } 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; }