1
2
3
4
5
6
7
8
9
10
11 package psiprobe.beans.accessors;
12
13 import org.apache.openejb.resource.jdbc.managed.local.ManagedDataSource;
14 import org.apache.tomcat.jdbc.pool.DataSourceProxy;
15 import org.apache.tomcat.jdbc.pool.PoolConfiguration;
16
17 import psiprobe.model.DataSourceInfo;
18
19
20
21
22 public class OpenEjbManagedDatasourceAccessor implements DatasourceAccessor {
23
24 @Override
25 public DataSourceInfo getInfo(Object resource) {
26 DataSourceInfo dataSourceInfo = null;
27 if (canMap(resource)) {
28 PoolConfiguration conf = (PoolConfiguration) unwrap(resource);
29 DataSourceProxy proxy = (DataSourceProxy) conf;
30
31 dataSourceInfo = new DataSourceInfo();
32 dataSourceInfo.setBusyConnections(proxy.getNumActive());
33 dataSourceInfo.setEstablishedConnections(proxy.getNumIdle() + proxy.getNumActive());
34 dataSourceInfo.setMaxConnections(conf.getMaxActive());
35 dataSourceInfo.setJdbcUrl(conf.getUrl());
36 dataSourceInfo.setUsername(conf.getUsername());
37 dataSourceInfo.setResettable(false);
38 dataSourceInfo.setType("tomee-jdbc");
39 }
40 return dataSourceInfo;
41 }
42
43 @Override
44 public boolean reset(Object resource) {
45 return false;
46 }
47
48 @Override
49 public boolean canMap(Object resource) {
50 if ("org.apache.openejb.resource.jdbc.managed.local.ManagedDataSource"
51 .equals(resource.getClass().getName())) {
52 Object wrapped = unwrap(resource);
53 return wrapped instanceof PoolConfiguration;
54 }
55 return false;
56 }
57
58
59
60
61
62
63
64
65 private Object unwrap(Object resource) {
66 return ((ManagedDataSource) resource).getDelegate();
67 }
68
69 }