1
2
3
4
5
6
7
8
9
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
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 }