1
2
3
4
5
6
7
8
9
10
11 package psiprobe.beans.accessors;
12
13 import oracle.ucp.jdbc.JDBCConnectionPoolStatistics;
14 import oracle.ucp.jdbc.PoolDataSource;
15
16 import psiprobe.model.DataSourceInfo;
17
18
19
20
21 public class OracleUcpDatasourceAccessor implements DatasourceAccessor {
22
23 @Override
24 public DataSourceInfo getInfo(Object resource) {
25 DataSourceInfo dataSourceInfo = null;
26 if (canMap(resource)) {
27 PoolDataSource source = (PoolDataSource) resource;
28 JDBCConnectionPoolStatistics stats = source.getStatistics();
29
30 dataSourceInfo = new DataSourceInfo();
31
32
33
34
35
36 if (stats != null) {
37 dataSourceInfo.setBusyConnections(stats.getBorrowedConnectionsCount());
38 dataSourceInfo.setEstablishedConnections(stats.getTotalConnectionsCount());
39 } else {
40 dataSourceInfo.setBusyConnections(0);
41 dataSourceInfo.setEstablishedConnections(0);
42 }
43 dataSourceInfo.setMaxConnections(source.getMaxPoolSize());
44 dataSourceInfo.setJdbcUrl(source.getURL());
45 dataSourceInfo.setUsername(source.getUser());
46 dataSourceInfo.setResettable(false);
47 dataSourceInfo.setType("oracle-ucp");
48 }
49 return dataSourceInfo;
50 }
51
52 @Override
53 public boolean reset(Object resource) {
54 return false;
55 }
56
57 @Override
58 public boolean canMap(Object resource) {
59 return ("oracle.ucp.jdbc.PoolDataSourceImpl".equals(resource.getClass().getName())
60 || "oracle.ucp.jdbc.PoolXADataSourceImpl".equals(resource.getClass().getName()))
61 && resource instanceof PoolDataSource;
62 }
63
64 }