1 4 package org.ofbiz.minerva.pool.jdbc; 5 6 import java.sql.Connection ; 7 import java.sql.ResultSet ; 8 import java.sql.Statement ; 9 import java.sql.SQLException ; 10 import java.sql.SQLWarning ; 11 12 13 20 public class StatementInPool implements Statement { 21 22 private final static String CLOSED = "Statement has been closed!"; 23 private Statement impl; 24 private ConnectionWrapper con; 25 26 29 public StatementInPool(Statement source, ConnectionWrapper owner) { 30 if (source == null || owner == null) throw new NullPointerException (); 31 impl = source; 32 con = owner; 33 } 34 35 38 public void setLastUsed() { 39 if (con != null) 40 con.setLastUsed(); 41 } 42 43 46 public void setError(SQLException e) { 47 if (con != null) 48 con.setError(e); 49 } 50 51 57 public Statement getUnderlyingStatement() { 58 return impl; 59 } 60 61 63 public void addBatch(String arg0) throws SQLException { 64 if (impl == null) throw new SQLException (CLOSED); 65 try { 66 impl.addBatch(arg0); 67 } catch (SQLException e) { 68 setError(e); 69 throw e; 70 } 71 } 72 73 public void cancel() throws SQLException { 74 if (impl == null) throw new SQLException (CLOSED); 75 try { 76 impl.cancel(); 77 } catch (SQLException e) { 78 setError(e); 79 throw e; 80 } 81 } 82 83 public void clearBatch() throws SQLException { 84 if (impl == null) throw new SQLException (CLOSED); 85 try { 86 impl.clearBatch(); 87 } catch (SQLException e) { 88 setError(e); 89 throw e; 90 } 91 } 92 93 public void clearWarnings() throws SQLException { 94 if (impl == null) throw new SQLException (CLOSED); 95 try { 96 impl.clearWarnings(); 97 } catch (SQLException e) { 98 setError(e); 99 throw e; 100 } 101 } 102 103 public void close() throws SQLException { 104 if (impl != null) { 105 impl.close(); 106 con.statementClosed(this); 107 } 108 clearFields(); 109 } 110 111 protected void clearFields() { 112 con = null; 113 impl = null; 114 } 115 116 public boolean execute(String arg0) throws SQLException { 117 if (impl == null) throw new SQLException (CLOSED); 118 try { 119 setLastUsed(); 120 return impl.execute(arg0); 121 } catch (SQLException e) { 122 setError(e); 123 throw e; 124 } 125 } 126 127 public int[] executeBatch() throws SQLException { 128 if (impl == null) throw new SQLException (CLOSED); 129 try { 130 setLastUsed(); 131 return impl.executeBatch(); 132 } catch (SQLException e) { 133 setError(e); 134 throw e; 135 } 136 } 137 138 public ResultSet executeQuery(String arg0) throws SQLException { 139 if (impl == null) throw new SQLException (CLOSED); 140 try { 141 setLastUsed(); 142 return new ResultSetInPool(impl.executeQuery(arg0), this); 143 } catch (SQLException e) { 144 setError(e); 145 throw e; 146 } 147 } 148 149 public int executeUpdate(String arg0) throws SQLException { 150 if (impl == null) throw new SQLException (CLOSED); 151 try { 152 setLastUsed(); 153 return impl.executeUpdate(arg0); 154 } catch (SQLException e) { 155 setError(e); 156 throw e; 157 } 158 } 159 160 public Connection getConnection() throws SQLException { 161 if (impl == null) throw new SQLException (CLOSED); 162 return con; 163 } 164 165 public int getFetchDirection() throws SQLException { 166 if (impl == null) throw new SQLException (CLOSED); 167 try { 168 return impl.getFetchDirection(); 169 } catch (SQLException e) { 170 setError(e); 171 throw e; 172 } 173 } 174 175 public int getFetchSize() throws SQLException { 176 if (impl == null) throw new SQLException (CLOSED); 177 try { 178 return impl.getFetchSize(); 179 } catch (SQLException e) { 180 setError(e); 181 throw e; 182 } 183 } 184 185 public int getMaxFieldSize() throws SQLException { 186 if (impl == null) throw new SQLException (CLOSED); 187 try { 188 return impl.getMaxFieldSize(); 189 } catch (SQLException e) { 190 setError(e); 191 throw e; 192 } 193 } 194 195 public int getMaxRows() throws SQLException { 196 if (impl == null) throw new SQLException (CLOSED); 197 try { 198 return impl.getMaxRows(); 199 } catch (SQLException e) { 200 setError(e); 201 throw e; 202 } 203 } 204 205 public boolean getMoreResults() throws SQLException { 206 if (impl == null) throw new SQLException (CLOSED); 207 try { 208 return impl.getMoreResults(); 209 } catch (SQLException e) { 210 setError(e); 211 throw e; 212 } 213 } 214 215 public int getQueryTimeout() throws SQLException { 216 if (impl == null) throw new SQLException (CLOSED); 217 try { 218 return impl.getQueryTimeout(); 219 } catch (SQLException e) { 220 setError(e); 221 throw e; 222 } 223 } 224 225 public ResultSet getResultSet() throws SQLException { 226 if (impl == null) throw new SQLException (CLOSED); 227 try { 228 ResultSet rs = impl.getResultSet(); 229 return rs == null ? null : new ResultSetInPool(rs, this); 230 } catch (SQLException e) { 231 setError(e); 232 throw e; 233 } 234 } 235 236 public int getResultSetConcurrency() throws SQLException { 237 if (impl == null) throw new SQLException (CLOSED); 238 try { 239 return impl.getResultSetConcurrency(); 240 } catch (SQLException e) { 241 setError(e); 242 throw e; 243 } 244 } 245 246 public int getResultSetType() throws SQLException { 247 if (impl == null) throw new SQLException (CLOSED); 248 try { 249 return impl.getResultSetType(); 250 } catch (SQLException e) { 251 setError(e); 252 throw e; 253 } 254 } 255 256 public int getUpdateCount() throws SQLException { 257 if (impl == null) throw new SQLException (CLOSED); 258 try { 259 return impl.getUpdateCount(); 260 } catch (SQLException e) { 261 setError(e); 262 throw e; 263 } 264 } 265 266 public SQLWarning getWarnings() throws SQLException { 267 if (impl == null) throw new SQLException (CLOSED); 268 try { 269 return impl.getWarnings(); 270 } catch (SQLException e) { 271 setError(e); 272 throw e; 273 } 274 } 275 276 public void setCursorName(String arg0) throws SQLException { 277 if (impl == null) throw new SQLException (CLOSED); 278 try { 279 impl.setCursorName(arg0); 280 } catch (SQLException e) { 281 setError(e); 282 throw e; 283 } 284 } 285 286 public void setEscapeProcessing(boolean arg0) throws SQLException { 287 if (impl == null) throw new SQLException (CLOSED); 288 try { 289 impl.setEscapeProcessing(arg0); 290 } catch (SQLException e) { 291 setError(e); 292 throw e; 293 } 294 } 295 296 public void setFetchDirection(int arg0) throws SQLException { 297 if (impl == null) throw new SQLException (CLOSED); 298 try { 299 impl.setFetchDirection(arg0); 300 } catch (SQLException e) { 301 setError(e); 302 throw e; 303 } 304 } 305 306 public void setFetchSize(int arg0) throws SQLException { 307 if (impl == null) throw new SQLException (CLOSED); 308 try { 309 impl.setFetchSize(arg0); 310 } catch (SQLException e) { 311 setError(e); 312 throw e; 313 } 314 } 315 316 public void setMaxFieldSize(int arg0) throws SQLException { 317 if (impl == null) throw new SQLException (CLOSED); 318 try { 319 impl.setMaxFieldSize(arg0); 320 } catch (SQLException e) { 321 setError(e); 322 throw e; 323 } 324 } 325 326 public void setMaxRows(int arg0) throws SQLException { 327 if (impl == null) throw new SQLException (CLOSED); 328 try { 329 impl.setMaxRows(arg0); 330 } catch (SQLException e) { 331 setError(e); 332 throw e; 333 } 334 } 335 336 public void setQueryTimeout(int arg0) throws SQLException { 337 if (impl == null) throw new SQLException (CLOSED); 338 try { 339 impl.setQueryTimeout(arg0); 340 } catch (SQLException e) { 341 setError(e); 342 throw e; 343 } 344 } 345 346 347 349 352 public boolean getMoreResults(int arg0) throws SQLException { 353 return false; 355 } 356 357 360 public ResultSet getGeneratedKeys() throws SQLException { 361 return null; 363 } 364 365 368 public int executeUpdate(String arg0, int arg1) throws SQLException { 369 return 0; 371 } 372 373 376 public int executeUpdate(String arg0, int[] arg1) throws SQLException { 377 return 0; 379 } 380 381 384 public int executeUpdate(String arg0, String [] arg1) throws SQLException { 385 return 0; 387 } 388 389 392 public boolean execute(String arg0, int arg1) throws SQLException { 393 return false; 395 } 396 397 400 public boolean execute(String arg0, int[] arg1) throws SQLException { 401 return false; 403 } 404 405 408 public boolean execute(String arg0, String [] arg1) throws SQLException { 409 return false; 411 } 412 413 416 public int getResultSetHoldability() throws SQLException { 417 return 0; 419 } 420 421 } 423 | Popular Tags |