1
2
3
4
5
6
7
8
9
10
11 package psiprobe.beans.accessors;
12
13 import com.mchange.v2.c3p0.ComboPooledDataSource;
14
15 import java.sql.SQLException;
16
17 import psiprobe.model.DataSourceInfo;
18
19
20
21
22 public class C3P0DatasourceAccessor implements DatasourceAccessor {
23
24 @Override
25 public DataSourceInfo getInfo(Object resource) throws SQLException {
26 DataSourceInfo dataSourceInfo = null;
27 if (canMap(resource)) {
28 ComboPooledDataSource source = (ComboPooledDataSource) resource;
29
30 dataSourceInfo = new DataSourceInfo();
31 dataSourceInfo.setBusyConnections(source.getNumBusyConnections());
32 dataSourceInfo.setEstablishedConnections(source.getNumConnections());
33 dataSourceInfo.setMaxConnections(source.getMaxPoolSize());
34 dataSourceInfo.setJdbcUrl(source.getJdbcUrl());
35 dataSourceInfo.setUsername(source.getUser());
36 dataSourceInfo.setResettable(true);
37 dataSourceInfo.setType("c3p0");
38 }
39 return dataSourceInfo;
40 }
41
42 @Override
43 public boolean reset(Object resource) {
44 if (canMap(resource)) {
45 ((ComboPooledDataSource) resource).hardReset();
46 return true;
47 }
48 return false;
49 }
50
51 @Override
52 public boolean canMap(Object resource) {
53 return "com.mchange.v2.c3p0.ComboPooledDataSource".equals(resource.getClass().getName())
54 && resource instanceof ComboPooledDataSource;
55 }
56 }