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 {
41
41
public static final String DS_DRUID_CLASS = "com.alibaba.druid.pool.DruidDataSource" ;
42
42
43
43
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" ;
44
45
45
46
public static final String DS_C3P0_CLASS = "com.mchange.v2.c3p0.ComboPooledDataSource" ;
46
47
@@ -69,11 +70,11 @@ public static boolean isDruidDataSource(String clazzType) {
69
70
}
70
71
71
72
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 ) ;
73
74
}
74
75
75
76
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 ) );
77
78
}
78
79
79
80
public static boolean isC3p0DataSource (Object dataSource ) {
Original file line number Diff line number Diff line change 236
236
<version >1.4</version >
237
237
<scope >test</scope >
238
238
</dependency >
239
+ <dependency >
240
+ <groupId >org.apache.commons</groupId >
241
+ <artifactId >commons-dbcp2</artifactId >
242
+ <scope >test</scope >
243
+ </dependency >
239
244
<dependency >
240
245
<groupId >com.github.kstyrc</groupId >
241
246
<artifactId >embedded-redis</artifactId >
Original file line number Diff line number Diff line change @@ -51,6 +51,14 @@ public void testGetDataSourceUrl() throws Throwable {
51
51
Assert .assertNotNull (method );
52
52
Assert .assertEquals ("test-url" , method .invoke (basicDataSource ));
53
53
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
+
54
62
// tomcat datasource
55
63
DataSource dataSource = new DataSource ();
56
64
dataSource .setUrl ("test-url" );
You can’t perform that action at this time.
0 commit comments