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.tomee.jdbc.TomEEDataSourceCreator;
14  
15  import psiprobe.model.DataSourceInfo;
16  
17  /**
18   * Datasource accessor for tomEE. sames as {@link TomEeJdbcPoolDatasourceAccessor} except different
19   * string in {@link #canMap(Object)}
20   */
21  public class TomEeJdbcPoolDatasourceAccessor implements DatasourceAccessor {
22  
23    @Override
24    public DataSourceInfo getInfo(Object resource) {
25      DataSourceInfo dataSourceInfo = null;
26      if (canMap(resource)) {
27        TomEEDataSourceCreator.TomEEDataSource source =
28            (TomEEDataSourceCreator.TomEEDataSource) resource;
29        dataSourceInfo = new DataSourceInfo();
30        dataSourceInfo.setBusyConnections(source.getNumActive());
31        dataSourceInfo.setEstablishedConnections(source.getNumIdle() + source.getNumActive());
32        dataSourceInfo.setMaxConnections(source.getMaxActive());
33        dataSourceInfo.setJdbcUrl(source.getUrl());
34        dataSourceInfo.setUsername(source.getUsername());
35        dataSourceInfo.setResettable(false);
36        dataSourceInfo.setType("tomcat-jdbc");
37      }
38      return dataSourceInfo;
39    }
40  
41    @Override
42    public boolean reset(Object resource) {
43      return false;
44    }
45  
46    @Override
47    public boolean canMap(Object resource) {
48      return "org.apache.tomee.jdbc.TomEEDataSourceCreator$TomEEDataSource"
49          .equals(resource.getClass().getName())
50          && resource instanceof TomEEDataSourceCreator.TomEEDataSource;
51    }
52  
53  }