Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support dbcp2 #549

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class DataSourceUtils {
public static final String DS_DRUID_CLASS = "com.alibaba.druid.pool.DruidDataSource";

public static final String DS_DBCP_CLASS = "org.apache.commons.dbcp.BasicDataSource";
public static final String DS_DBCP2_CLASS = "org.apache.commons.dbcp2.BasicDataSource";

public static final String DS_C3P0_CLASS = "com.mchange.v2.c3p0.ComboPooledDataSource";

Expand Down Expand Up @@ -69,11 +70,13 @@ public static boolean isDruidDataSource(String clazzType) {
}

public static boolean isDbcpDataSource(Object dataSource) {
return isTargetDataSource(DS_DBCP_CLASS, dataSource);
return isTargetDataSource(DS_DBCP_CLASS, dataSource)
|| isTargetDataSource(DS_DBCP2_CLASS, dataSource);
}

public static boolean isDbcpDataSource(String clazzType) {
return !StringUtils.isBlank(clazzType) && DS_DBCP_CLASS.equals(clazzType);
return !StringUtils.isBlank(clazzType)
&& (DS_DBCP_CLASS.equals(clazzType) || DS_DBCP2_CLASS.equals(clazzType));
}

public static boolean isC3p0DataSource(Object dataSource) {
Expand Down
5 changes: 5 additions & 0 deletions tracer-sofa-boot-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,11 @@
<version>1.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-dbcp2</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.kstyrc</groupId>
<artifactId>embedded-redis</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ public void testGetDataSourceUrl() throws Throwable {
Assert.assertNotNull(method);
Assert.assertEquals("test-url", method.invoke(basicDataSource));

// dbcp2
org.apache.commons.dbcp2.BasicDataSource basicDataSource2 = new org.apache.commons.dbcp2.BasicDataSource();
basicDataSource2.setUrl("test-url");
method = ReflectionUtils.findMethod(basicDataSource2.getClass(),
DataSourceUtils.METHOD_GET_URL);
Assert.assertNotNull(method);
Assert.assertEquals("test-url", method.invoke(basicDataSource2));

// tomcat datasource
DataSource dataSource = new DataSource();
dataSource.setUrl("test-url");
Expand Down