1 21 22 package org.apache.derby.iapi.jdbc; 23 24 import org.apache.derby.iapi.reference.JDBC30Translation; 25 import org.apache.derby.iapi.reference.SQLState; 26 27 import org.apache.derby.iapi.error.StandardException; 28 import org.apache.derby.iapi.error.PublicAPI; 29 import org.apache.derby.iapi.services.info.JVMInfo; 30 import org.apache.derby.impl.jdbc.Util; 31 32 import java.sql.Connection ; 33 import java.sql.ResultSet ; 34 import java.sql.SQLException ; 35 import java.sql.SQLWarning ; 36 import java.sql.Statement ; 37 38 import java.lang.reflect.*; 39 40 43 public class BrokeredStatement implements EngineStatement 44 { 45 46 51 final BrokeredStatementControl control; 52 53 final int jdbcLevel; 54 final int resultSetType; 55 final int resultSetConcurrency; 56 final int resultSetHoldability; 57 58 61 private String cursorName; 62 private Boolean escapeProcessing; 63 64 BrokeredStatement(BrokeredStatementControl control, int jdbcLevel) throws SQLException 65 { 66 this.control = control; 67 this.jdbcLevel = jdbcLevel; 68 69 resultSetType = getResultSetType(); 72 resultSetConcurrency = getResultSetConcurrency(); 73 74 resultSetHoldability = getResultSetHoldability(); 75 } 76 77 78 public final void addBatch(String sql) 79 throws SQLException 80 { 81 getStatement().addBatch( sql); 82 } 83 84 public final void clearBatch() 85 throws SQLException 86 { 87 getStatement().clearBatch(); 88 } 89 90 public final int[] executeBatch() 91 throws SQLException 92 { 93 return getStatement().executeBatch(); 94 } 95 96 97 public final void cancel() 98 throws SQLException 99 { 100 getStatement().cancel(); 101 } 102 103 public final boolean execute(String sql) throws SQLException 104 { 105 return getStatement().execute(sql); 106 } 107 108 public final ResultSet executeQuery(String sql) throws SQLException 109 { 110 return wrapResultSet(getStatement().executeQuery(sql)); 111 } 112 113 public final int executeUpdate(String sql) throws SQLException 114 { 115 return getStatement().executeUpdate(sql); 116 } 117 118 119 130 public final void close() throws SQLException 131 { 132 getStatement().close(); 133 } 134 135 public final Connection getConnection() 136 throws SQLException 137 { 138 return getStatement().getConnection(); 139 } 140 141 public final int getFetchDirection() 142 throws SQLException 143 { 144 return getStatement().getFetchDirection(); 145 } 146 147 public final int getFetchSize() 148 throws SQLException 149 { 150 return getStatement().getFetchSize(); 151 } 152 153 public final int getMaxFieldSize() 154 throws SQLException 155 { 156 return getStatement().getMaxFieldSize(); 157 } 158 159 public final int getMaxRows() 160 throws SQLException 161 { 162 return getStatement().getMaxRows(); 163 } 164 165 public final int getResultSetConcurrency() 166 throws SQLException 167 { 168 return getStatement().getResultSetConcurrency(); 169 } 170 171 181 public final void setMaxFieldSize(int max) throws SQLException 182 { 183 getStatement().setMaxFieldSize(max); 184 } 185 186 194 public final void setMaxRows(int max) throws SQLException 195 { 196 getStatement().setMaxRows( max); 197 } 198 199 206 public final void setEscapeProcessing(boolean enable) throws SQLException 207 { 208 getStatement().setEscapeProcessing( enable); 209 escapeProcessing = enable ? Boolean.TRUE : Boolean.FALSE; 210 } 211 212 228 public final SQLWarning getWarnings() throws SQLException 229 { 230 return getStatement().getWarnings(); 231 } 232 233 238 public final void clearWarnings() throws SQLException 239 { 240 getStatement().clearWarnings(); 241 } 242 243 258 public final void setCursorName(String name) throws SQLException 259 { 260 getStatement().setCursorName( name); 261 cursorName = name; 262 } 263 264 265 274 public final ResultSet getResultSet() throws SQLException 275 { 276 return wrapResultSet(getStatement().getResultSet()); 277 } 278 279 293 public final int getUpdateCount() throws SQLException 294 { 295 return getStatement().getUpdateCount(); 296 } 297 298 311 public final boolean getMoreResults() throws SQLException 312 { 313 return getStatement().getMoreResults(); 314 } 315 316 323 public final int getResultSetType() 324 throws SQLException 325 { 326 return getStatement().getResultSetType(); 327 } 328 329 342 public final void setFetchDirection(int direction) throws SQLException 343 { 344 getStatement().setFetchDirection( direction); 345 } 346 347 360 public final void setFetchSize(int rows) throws SQLException 361 { 362 getStatement().setFetchSize( rows); 363 } 364 365 public final int getQueryTimeout() 366 throws SQLException 367 { 368 return getStatement().getQueryTimeout(); 369 } 370 371 public final void setQueryTimeout(int seconds) 372 throws SQLException 373 { 374 getStatement().setQueryTimeout( seconds); 375 } 376 377 378 381 public final boolean execute(String sql, 382 int autoGeneratedKeys) 383 throws SQLException 384 { 385 386 return getStatement().execute( sql, autoGeneratedKeys); 387 } 388 389 390 public final boolean execute(String sql, 391 int[] columnIndexes) 392 throws SQLException 393 { 394 return getStatement().execute( sql, columnIndexes); 395 } 396 397 public final boolean execute(String sql, 398 String [] columnNames) 399 throws SQLException 400 { 401 return getStatement().execute( sql, columnNames); 402 } 403 404 public final int executeUpdate(String sql, 405 int autoGeneratedKeys) 406 throws SQLException 407 { 408 int retVal = getStatement().executeUpdate( sql, autoGeneratedKeys); 409 return retVal; 410 } 411 412 public final int executeUpdate(String sql, 413 int[] columnIndexes) 414 throws SQLException 415 { 416 return getStatement().executeUpdate( sql, columnIndexes); 417 } 418 419 public final int executeUpdate(String sql, 420 String [] columnNames) 421 throws SQLException 422 { 423 424 return getStatement().executeUpdate( sql, columnNames); 425 } 426 427 428 429 444 public final boolean getMoreResults(int current) throws SQLException 445 { 446 return ((EngineStatement) getStatement()).getMoreResults( current); 447 } 448 449 461 public final ResultSet getGeneratedKeys() throws SQLException 462 { 463 return wrapResultSet(getStatement().getGeneratedKeys()); 464 } 465 466 473 public final int getResultSetHoldability() 474 throws SQLException 475 { 476 int holdability = 477 ((EngineStatement) getStatement()).getResultSetHoldability(); 478 479 return controlCheck().checkHoldCursors(holdability); 481 } 482 483 486 487 public Statement createDuplicateStatement(Connection conn, Statement oldStatement) throws SQLException { 488 489 Statement newStatement; 490 491 if (jdbcLevel == 2) 492 newStatement = conn.createStatement(resultSetType, resultSetConcurrency); 493 else 494 newStatement = conn.createStatement(resultSetType, resultSetConcurrency, 495 resultSetHoldability); 496 497 setStatementState(oldStatement, newStatement); 498 499 return newStatement; 500 } 501 502 void setStatementState(Statement oldStatement, Statement newStatement) throws SQLException { 503 if (cursorName != null) 504 newStatement.setCursorName(cursorName); 505 if (escapeProcessing != null) 506 newStatement.setEscapeProcessing(escapeProcessing.booleanValue()); 507 508 newStatement.setFetchDirection(oldStatement.getFetchDirection()); 509 newStatement.setFetchSize(oldStatement.getFetchSize()); 510 newStatement.setMaxFieldSize(oldStatement.getMaxFieldSize()); 511 newStatement.setMaxRows(oldStatement.getMaxRows()); 512 newStatement.setQueryTimeout(oldStatement.getQueryTimeout()); 513 } 514 515 public Statement getStatement() throws SQLException { 516 return control.getRealStatement(); 517 } 518 519 528 final ResultSet wrapResultSet(ResultSet rs) { 529 return control.wrapResultSet(this, rs); 530 } 531 532 537 final BrokeredStatementControl controlCheck() throws SQLException 538 { 539 getStatement().getConnection(); 541 return control; 542 } 543 544 555 public boolean isWrapperFor(Class iface) throws SQLException { 556 checkIfClosed(); 557 return iface.isInstance(this); 558 } 559 560 569 protected boolean isClosed() throws SQLException { 570 throw Util.notImplemented(); 576 } 577 578 585 protected final void checkIfClosed() 586 throws SQLException 587 { 588 if (isClosed()) { 589 throw Util.generateCsSQLException(SQLState.ALREADY_CLOSED, 590 "Statement"); 591 } 592 } 593 } 594 | Popular Tags |