1
2
3
4
5
6
7
8
9
10
11 package psiprobe.beans.accessors;
12
13 import org.apache.tomcat.dbcp.dbcp2.BasicDataSource;
14
15 import psiprobe.model.DataSourceInfo;
16
17
18
19
20 public class Tomcat10DbcpDatasourceAccessor implements DatasourceAccessor {
21
22 @Override
23 public DataSourceInfo getInfo(Object resource) {
24 DataSourceInfo dataSourceInfo = null;
25 if (canMap(resource)) {
26 BasicDataSource source = (BasicDataSource) resource;
27 dataSourceInfo = new DataSourceInfo();
28 dataSourceInfo.setBusyConnections(source.getNumActive());
29 dataSourceInfo.setEstablishedConnections(source.getNumIdle() + source.getNumActive());
30 dataSourceInfo.setMaxConnections(source.getMaxTotal());
31 dataSourceInfo.setJdbcUrl(source.getUrl());
32 dataSourceInfo.setUsername(source.getUsername());
33 dataSourceInfo.setResettable(false);
34 dataSourceInfo.setType("tomcat-dbcp2");
35 }
36 return dataSourceInfo;
37 }
38
39 @Override
40 public boolean reset(Object resource) {
41 return false;
42 }
43
44 @Override
45 public boolean canMap(Object resource) {
46 return "org.apache.tomcat.dbcp.dbcp2.BasicDataSource".equals(resource.getClass().getName())
47 && resource instanceof BasicDataSource;
48 }
49
50 }