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 org.apache.tomcat.dbcp.dbcp2.BasicDataSource;
14  
15  import psiprobe.model.DataSourceInfo;
16  
17  /**
18   * The Class Tomcat11DbcpDatasourceAccessor.
19   */
20  public class Tomcat11DbcpDatasourceAccessor 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  }