View Javadoc
1   /*
2    * Licensed under the GPL License. You may not use this file except in compliance with the License.
3    * You may obtain a copy of the License at
4    *
5    *   https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
6    *
7    * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
8    * WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
9    * PURPOSE.
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   * Accesses an Oracle Universal Connection Pool (UCP) resource.
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         * If the pool starts with 0 instances, the JDBCConnectionPoolStatistics will be null. The
33         * JDBCConnectionPoolStatistics only initializes when there is at least one connection
34         * instance created.
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  }