File tree Expand file tree Collapse file tree 3 files changed +16
-2
lines changed
sofa-tracer-plugins/sofa-tracer-datasource-plugin/src/main/java/com/alipay/sofa/tracer/plugins/datasource/utils
src/test/java/com/alipay/sofa/tracer/boot/datasource Expand file tree Collapse file tree 3 files changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -41,6 +41,7 @@ public class DataSourceUtils {
4141 public static final String DS_DRUID_CLASS = "com.alibaba.druid.pool.DruidDataSource" ;
4242
4343 public static final String DS_DBCP_CLASS = "org.apache.commons.dbcp.BasicDataSource" ;
44+ public static final String DS_DBCP2_CLASS = "org.apache.commons.dbcp2.BasicDataSource" ;
4445
4546 public static final String DS_C3P0_CLASS = "com.mchange.v2.c3p0.ComboPooledDataSource" ;
4647
@@ -69,11 +70,11 @@ public static boolean isDruidDataSource(String clazzType) {
6970 }
7071
7172 public static boolean isDbcpDataSource (Object dataSource ) {
72- return isTargetDataSource (DS_DBCP_CLASS , dataSource );
73+ return isTargetDataSource (DS_DBCP_CLASS , dataSource ) || isTargetDataSource ( DS_DBCP2_CLASS , dataSource ) ;
7374 }
7475
7576 public static boolean isDbcpDataSource (String clazzType ) {
76- return !StringUtils .isBlank (clazzType ) && DS_DBCP_CLASS .equals (clazzType );
77+ return !StringUtils .isBlank (clazzType ) && ( DS_DBCP_CLASS .equals (clazzType ) || DS_DBCP2_CLASS . equals ( clazzType ) );
7778 }
7879
7980 public static boolean isC3p0DataSource (Object dataSource ) {
Original file line number Diff line number Diff line change 236236 <version >1.4</version >
237237 <scope >test</scope >
238238 </dependency >
239+ <dependency >
240+ <groupId >org.apache.commons</groupId >
241+ <artifactId >commons-dbcp2</artifactId >
242+ <scope >test</scope >
243+ </dependency >
239244 <dependency >
240245 <groupId >com.github.kstyrc</groupId >
241246 <artifactId >embedded-redis</artifactId >
Original file line number Diff line number Diff line change @@ -51,6 +51,14 @@ public void testGetDataSourceUrl() throws Throwable {
5151 Assert .assertNotNull (method );
5252 Assert .assertEquals ("test-url" , method .invoke (basicDataSource ));
5353
54+ // dbcp2
55+ org .apache .commons .dbcp2 .BasicDataSource basicDataSource2 = new org .apache .commons .dbcp2 .BasicDataSource ();
56+ basicDataSource2 .setUrl ("test-url" );
57+ method = ReflectionUtils .findMethod (basicDataSource2 .getClass (),
58+ DataSourceUtils .METHOD_GET_URL );
59+ Assert .assertNotNull (method );
60+ Assert .assertEquals ("test-url" , method .invoke (basicDataSource2 ));
61+
5462 // tomcat datasource
5563 DataSource dataSource = new DataSource ();
5664 dataSource .setUrl ("test-url" );
You can’t perform that action at this time.
0 commit comments