1 10 package org.mmbase.module.database; 11 12 import java.sql.*; 13 import org.mmbase.util.logging.Logger; 14 import org.mmbase.util.logging.Logging; 15 16 32 public class MultiStatement implements Statement { 33 private static final Logger log = Logging.getLoggerInstance(MultiStatement.class); 34 35 38 MultiConnection parent; 39 42 private Statement s; 43 44 47 MultiStatement(MultiConnection parent,Statement s) { 48 this.parent = parent; 49 this.s=s; 50 } 51 52 55 public int executeUpdate(String sql) throws SQLException { 56 parent.setLastSQL(sql); 57 return s.executeUpdate(sql); 58 } 59 60 63 public void close() throws SQLException { 64 s.close(); 65 s = null; } 67 68 71 public int getMaxFieldSize() throws SQLException { 72 return s.getMaxFieldSize(); 73 } 74 75 78 public void setMaxFieldSize(int max) throws SQLException { 79 s.setMaxFieldSize(max); 80 } 81 82 85 public int getMaxRows() throws SQLException { 86 return s.getMaxRows(); 87 } 88 89 92 public void setMaxRows(int max) throws SQLException { 93 s.setMaxRows(max); 94 } 95 96 99 public void setEscapeProcessing(boolean enable) throws SQLException { 100 s.setEscapeProcessing(enable); 101 } 102 103 106 public int getQueryTimeout() throws SQLException { 107 return s.getQueryTimeout(); 108 } 109 110 113 public void setQueryTimeout(int seconds) throws SQLException { 114 s.setQueryTimeout(seconds); 115 } 116 117 120 public void cancel() throws SQLException { 121 s.cancel(); 122 } 123 124 127 public SQLWarning getWarnings() throws SQLException { 128 return s.getWarnings(); 129 } 130 131 134 public void clearWarnings() throws SQLException { 135 s.clearWarnings(); 136 } 137 138 141 public boolean execute(String sql) throws SQLException { 142 parent.setLastSQL(sql); 143 return s.execute(sql); 144 } 145 146 149 public ResultSet getResultSet() throws SQLException { 150 return s.getResultSet(); 151 } 152 153 156 public int getUpdateCount() throws SQLException { 157 return s.getUpdateCount(); 158 } 159 160 163 public boolean getMoreResults() throws SQLException { 164 return s.getMoreResults(); 165 } 166 167 170 public void setCursorName(String name) throws SQLException { 171 s.setCursorName(name); 172 } 173 174 175 184 protected Statement checkAfterException() throws SQLException { 185 if (! org.mmbase.module.core.MMBase.getMMBase().getBuilder("object").created()) { 186 return s; 188 } 189 ResultSet rs = null; 190 try { 192 rs = s.executeQuery("SELECT 1 FROM " + org.mmbase.module.core.MMBase.getMMBase().getBuilder("object").getFullTableName() + " WHERE 1 = 0"); } catch (SQLException isqe) { 194 log.service("Found broken connection, will try to fix it."); 196 s.close(); 197 parent.parent.replaceConnection(parent); 198 s = parent.createStatement(); 199 return s; 207 } finally { 208 if (rs != null) { 209 rs.close(); 210 } 211 } 212 213 return null; 214 } 215 216 219 public ResultSet executeQuery(String sql) throws SQLException { 220 try { 221 parent.setLastSQL(sql); 222 return s.executeQuery(sql); 223 } catch (SQLException sqe) { 224 Statement ts = checkAfterException(); 225 if (ts != null) { return ts.executeQuery(sql); 227 } else { 228 throw sqe; 229 } 230 231 } 232 } 233 234 237 public int[] executeBatch() throws SQLException { 238 return s.executeBatch(); 239 } 240 241 244 public void setFetchDirection(int dir) throws SQLException { 245 s.setFetchDirection(dir); 246 } 247 248 251 public int getFetchDirection() throws SQLException { 252 return s.getFetchDirection(); 253 } 254 255 258 public int getResultSetConcurrency() throws SQLException { 259 return s.getResultSetConcurrency(); 260 } 261 262 265 public int getResultSetType() throws SQLException { 266 return s.getResultSetType(); 267 } 268 269 272 public void addBatch(String sql) throws SQLException { 273 s.addBatch(sql); 274 } 275 276 279 public void clearBatch() throws SQLException { 280 s.clearBatch(); 281 } 282 283 286 public Connection getConnection() throws SQLException { 287 return s.getConnection(); 288 } 289 290 293 public int getFetchSize() throws SQLException { 294 return s.getFetchSize(); 295 } 296 297 300 public void setFetchSize(int i) throws SQLException { 301 s.setFetchSize(i); 302 } 303 304 311 public boolean getMoreResults(int current) throws SQLException { 312 return s.getMoreResults(current); 313 } 314 315 320 public ResultSet getGeneratedKeys() throws SQLException { 321 return s.getGeneratedKeys(); 322 } 323 324 332 public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException { 333 try { 334 parent.setLastSQL(sql); 335 return s.executeUpdate(sql, autoGeneratedKeys); 336 } catch (SQLException sqe) { 337 Statement ts = checkAfterException(); 338 if (ts != null) { return ts.executeUpdate(sql, autoGeneratedKeys); 340 } else { 341 throw sqe; 342 } 343 } 344 } 345 346 354 public int executeUpdate(String sql, int[] columnIndexes) throws SQLException { 355 try { 356 parent.setLastSQL(sql); 357 return s.executeUpdate(sql, columnIndexes); 358 } catch (SQLException sqe) { 359 Statement ts = checkAfterException(); 360 if (ts != null) { return ts.executeUpdate(sql, columnIndexes); 362 } else { 363 throw sqe; 364 } 365 366 } 367 } 368 369 377 public int executeUpdate(String sql, String [] columnNames) throws SQLException { 378 try { 379 parent.setLastSQL(sql); 380 return s.executeUpdate(sql, columnNames); 381 } catch (SQLException sqe) { 382 Statement ts = checkAfterException(); 383 if (ts != null) { return ts.executeUpdate(sql, columnNames); 385 } else { 386 throw sqe; 387 } 388 389 } 390 } 391 392 400 public boolean execute(String sql, int autoGeneratedKeys) throws SQLException { 401 try { 402 parent.setLastSQL(sql); 403 return s.execute(sql, autoGeneratedKeys); 404 } catch (SQLException sqe) { 405 Statement ts = checkAfterException(); 406 if (ts != null) { return ts.execute(sql, autoGeneratedKeys); 408 } else { 409 throw sqe; 410 } 411 } 412 } 413 414 422 public boolean execute(String sql, int[] columnIndexes) throws SQLException { 423 try { 424 parent.setLastSQL(sql); 425 return s.execute(sql, columnIndexes); 426 } catch (SQLException sqe) { 427 Statement ts = checkAfterException(); 428 if (ts != null) { return ts.execute(sql, columnIndexes); 430 } else { 431 throw sqe; 432 } 433 } 434 } 435 436 444 public boolean execute(String sql, String [] columnNames) throws SQLException { 445 try { 446 parent.setLastSQL(sql); 447 return s.execute(sql, columnNames); 448 } catch (SQLException sqe) { 449 Statement ts = checkAfterException(); 450 if (ts != null) { return ts.execute(sql, columnNames); 452 } else { 453 throw sqe; 454 } 455 } 456 } 457 458 463 public int getResultSetHoldability() throws SQLException { 464 return s.getResultSetHoldability(); 465 } 466 467 } 468 469 | Popular Tags |