1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.dbcp2.datasources;
19
20 import java.io.PrintWriter;
21 import java.sql.SQLException;
22 import java.sql.SQLFeatureNotSupportedException;
23 import java.util.logging.Logger;
24
25 import javax.sql.ConnectionPoolDataSource;
26 import javax.sql.PooledConnection;
27
28 import org.apache.commons.dbcp2.Jdbc41Bridge;
29
30
31
32
33 public class ConnectionPoolDataSourceProxy implements ConnectionPoolDataSource {
34
35 protected ConnectionPoolDataSource delegate;
36
37 public ConnectionPoolDataSourceProxy(final ConnectionPoolDataSource cpds) {
38 this.delegate = cpds;
39 }
40
41 public ConnectionPoolDataSource getDelegate() {
42 return delegate;
43 }
44
45 @Override
46 public int getLoginTimeout() throws SQLException {
47 return delegate.getLoginTimeout();
48 }
49
50 @Override
51 public PrintWriter getLogWriter() throws SQLException {
52 return delegate.getLogWriter();
53 }
54
55 @Override
56 public Logger getParentLogger() throws SQLFeatureNotSupportedException {
57 return Jdbc41Bridge.getParentLogger(delegate);
58 }
59
60
61
62
63 @Override
64 public PooledConnection getPooledConnection() throws SQLException {
65 return wrapPooledConnection(delegate.getPooledConnection());
66 }
67
68
69
70
71 @Override
72 public PooledConnection getPooledConnection(final String user, final String password)
73 throws SQLException {
74 return wrapPooledConnection(delegate.getPooledConnection(user, password));
75 }
76
77 @Override
78 public void setLoginTimeout(final int seconds) throws SQLException {
79 delegate.setLoginTimeout(seconds);
80 }
81
82 @Override
83 public void setLogWriter(final PrintWriter out) throws SQLException {
84 delegate.setLogWriter(out);
85 }
86
87
88
89
90 protected PooledConnection wrapPooledConnection(final PooledConnection pc) {
91 final PooledConnectionProxy tpc = new PooledConnectionProxy(pc);
92 tpc.setNotifyOnClose(true);
93 return tpc;
94 }
95 }