View Javadoc
1   package org.davidmoten.rx.jdbc.pool.internal;
2   
3   import java.sql.CallableStatement;
4   import java.sql.Connection;
5   import java.sql.PreparedStatement;
6   import java.sql.SQLException;
7   
8   import org.davidmoten.rx.jdbc.internal.DelegatedConnection;
9   import org.davidmoten.rx.pool.Checkin;
10  
11  public final class PooledConnection implements DelegatedConnection {
12  
13      private final Connection connection;
14      private final Checkin checkin;
15  
16      public PooledConnection(Connection connection, Checkin checkin) {
17          this.connection = connection;
18          this.checkin = checkin;
19      }
20  
21      @Override
22      public PreparedStatement prepareStatement(String sql) throws SQLException {
23          return new ConnectionNonBlockingMemberPreparedStatement(con().prepareStatement(sql), this);
24      }
25  
26      @Override
27      public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException {
28          return new ConnectionNonBlockingMemberPreparedStatement(
29                  con().prepareStatement(sql, columnIndexes), this);
30      }
31  
32      @Override
33      public PreparedStatement prepareStatement(String sql, String[] columnNames)
34              throws SQLException {
35          return new ConnectionNonBlockingMemberPreparedStatement(
36                  con().prepareStatement(sql, columnNames), this);
37      }
38  
39      @Override
40      public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys)
41              throws SQLException {
42          return new ConnectionNonBlockingMemberPreparedStatement(
43                  con().prepareStatement(sql, autoGeneratedKeys), this);
44      }
45  
46      @Override
47      public PreparedStatement prepareStatement(String sql, int resultSetType,
48              int resultSetConcurrency, int resultSetHoldability) throws SQLException {
49          return new ConnectionNonBlockingMemberPreparedStatement(con().prepareStatement(sql,
50                  resultSetType, resultSetConcurrency, resultSetHoldability), this);
51      }
52  
53      @Override
54      public PreparedStatement prepareStatement(String sql, int resultSetType,
55              int resultSetConcurrency) throws SQLException {
56          return new ConnectionNonBlockingMemberPreparedStatement(
57                  con().prepareStatement(sql, resultSetType, resultSetConcurrency), this);
58      }
59  
60      @Override
61      public CallableStatement prepareCall(String sql) throws SQLException {
62          return new ConnectionNonBlockingMemberCallableStatement(con().prepareCall(sql), this);
63      }
64  
65      @Override
66      public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency)
67              throws SQLException {
68          return new ConnectionNonBlockingMemberCallableStatement(
69                  con().prepareCall(sql, resultSetType, resultSetConcurrency), this);
70      }
71  
72      @Override
73      public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency,
74              int resultSetHoldability) throws SQLException {
75          return new ConnectionNonBlockingMemberCallableStatement(
76                  con().prepareCall(sql, resultSetType, resultSetConcurrency, resultSetHoldability),
77                  this);
78      }
79  
80      @Override
81      public void close() {
82          // doesn't close the underlying connection, just releases it for reuse
83          checkin.checkin();
84      }
85  
86      @Override
87      public Connection con() {
88          return connection;
89      }
90  
91  }