1 4 5 6 package org.smartlib.pool.core; 7 8 import java.sql.*; 9 10 17 18 public class SmartStatement implements Statement , Close { 19 20 private Statement stmt; 21 private boolean isClosed = false; 22 private SmartConnection sConn ; 23 private Debugger debug = new Debugger("SmartStatement", true); 24 25 SmartStatement(Statement stmt , SmartConnection sConn) { 27 28 this.stmt = stmt; 29 this.sConn = sConn; 30 31 } 32 33 private void preProcess() throws SQLException { 34 35 if (isClosed()) 36 throw new SQLException("Statement already closed"); 37 sConn.setLastAccessedTime(); 38 39 } 40 41 42 43 public ResultSet executeQuery(String sql) throws SQLException { 44 45 preProcess(); 46 return stmt.executeQuery(sql); 47 48 } 49 50 public int executeUpdate(String sql) throws SQLException { 51 52 preProcess(); 53 return stmt.executeUpdate(sql); 54 55 } 56 57 public void close() throws SQLException { 58 59 if (isClosed) 60 throw new SQLException("Statement already closed"); 61 stmt.close(); 62 debug.print("Statement Closed for:" + sConn.getOwner()); 63 isClosed = true; 64 65 } 66 67 public boolean isClosed() throws SQLException { 68 69 return isClosed; 70 71 } 72 73 public int getMaxFieldSize() throws SQLException { 74 75 preProcess(); 76 return stmt.getMaxFieldSize(); 77 78 } 79 80 public void setMaxFieldSize(int max) throws SQLException { 81 82 preProcess(); 83 stmt.setMaxFieldSize(max); 84 85 } 86 87 public int getMaxRows() throws SQLException { 88 89 preProcess(); 90 return stmt.getMaxRows(); 91 92 } 93 94 public void setMaxRows(int max) throws SQLException { 95 96 preProcess(); 97 stmt.setMaxRows(max); 98 99 } 100 101 public void setEscapeProcessing(boolean enable) throws SQLException { 102 103 preProcess(); 104 stmt.setEscapeProcessing(enable); 105 106 } 107 108 public int getQueryTimeout() throws SQLException { 109 110 preProcess(); 111 return stmt.getQueryTimeout(); 112 113 } 114 115 public void setQueryTimeout(int seconds) throws SQLException { 116 117 preProcess(); 118 stmt.setQueryTimeout(seconds); 119 120 } 121 122 public void cancel() throws SQLException { 123 124 preProcess(); 125 stmt.cancel(); 126 127 } 128 129 public SQLWarning getWarnings() throws SQLException { 130 131 preProcess(); 132 return stmt.getWarnings(); 133 134 } 135 136 public void clearWarnings() throws SQLException { 137 138 preProcess(); 139 stmt.clearWarnings(); 140 141 } 142 143 public void setCursorName(String name) throws SQLException { 144 145 preProcess(); 146 stmt.setCursorName(name); 147 148 } 149 150 public boolean execute(String sql) throws SQLException { 151 152 preProcess(); 153 return stmt.execute(sql); 154 155 } 156 157 public ResultSet getResultSet() throws SQLException { 158 159 preProcess(); 160 return stmt.getResultSet(); 161 162 } 163 164 public int getUpdateCount() throws SQLException { 165 166 preProcess(); 167 return stmt.getUpdateCount(); 168 169 } 170 171 public boolean getMoreResults() throws SQLException { 172 173 preProcess(); 174 return stmt.getMoreResults(); 175 176 } 177 178 public void setFetchDirection(int direction) throws SQLException { 179 180 preProcess(); 181 stmt.setFetchDirection(direction); 182 183 } 184 185 public int getFetchDirection() throws SQLException { 186 187 preProcess(); 188 return stmt.getFetchDirection(); 189 190 } 191 192 public void setFetchSize(int rows) throws SQLException { 193 194 preProcess(); 195 stmt.setFetchSize(rows); 196 197 } 198 199 public int getFetchSize() throws SQLException { 200 201 preProcess(); 202 return stmt.getFetchSize(); 203 204 } 205 206 public int getResultSetConcurrency() throws SQLException { 207 208 preProcess(); 209 return stmt.getResultSetConcurrency(); 210 211 } 212 213 public int getResultSetType() throws SQLException { 214 215 preProcess(); 216 return stmt.getResultSetType(); 217 218 } 219 220 public void addBatch( String sql ) throws SQLException { 221 222 preProcess(); 223 stmt.addBatch(sql); 224 225 } 226 227 public void clearBatch() throws SQLException { 228 229 preProcess(); 230 stmt.clearBatch(); 231 232 } 233 234 public int[] executeBatch() throws SQLException { 235 236 preProcess(); 237 return stmt.executeBatch(); 238 239 } 240 241 public Connection getConnection() throws SQLException { 242 243 preProcess(); 244 return stmt.getConnection(); 245 246 } 247 248 public boolean getMoreResults(int current) throws SQLException { 249 return false; } 251 252 public ResultSet getGeneratedKeys() throws SQLException { 253 return null; } 255 256 public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException { 257 return 0; } 259 260 public int executeUpdate(String sql, int columnIndexes[]) throws SQLException { 261 return 0; } 263 264 public int executeUpdate(String sql, String columnNames[]) throws SQLException { 265 return 0; } 267 268 public boolean execute(String sql, int autoGeneratedKeys) throws SQLException { 269 return false; } 271 272 public boolean execute(String sql, int columnIndexes[]) throws SQLException { 273 return false; } 275 276 public boolean execute(String sql, String columnNames[]) throws SQLException { 277 return false; } 279 280 public int getResultSetHoldability() throws SQLException { 281 return 0; } 283 284 public String toString() { 285 286 return stmt.toString(); 287 288 } 289 290 } 291 | Popular Tags |