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