1 6 7 package org.jfox.jdbc.datasource; 8 9 import java.sql.CallableStatement ; 10 import java.sql.Connection ; 11 import java.sql.DatabaseMetaData ; 12 import java.sql.PreparedStatement ; 13 import java.sql.SQLException ; 14 import java.sql.SQLWarning ; 15 import java.sql.Savepoint ; 16 import java.sql.Statement ; 17 import java.util.Map ; 18 19 import org.jfox.jdbc.LoggablePreparedStatement; 20 import org.jfox.pool.AbstractPoolableObject; 21 22 25 26 public class PoolableConnection extends AbstractPoolableObject implements Connection { 27 private Connection conn; 28 private ConnectionPool pool; 29 30 void setConnection(Connection conn) { 31 this.conn = conn; 32 } 33 34 Connection getConnection() { 35 return conn; 36 } 37 38 void setPool(ConnectionPool pool) { 39 this.pool = pool; 40 } 41 42 public void rollback(Savepoint savepoint) throws SQLException { 43 checkClosed(); 44 conn.rollback(savepoint); 45 } 46 47 public PreparedStatement prepareStatement(String sql, String columnNames[]) throws SQLException { 48 checkClosed(); 49 return new LoggablePreparedStatement(conn.prepareStatement(sql, columnNames), sql); 50 } 51 52 public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException { 53 checkClosed(); 54 return conn.prepareCall(sql, resultSetType, resultSetConcurrency, resultSetHoldability); 55 } 56 57 public void rollback() throws SQLException { 58 conn.rollback(); 59 } 60 61 public DatabaseMetaData getMetaData() throws SQLException { 62 checkClosed(); 63 return conn.getMetaData(); 64 } 65 66 public SQLWarning getWarnings() throws SQLException { 67 checkClosed(); 68 return conn.getWarnings(); 69 } 70 71 public PreparedStatement prepareStatement(String sql, int columnIndexes[]) throws SQLException { 72 checkClosed(); 73 return new LoggablePreparedStatement(conn.prepareStatement(sql, columnIndexes), sql); 74 } 75 76 public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException { 77 checkClosed(); 78 return new LoggablePreparedStatement(conn.prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability), sql); 79 } 80 81 public boolean getAutoCommit() throws SQLException { 82 checkClosed(); 83 return conn.getAutoCommit(); 84 } 85 86 public String nativeSQL(String sql) throws SQLException { 87 checkClosed(); 88 return conn.nativeSQL(sql); 89 } 90 91 public void setTransactionIsolation(int level) throws SQLException { 92 checkClosed(); 93 conn.setTransactionIsolation(level); 94 } 95 96 public PreparedStatement prepareStatement(String sql) throws SQLException { 97 checkClosed(); 98 return new LoggablePreparedStatement(conn.prepareStatement(sql), sql); 99 } 100 101 public int getHoldability() throws SQLException { 102 checkClosed(); 103 return conn.getHoldability(); 104 } 105 106 public void clearWarnings() throws SQLException { 107 checkClosed(); 108 conn.clearWarnings(); 109 } 110 111 public Savepoint setSavepoint() throws SQLException { 112 checkClosed(); 113 return conn.setSavepoint(); 114 } 115 116 public Map getTypeMap() throws SQLException { 117 checkClosed(); 118 return conn.getTypeMap(); 119 } 120 121 public void setTypeMap(Map map) throws SQLException { 122 checkClosed(); 123 conn.setTypeMap(map); 124 } 125 126 public void commit() throws SQLException { 127 conn.commit(); 128 } 129 130 public void setCatalog(String catalog) throws SQLException { 131 checkClosed(); 132 conn.setCatalog(catalog); 133 } 134 135 public boolean isClosed() throws SQLException { 136 return !isAvailable(); 137 } 138 139 public void setHoldability(int holdability) throws SQLException { 140 checkClosed(); 141 conn.setHoldability(holdability); 142 } 143 144 public String getCatalog() throws SQLException { 145 checkClosed(); 146 return conn.getCatalog(); 147 } 148 149 public void setReadOnly(boolean readOnly) throws SQLException { 150 checkClosed(); 151 conn.setReadOnly(readOnly); 152 } 153 154 public Savepoint setSavepoint(String name) throws SQLException { 155 checkClosed(); 156 return conn.setSavepoint(name); 157 } 158 159 public void releaseSavepoint(Savepoint savepoint) throws SQLException { 160 checkClosed(); 161 conn.releaseSavepoint(savepoint); 162 } 163 164 public CallableStatement prepareCall(String sql) throws SQLException { 165 checkClosed(); 166 return conn.prepareCall(sql); 167 } 168 169 public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException { 170 checkClosed(); 171 return new LoggablePreparedStatement(conn.prepareStatement(sql, resultSetType, resultSetConcurrency), sql); 172 } 173 174 public void close() throws SQLException { 175 checkClosed(); 176 pool.restoreObject(this); 177 } 178 179 public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException { 180 checkClosed(); 181 return new LoggablePreparedStatement(conn.prepareStatement(sql, autoGeneratedKeys), sql); 182 } 183 184 public int getTransactionIsolation() throws SQLException { 185 checkClosed(); 186 return conn.getTransactionIsolation(); 187 } 188 189 public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException { 190 checkClosed(); 191 return conn.prepareCall(sql, resultSetType, resultSetConcurrency); 192 } 193 194 public boolean isReadOnly() throws SQLException { 195 checkClosed(); 196 return conn.isReadOnly(); 197 } 198 199 public Statement createStatement() throws SQLException { 200 checkClosed(); 201 return conn.createStatement(); 202 } 203 204 public void setAutoCommit(boolean autoCommit) throws SQLException { 205 checkClosed(); 206 conn.setAutoCommit(autoCommit); 207 } 208 209 public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException { 210 checkClosed(); 211 return conn.createStatement(resultSetType, resultSetConcurrency); 212 } 213 214 public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException { 215 checkClosed(); 216 return conn.createStatement(resultSetType, resultSetConcurrency, resultSetHoldability); 217 } 218 219 private void checkClosed() throws SQLException { 220 if(!isAvailable()) { 221 throw new SQLException ("connection closed"); 222 } 223 } 224 225 public static void main(String [] args) { 226 227 } 228 } | Popular Tags |