Skip to content

Commit

Permalink
feat: support dbcp2
Browse files Browse the repository at this point in the history
  • Loading branch information
Just-CJ committed Oct 25, 2024
1 parent d8053ce commit 4a76797
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
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,11 @@ 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

0 comments on commit 4a76797

Please sign in to comment.