diff --git a/build.gradle b/build.gradle index 6d9a20a..9e03463 100644 --- a/build.gradle +++ b/build.gradle @@ -44,8 +44,8 @@ subprojects { apply plugin: 'propdeps-idea' apply plugin: 'propdeps-eclipse' - sourceCompatibility = 1.7 - targetCompatibility = 1.7 + sourceCompatibility = 1.6 + targetCompatibility = 1.6 task packageSources(type: Jar) { classifier = 'sources' diff --git a/spring-service-connector/build.gradle b/spring-service-connector/build.gradle index 7ef5f1b..fb6d701 100644 --- a/spring-service-connector/build.gradle +++ b/spring-service-connector/build.gradle @@ -20,14 +20,12 @@ dependencies { optional("org.apache.tomcat:tomcat-dbcp:$tomcatVersion") optional("org.apache.commons:commons-dbcp2:$commonDbcp2Version") { exclude(module: 'commons-logging') - exclude(module: 'commons-pool') exclude(module: 'xerces') exclude(module: 'xercesImpl') exclude(module: 'xml-apis') } optional("commons-dbcp:commons-dbcp:$commonDbcpVersion") { exclude(module: 'commons-logging') - exclude(module: 'commons-pool') exclude(module: 'xerces') exclude(module: 'xercesImpl') exclude(module: 'xml-apis') diff --git a/spring-service-connector/src/main/java/org/springframework/cloud/service/relational/BasicDbcpPooledDataSourceCreator.java b/spring-service-connector/src/main/java/org/springframework/cloud/service/relational/BasicDbcpPooledDataSourceCreator.java index 8efcff6..7f67266 100644 --- a/spring-service-connector/src/main/java/org/springframework/cloud/service/relational/BasicDbcpPooledDataSourceCreator.java +++ b/spring-service-connector/src/main/java/org/springframework/cloud/service/relational/BasicDbcpPooledDataSourceCreator.java @@ -15,22 +15,21 @@ import org.springframework.cloud.service.common.RelationalServiceInfo; */ public class BasicDbcpPooledDataSourceCreator extends DbcpLikePooledDataSourceCreator { - @Override - public DataSource create(RelationalServiceInfo serviceInfo, ServiceConnectorConfig serviceConnectorConfig, - String driverClassName, String validationQuery) { - if (hasClass("org.apache.commons.dbcp.BasicDataSource")) { - logger.info("Found DBCP on the classpath. Using it for DataSource connection pooling."); - org.apache.commons.dbcp.BasicDataSource ds = new org.apache.commons.dbcp.BasicDataSource(); - setBasicDataSourceProperties(ds, serviceInfo, serviceConnectorConfig, driverClassName, validationQuery); - return ds; - } else if (hasClass("org.apache.commons.dbcp2.BasicDataSource")) { - logger.info("Found DBCP on the classpath. Using it for DataSource connection pooling."); - org.apache.commons.dbcp2.BasicDataSource ds = new org.apache.commons.dbcp2.BasicDataSource(); - setBasicDataSourceProperties(ds, serviceInfo, serviceConnectorConfig, driverClassName, validationQuery); - return ds; - } else { - return null; - } - } - + @Override + public DataSource create(RelationalServiceInfo serviceInfo, ServiceConnectorConfig serviceConnectorConfig, + String driverClassName, String validationQuery) { + if (hasClass("org.apache.commons.dbcp2.BasicDataSource")) { + logger.info("Found DBCP2 on the classpath. Using it for DataSource connection pooling."); + org.apache.commons.dbcp2.BasicDataSource ds = new org.apache.commons.dbcp2.BasicDataSource(); + setBasicDataSourceProperties(ds, serviceInfo, serviceConnectorConfig, driverClassName, validationQuery); + return ds; + } else if (hasClass("org.apache.commons.dbcp.BasicDataSource")) { + logger.info("Found DBCP on the classpath. Using it for DataSource connection pooling."); + org.apache.commons.dbcp.BasicDataSource ds = new org.apache.commons.dbcp.BasicDataSource(); + setBasicDataSourceProperties(ds, serviceInfo, serviceConnectorConfig, driverClassName, validationQuery); + return ds; + } else { + return null; + } + } } diff --git a/spring-service-connector/src/test/java/org/springframework/cloud/service/relational/PooledDataSourceCreatorsTest.java b/spring-service-connector/src/test/java/org/springframework/cloud/service/relational/PooledDataSourceCreatorsTest.java index 03edf94..5791980 100644 --- a/spring-service-connector/src/test/java/org/springframework/cloud/service/relational/PooledDataSourceCreatorsTest.java +++ b/spring-service-connector/src/test/java/org/springframework/cloud/service/relational/PooledDataSourceCreatorsTest.java @@ -1,8 +1,5 @@ package org.springframework.cloud.service.relational; -import java.util.ArrayList; -import java.util.List; - import javax.sql.DataSource; import org.junit.Assert; @@ -24,19 +21,26 @@ public class PooledDataSourceCreatorsTest { } @Test - public void pooledDataSourceCreation() { - List> pooledDataSourceCreators = new ArrayList>(); + public void pooledDataSourceCreationDbcp() { + assertPooledDataSource(new BasicDbcpPooledDataSourceCreator()); + } - pooledDataSourceCreators.add(new BasicDbcpPooledDataSourceCreator()); - pooledDataSourceCreators.add(new TomcatDbcpPooledDataSourceCreator()); - pooledDataSourceCreators.add(new TomcatHighPerformancePooledDataSourceCreator()); + @Test + public void pooledDataSourceCreationTomcatDbcp() { + assertPooledDataSource(new TomcatDbcpPooledDataSourceCreator()); + } + + @Test + public void pooledDataSourceCreationTomcatHighPerformance() { + assertPooledDataSource(new TomcatHighPerformancePooledDataSourceCreator()); + } + + private void assertPooledDataSource(PooledDataSourceCreator testCreator) { + DataSource ds = testCreator.create(mockMysqlServiceInfo, null, + mysqlDataSourceCreator.getDriverClassName(mockMysqlServiceInfo), + "select 1"); + + Assert.assertNotNull("Failed to create datasource with " + testCreator.getClass().getSimpleName(), ds); - for (PooledDataSourceCreator testCreator : pooledDataSourceCreators) { - DataSource ds = testCreator.create(mockMysqlServiceInfo, null, - mysqlDataSourceCreator.getDriverClassName(mockMysqlServiceInfo), - "select 1"); - - Assert.assertNotNull("Failed to create datasource with " + testCreator.getClass().getSimpleName(), ds); - } } }