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 com.zaxxer.hikari.HikariDataSource;
14  
15  import java.sql.SQLException;
16  
17  import psiprobe.model.DataSourceInfo;
18  
19  /**
20   * The Class HikariCpDatasourceAccessor.
21   */
22  public class HikariCpDatasourceAccessor implements DatasourceAccessor {
23  
24    @Override
25    public DataSourceInfo getInfo(final Object resource) throws SQLException {
26      DataSourceInfo dataSourceInfo = null;
27      if (canMap(resource)) {
28        HikariDataSource source = (HikariDataSource) resource;
29  
30        dataSourceInfo = new DataSourceInfo();
31        dataSourceInfo.setBusyConnections(source.getHikariPoolMXBean().getActiveConnections());
32        dataSourceInfo.setEstablishedConnections(source.getHikariPoolMXBean().getTotalConnections());
33        dataSourceInfo.setMaxConnections(source.getMaximumPoolSize());
34        dataSourceInfo.setJdbcUrl(source.getJdbcUrl());
35        dataSourceInfo.setUsername(source.getUsername());
36        dataSourceInfo.setResettable(false);
37        dataSourceInfo.setType("hikari");
38      }
39      return dataSourceInfo;
40    }
41  
42    @Override
43    public boolean reset(final Object resource) {
44      return false;
45    }
46  
47    @Override
48    public boolean canMap(final Object resource) {
49      return "com.zaxxer.hikari.HikariDataSource".equals(resource.getClass().getName())
50          && resource instanceof HikariDataSource;
51    }
52  
53  }