1
2
3
4
5
6
7
8
9
10
11 package psiprobe.beans.accessors;
12
13 import java.sql.SQLException;
14 import java.util.Properties;
15
16 import oracle.jdbc.pool.OracleConnectionCacheManager;
17 import oracle.jdbc.pool.OracleDataSource;
18
19 import psiprobe.UtilsBase;
20 import psiprobe.model.DataSourceInfo;
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40 @Deprecated
41 public class OracleDatasourceAccessor implements DatasourceAccessor {
42
43 @Override
44 public DataSourceInfo getInfo(Object resource) throws SQLException {
45 DataSourceInfo dataSourceInfo = null;
46
47 if (canMap(resource)) {
48 OracleDataSource source = (OracleDataSource) resource;
49 OracleConnectionCacheManager occm =
50 OracleConnectionCacheManager.getConnectionCacheManagerInstance();
51 Properties cacheProperties = source.getConnectionCacheProperties();
52 String cacheName = source.getConnectionCacheName();
53 cacheName = cacheName != null && occm.existsCache(cacheName) ? cacheName : null;
54
55 if (cacheProperties != null) {
56
57 dataSourceInfo = new DataSourceInfo();
58 if (cacheName != null) {
59 dataSourceInfo.setBusyConnections(occm.getNumberOfActiveConnections(cacheName));
60 dataSourceInfo.setEstablishedConnections(occm.getNumberOfAvailableConnections(cacheName)
61 + dataSourceInfo.getBusyConnections());
62 } else {
63 dataSourceInfo.setBusyConnections(0);
64 dataSourceInfo.setEstablishedConnections(0);
65 }
66
67 dataSourceInfo
68 .setMaxConnections(UtilsBase.toInt(cacheProperties.getProperty("MaxLimit"), -1));
69 dataSourceInfo.setJdbcUrl(source.getURL());
70 dataSourceInfo.setUsername(source.getUser());
71 dataSourceInfo.setResettable(true);
72 dataSourceInfo.setType("oracle-jdbc");
73 }
74 }
75 return dataSourceInfo;
76 }
77
78 @Override
79 public boolean reset(Object resource) throws SQLException {
80 if (canMap(resource)) {
81 ((OracleDataSource) resource).close();
82 return true;
83 }
84 return false;
85 }
86
87 @Override
88 public boolean canMap(Object resource) {
89 return "oracle.jdbc.pool.OracleDataSource".equals(resource.getClass().getName())
90 && resource instanceof OracleDataSource;
91 }
92 }