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