1 21 22 package org.apache.derby.client.am; 23 24 import org.apache.derby.shared.common.reference.JDBC40Translation; 25 import org.apache.derby.shared.common.reference.SQLState; 26 27 import java.io.InputStream ; 28 import java.io.Reader ; 29 import java.sql.SQLException ; 30 import java.util.ArrayList ; 31 import org.apache.derby.client.ClientPooledConnection; 32 import org.apache.derby.jdbc.ClientDriver; 33 34 public class PreparedStatement extends Statement 35 implements java.sql.PreparedStatement , 36 PreparedStatementCallbackInterface { 37 43 public MaterialPreparedStatement materialPreparedStatement_ = null; 45 46 48 public String sql_; 49 50 public boolean outputRegistered_ = false; 53 54 public Object [] parameters_; 56 57 boolean[] parameterSet_; 58 boolean[] parameterRegistered_; 59 60 void setInput(int parameterIndex, Object input) { 61 parameters_[parameterIndex - 1] = input; 62 parameterSet_[parameterIndex - 1] = true; 63 } 64 65 public ColumnMetaData parameterMetaData_; 67 private ArrayList parameterTypeList; 68 69 70 String positionedUpdateCursorName_ = null; 78 79 protected final ClientPooledConnection pooledConnection_; 82 83 84 private void initPreparedStatement() { 85 materialPreparedStatement_ = null; 86 sql_ = null; 87 outputRegistered_ = false; 88 parameters_ = null; 89 parameterSet_ = null; 90 parameterRegistered_ = null; 91 parameterMetaData_ = null; 92 parameterTypeList = null; 93 isAutoCommittableStatement_ = true; 94 isPreparedStatement_ = true; 95 } 96 97 protected void initResetPreparedStatement() { 98 outputRegistered_ = false; 99 isPreparedStatement_ = true; 100 101 if (parameterMetaData_ != null) { 102 resetParameters(); 103 } 104 } 105 106 public void reset(boolean fullReset) throws SqlException { 107 if (fullReset) { 108 connection_.resetPrepareStatement(this); 109 } else { 110 super.initResetPreparedStatement(); 111 initResetPreparedStatement(); 112 } 113 } 114 115 private void resetParameters() { 116 for (int i = 0; i < parameterMetaData_.columns_; i++) { 117 parameters_[i] = null; 118 parameterSet_[i] = false; 119 parameterRegistered_[i] = false; 120 } 121 } 122 123 146 147 public PreparedStatement(Agent agent, 148 Connection connection, 149 String sql, 150 Section section,ClientPooledConnection cpc) 151 throws SqlException { 152 super(agent, connection); 153 isPoolable = true; 155 initPreparedStatement(sql, section); 156 pooledConnection_ = cpc; 157 } 158 159 public void resetPreparedStatement(Agent agent, 160 Connection connection, 161 String sql, 162 Section section) throws SqlException { 163 super.resetStatement(agent, connection); 164 initPreparedStatement(); 165 initPreparedStatement(sql, section); 166 } 167 168 private void initPreparedStatement(String sql, Section section) throws SqlException { 169 sql_ = sql; 170 isPreparedStatement_ = true; 171 172 parseSqlAndSetSqlModes(sql_); 173 section_ = section; 174 } 175 176 203 public PreparedStatement(Agent agent, 204 Connection connection, 205 String sql, 206 int type, int concurrency, int holdability, 207 int autoGeneratedKeys, String [] columnNames, 208 ClientPooledConnection cpc) 209 throws SqlException { 210 super(agent, connection, type, concurrency, holdability, 211 autoGeneratedKeys, columnNames); 212 isPoolable = true; 214 initPreparedStatement(sql); 215 pooledConnection_ = cpc; 216 } 217 218 219 public void resetPreparedStatement(Agent agent, 220 Connection connection, 221 String sql, 222 int type, int concurrency, int holdability, int autoGeneratedKeys, String [] columnNames) throws SqlException { 223 super.resetStatement(agent, connection, type, concurrency, holdability, autoGeneratedKeys, columnNames); 224 initPreparedStatement(); 225 initPreparedStatement(sql); 226 } 227 228 private void initPreparedStatement(String sql) throws SqlException { 229 sql_ = super.escape(sql); 230 parseSqlAndSetSqlModes(sql_); 231 isPreparedStatement_ = true; 232 233 String cursorName = null; 237 if (sqlUpdateMode_ == isDeleteSql__ || sqlUpdateMode_ == isUpdateSql__) { 238 String [] sqlAndCursorName = extractCursorNameFromWhereCurrentOf(sql_); 239 if (sqlAndCursorName != null) { 240 cursorName = sqlAndCursorName[0]; 241 sql_ = sqlAndCursorName[1]; 242 } 243 } 244 if (cursorName != null) { 245 positionedUpdateCursorName_ = cursorName; 246 section_ = agent_.sectionManager_.getPositionedUpdateSection(cursorName, false); 249 if (section_ == null) { 250 throw new SqlException(agent_.logWriter_, 251 new ClientMessageId(SQLState.CURSOR_INVALID_CURSOR_NAME), cursorName); 252 } 253 254 256 if (section_.getClientCursorName() != null && cursorName.compareTo(section_.getClientCursorName()) == 0) 264 { 266 sql_ = substituteClientCursorNameWithServerCursorName(sql_, section_); 267 } 268 } else { 269 section_ = agent_.sectionManager_.getDynamicSection(resultSetHoldability_); 272 } 273 } 274 275 public void resetPreparedStatement(Agent agent, 276 Connection connection, 277 String sql, 278 Section section, 279 ColumnMetaData parameterMetaData, 280 ColumnMetaData resultSetMetaData) throws SqlException { 281 resetPreparedStatement(agent, connection, sql, section); 282 initPreparedStatement(parameterMetaData, resultSetMetaData); 283 } 284 285 private void initPreparedStatement(ColumnMetaData parameterMetaData, 286 ColumnMetaData resultSetMetaData) throws SqlException { 287 isPreparedStatement_ = true; 288 parameterMetaData_ = parameterMetaData; 289 resultSetMetaData_ = resultSetMetaData; 290 if (parameterMetaData_ != null) { 291 parameters_ = new Object [parameterMetaData_.columns_]; 292 parameterSet_ = new boolean[parameterMetaData_.columns_]; 294 parameterRegistered_ = new boolean[parameterMetaData_.columns_]; 295 } 296 } 297 298 void prepare() throws SqlException { 300 try { 301 if (sqlUpdateMode_ == isInsertSql__ && generatedKeysColumnNames_ != null) { 305 flowPrepareForSelectFromInsert(); 306 } else { 307 flowPrepareDescribeInputOutput(); 308 } 309 } catch (SqlException e) { 310 this.markClosed(); 311 throw e; 312 } 313 } 314 315 316 318 public boolean execute(String sql) throws SQLException { 319 if (agent_.loggingEnabled()) { 320 agent_.logWriter_.traceEntry(this, "execute", sql); 321 } 322 throw new SqlException(agent_.logWriter_, 323 new ClientMessageId(SQLState.NOT_FOR_PREPARED_STATEMENT), 324 "execute(String)").getSQLException(); 325 } 326 327 public java.sql.ResultSet executeQuery(String sql) throws SQLException { 328 if (agent_.loggingEnabled()) { 329 agent_.logWriter_.traceEntry(this, "executeQuery", sql); 330 } 331 throw new SqlException(agent_.logWriter_, 332 new ClientMessageId(SQLState.NOT_FOR_PREPARED_STATEMENT), 333 "executeQuery(String)").getSQLException(); 334 } 335 336 public int executeUpdate(String sql) throws SQLException { 337 if (agent_.loggingEnabled()) { 338 agent_.logWriter_.traceEntry(this, "executeUpdate", sql); 339 } 340 throw new SqlException(agent_.logWriter_, 341 new ClientMessageId(SQLState.NOT_FOR_PREPARED_STATEMENT), 342 "executeUpdate(String)").getSQLException(); 343 } 344 346 public java.sql.ResultSet executeQuery() throws SQLException { 347 try 348 { 349 synchronized (connection_) { 350 if (agent_.loggingEnabled()) { 351 agent_.logWriter_.traceEntry(this, "executeQuery"); 352 } 353 ResultSet resultSet = executeQueryX(); 354 if (agent_.loggingEnabled()) { 355 agent_.logWriter_.traceExit(this, "executeQuery", resultSet); 356 } 357 return resultSet; 358 } 359 } 360 catch ( SqlException se ) { 361 checkStatementValidity(se); 362 throw se.getSQLException(); 363 } 364 } 365 366 ResultSet executeQueryX() throws SqlException { 368 flowExecute(executeQueryMethod__); 369 return resultSet_; 370 } 371 372 373 public int executeUpdate() throws SQLException { 374 try 375 { 376 synchronized (connection_) { 377 if (agent_.loggingEnabled()) { 378 agent_.logWriter_.traceEntry(this, "executeUpdate"); 379 } 380 int updateValue = executeUpdateX(); 381 if (agent_.loggingEnabled()) { 382 agent_.logWriter_.traceExit(this, "executeUpdate", updateValue); 383 } 384 return updateValue; 385 } 386 } 387 catch ( SqlException se ) { 388 checkStatementValidity(se); 389 throw se.getSQLException(); 390 } 391 } 392 393 private int executeUpdateX() throws SqlException { 394 flowExecute(executeUpdateMethod__); 395 return updateCount_; 396 } 397 398 public void setNull(int parameterIndex, int jdbcType) throws SQLException { 399 try 400 { 401 synchronized (connection_) { 402 if (agent_.loggingEnabled()) { 403 agent_.logWriter_.traceEntry(this, "setNull", parameterIndex, jdbcType); 404 } 405 setNullX(parameterIndex, jdbcType); 406 } 407 } 408 catch ( SqlException se ) 409 { 410 throw se.getSQLException(); 411 } 412 } 413 414 void setNullX(int parameterIndex, int jdbcType) throws SqlException { 416 checkForSupportedDataType(jdbcType); 417 super.checkForClosedStatement(); parameterIndex = checkSetterPreconditions(parameterIndex); 419 parameterMetaData_.clientParamtertype_[parameterIndex - 1] = jdbcType; 420 421 if (!parameterMetaData_.nullable_[parameterIndex - 1]) { 422 throw new SqlException(agent_.logWriter_, 423 new ClientMessageId(SQLState.LANG_NULL_INTO_NON_NULL), 424 new Integer (parameterIndex)); 425 } 426 setInput(parameterIndex, null); 427 } 428 429 public void setNull(int parameterIndex, int jdbcType, String typeName) throws SQLException { 430 try 431 { 432 synchronized (connection_) { 433 if (agent_.loggingEnabled()) { 434 agent_.logWriter_.traceEntry(this, "setNull", parameterIndex, jdbcType, typeName); 435 } 436 super.checkForClosedStatement(); 437 setNull(parameterIndex, jdbcType); 438 } 439 } 440 catch ( SqlException se ) 441 { 442 throw se.getSQLException(); 443 } 444 } 445 446 public void setBoolean(int parameterIndex, boolean x) throws SQLException { 447 try 448 { 449 synchronized (connection_) { 450 if (agent_.loggingEnabled()) { 451 agent_.logWriter_.traceEntry(this, "setBoolean", parameterIndex, x); 452 } 453 parameterIndex = checkSetterPreconditions(parameterIndex); 454 parameterMetaData_.clientParamtertype_[parameterIndex - 1] = java.sql.Types.BIT; 455 setInput(parameterIndex, new Short ((short) (x ? 1 : 0))); 456 } 457 } 458 catch ( SqlException se ) 459 { 460 throw se.getSQLException(); 461 } 462 } 463 464 public void setByte(int parameterIndex, byte x) throws SQLException { 465 try 466 { 467 synchronized (connection_) { 468 if (agent_.loggingEnabled()) { 469 agent_.logWriter_.traceEntry(this, "setByte", parameterIndex, x); 470 } 471 parameterIndex = checkSetterPreconditions(parameterIndex); 472 parameterMetaData_.clientParamtertype_[parameterIndex - 1] = java.sql.Types.TINYINT; 473 setInput(parameterIndex, new Short (x)); 474 } 475 } 476 catch ( SqlException se ) 477 { 478 throw se.getSQLException(); 479 } 480 } 481 482 public void setShort(int parameterIndex, short x) throws SQLException { 483 try 484 { 485 synchronized (connection_) { 486 if (agent_.loggingEnabled()) { 487 agent_.logWriter_.traceEntry(this, "setShort", parameterIndex, x); 488 } 489 setShortX(parameterIndex, x); 490 } 491 } 492 catch ( SqlException se ) 493 { 494 throw se.getSQLException(); 495 } 496 } 497 498 void setShortX(int parameterIndex, short x) throws SqlException { 500 parameterIndex = checkSetterPreconditions(parameterIndex); 501 parameterMetaData_.clientParamtertype_[parameterIndex - 1] = java.sql.Types.SMALLINT; 502 setInput(parameterIndex, new Short (x)); 503 504 } 505 506 public void setInt(int parameterIndex, int x) throws SQLException { 507 try 508 { 509 synchronized (connection_) { 510 if (agent_.loggingEnabled()) { 511 agent_.logWriter_.traceEntry(this, "setInt", parameterIndex, x); 512 } 513 setIntX(parameterIndex, x); 514 } 515 } 516 catch ( SqlException se ) 517 { 518 throw se.getSQLException(); 519 } 520 } 521 522 void setIntX(int parameterIndex, int x) throws SqlException { 524 parameterIndex = checkSetterPreconditions(parameterIndex); 525 parameterMetaData_.clientParamtertype_[parameterIndex - 1] = java.sql.Types.INTEGER; 526 setInput(parameterIndex, new Integer (x)); 527 } 528 529 530 public void setLong(int parameterIndex, long x) throws SQLException { 531 try 532 { 533 synchronized (connection_) { 534 if (agent_.loggingEnabled()) { 535 agent_.logWriter_.traceEntry(this, "setLong", parameterIndex, x); 536 } 537 parameterIndex = checkSetterPreconditions(parameterIndex); 538 parameterMetaData_.clientParamtertype_[parameterIndex - 1] = java.sql.Types.BIGINT; 539 setInput(parameterIndex, new Long (x)); 540 } 541 } 542 catch ( SqlException se ) 543 { 544 throw se.getSQLException(); 545 } 546 } 547 548 public void setFloat(int parameterIndex, float x) throws SQLException { 549 try 550 { 551 synchronized (connection_) { 552 if (agent_.loggingEnabled()) { 553 agent_.logWriter_.traceEntry(this, "setFloat", parameterIndex, x); 554 } 555 parameterIndex = checkSetterPreconditions(parameterIndex); 556 parameterMetaData_.clientParamtertype_[parameterIndex - 1] = java.sql.Types.REAL; 557 setInput(parameterIndex, new Float (x)); 558 } 559 } 560 catch ( SqlException se ) 561 { 562 throw se.getSQLException(); 563 } 564 } 565 566 public void setDouble(int parameterIndex, double x) throws SQLException { 567 try 568 { 569 synchronized (connection_) { 570 if (agent_.loggingEnabled()) { 571 agent_.logWriter_.traceEntry(this, "setDouble", parameterIndex, x); 572 } 573 parameterIndex = checkSetterPreconditions(parameterIndex); 574 parameterMetaData_.clientParamtertype_[parameterIndex - 1] = java.sql.Types.DOUBLE; 575 setInput(parameterIndex, new Double (x)); 576 } 577 } 578 catch ( SqlException se ) 579 { 580 throw se.getSQLException(); 581 } 582 } 583 584 public void setBigDecimal(int parameterIndex, java.math.BigDecimal x) throws SQLException { 585 try 586 { 587 synchronized (connection_) { 588 if (agent_.loggingEnabled()) { 589 agent_.logWriter_.traceEntry(this, "setBigDecimal", parameterIndex, x); 590 } 591 parameterIndex = checkSetterPreconditions(parameterIndex); 592 parameterMetaData_.clientParamtertype_[parameterIndex - 1] = java.sql.Types.DECIMAL; 593 if (x == null) { 594 setNull(parameterIndex, java.sql.Types.DECIMAL); 595 return; 596 } 597 int registerOutScale = 0; 598 setInput(parameterIndex, x); 599 } 600 } 601 catch ( SqlException se ) 602 { 603 throw se.getSQLException(); 604 } 605 } 606 607 public void setDate(int parameterIndex, java.sql.Date x) throws SQLException { 608 try 609 { 610 synchronized (connection_) { 611 if (agent_.loggingEnabled()) { 612 agent_.logWriter_.traceEntry(this, "setDate", parameterIndex, x); 613 } 614 checkForClosedStatement(); 615 parameterIndex = checkSetterPreconditions(parameterIndex); 616 parameterMetaData_.clientParamtertype_[parameterIndex - 1] = java.sql.Types.DATE; 617 if (x == null) { 618 setNull(parameterIndex, java.sql.Types.DATE); 619 return; 620 } 621 setInput(parameterIndex, x); 622 } 623 } 624 catch ( SqlException se ) 625 { 626 throw se.getSQLException(); 627 } 628 } 629 630 public void setDate(int parameterIndex, 631 java.sql.Date x, 632 java.util.Calendar calendar) throws SQLException { 633 try 634 { 635 synchronized (connection_) { 636 if (agent_.loggingEnabled()) { 637 agent_.logWriter_.traceEntry(this, "setDate", parameterIndex, x, calendar); 638 } 639 checkForClosedStatement(); 640 if (calendar == null) { 641 throw new SqlException(agent_.logWriter_, 642 new ClientMessageId(SQLState.INVALID_API_PARAMETER), 643 "null", "calendar", "setDate"); 644 } 645 java.util.Calendar targetCalendar = java.util.Calendar.getInstance(calendar.getTimeZone()); 646 targetCalendar.clear(); 647 targetCalendar.setTime(x); 648 java.util.Calendar defaultCalendar = java.util.Calendar.getInstance(); 649 defaultCalendar.clear(); 650 defaultCalendar.setTime(x); 651 long timeZoneOffset = 652 targetCalendar.get(java.util.Calendar.ZONE_OFFSET) - defaultCalendar.get(java.util.Calendar.ZONE_OFFSET) + 653 targetCalendar.get(java.util.Calendar.DST_OFFSET) - defaultCalendar.get(java.util.Calendar.DST_OFFSET); 654 java.sql.Date adjustedDate = ((timeZoneOffset == 0) || (x == null)) ? x : new java.sql.Date (x.getTime() + timeZoneOffset); 655 setDate(parameterIndex, adjustedDate); 656 } 657 } 658 catch ( SqlException se ) 659 { 660 throw se.getSQLException(); 661 } 662 } 663 664 public void setTime(int parameterIndex, java.sql.Time x) throws SQLException { 665 try 666 { 667 synchronized (connection_) { 668 if (agent_.loggingEnabled()) { 669 agent_.logWriter_.traceEntry(this, "setTime", parameterIndex, x); 670 } 671 parameterIndex = checkSetterPreconditions(parameterIndex); 672 parameterMetaData_.clientParamtertype_[parameterIndex - 1] = java.sql.Types.TIME; 673 if (x == null) { 674 setNull(parameterIndex, java.sql.Types.TIME); 675 return; 676 } 677 setInput(parameterIndex, x); 678 679 } 680 } 681 catch ( SqlException se ) 682 { 683 throw se.getSQLException(); 684 } 685 } 686 687 public void setTime(int parameterIndex, 688 java.sql.Time x, 689 java.util.Calendar calendar) throws SQLException { 690 try 691 { 692 synchronized (connection_) { 693 if (agent_.loggingEnabled()) { 694 agent_.logWriter_.traceEntry(this, "setTime", parameterIndex, x, calendar); 695 } 696 checkForClosedStatement(); 697 if (calendar == null) { 698 throw new SqlException(agent_.logWriter_, 699 new ClientMessageId(SQLState.INVALID_API_PARAMETER), 700 "null", "calendar", "setTime()"); 701 } 702 java.util.Calendar targetCalendar = java.util.Calendar.getInstance(calendar.getTimeZone()); 703 targetCalendar.clear(); 704 targetCalendar.setTime(x); 705 java.util.Calendar defaultCalendar = java.util.Calendar.getInstance(); 706 defaultCalendar.clear(); 707 defaultCalendar.setTime(x); 708 long timeZoneOffset = 709 targetCalendar.get(java.util.Calendar.ZONE_OFFSET) - defaultCalendar.get(java.util.Calendar.ZONE_OFFSET) + 710 targetCalendar.get(java.util.Calendar.DST_OFFSET) - defaultCalendar.get(java.util.Calendar.DST_OFFSET); 711 java.sql.Time adjustedTime = ((timeZoneOffset == 0) || (x == null)) ? x : new java.sql.Time (x.getTime() + timeZoneOffset); 712 setTime(parameterIndex, adjustedTime); 713 } 714 } 715 catch ( SqlException se ) 716 { 717 throw se.getSQLException(); 718 } 719 } 720 721 public void setTimestamp(int parameterIndex, java.sql.Timestamp x) throws SQLException { 722 try 723 { 724 synchronized (connection_) { 725 if (agent_.loggingEnabled()) { 726 agent_.logWriter_.traceEntry(this, "setTimestamp", parameterIndex, x); 727 } 728 parameterIndex = checkSetterPreconditions(parameterIndex); 729 parameterMetaData_.clientParamtertype_[parameterIndex - 1] = java.sql.Types.TIMESTAMP; 730 731 if (x == null) { 732 setNull(parameterIndex, java.sql.Types.TIMESTAMP); 733 return; 734 } 735 setInput(parameterIndex, x); 736 } 740 } 741 catch ( SqlException se ) 742 { 743 throw se.getSQLException(); 744 } 745 } 746 747 public void setTimestamp(int parameterIndex, 748 java.sql.Timestamp x, 749 java.util.Calendar calendar) throws SQLException { 750 try 751 { 752 synchronized (connection_) { 753 if (agent_.loggingEnabled()) { 754 agent_.logWriter_.traceEntry(this, "setTimestamp", parameterIndex, x, calendar); 755 } 756 checkForClosedStatement(); 757 if (calendar == null) { 758 throw new SqlException(agent_.logWriter_, 759 new ClientMessageId(SQLState.INVALID_API_PARAMETER), 760 "null", "calendar", "setTimestamp()"); 761 } 762 java.util.Calendar targetCalendar = java.util.Calendar.getInstance(calendar.getTimeZone()); 763 targetCalendar.clear(); 764 targetCalendar.setTime(x); 765 java.util.Calendar defaultCalendar = java.util.Calendar.getInstance(); 766 defaultCalendar.clear(); 767 defaultCalendar.setTime(x); 768 long timeZoneOffset = 769 targetCalendar.get(java.util.Calendar.ZONE_OFFSET) - defaultCalendar.get(java.util.Calendar.ZONE_OFFSET) + 770 targetCalendar.get(java.util.Calendar.DST_OFFSET) - defaultCalendar.get(java.util.Calendar.DST_OFFSET); 771 java.sql.Timestamp adjustedTimestamp = ((timeZoneOffset == 0) || (x == null)) ? x : new java.sql.Timestamp (x.getTime() + timeZoneOffset); 772 if (x != null) { 773 adjustedTimestamp.setNanos(x.getNanos()); 774 } 775 setTimestamp(parameterIndex, adjustedTimestamp); 776 } 777 } 778 catch ( SqlException se ) 779 { 780 throw se.getSQLException(); 781 } 782 } 783 784 public void setString(int parameterIndex, String x) throws SQLException { 785 try 786 { 787 synchronized (connection_) { 788 if (agent_.loggingEnabled()) { 789 agent_.logWriter_.traceEntry(this, "setString", parameterIndex, x); 790 } 791 setStringX(parameterIndex, x); 792 } 793 } 794 catch ( SqlException se ) 795 { 796 throw se.getSQLException(); 797 } 798 } 799 800 void setStringX(int parameterIndex, String x) throws SqlException { 802 parameterIndex = checkSetterPreconditions(parameterIndex); 803 parameterMetaData_.clientParamtertype_[parameterIndex - 1] = java.sql.Types.LONGVARCHAR; 804 if (x == null) { 805 setNullX(parameterIndex, java.sql.Types.LONGVARCHAR); 806 return; 807 } 808 setInput(parameterIndex, x); 809 } 810 811 public void setBytes(int parameterIndex, byte[] x) throws SQLException { 812 try 813 { 814 synchronized (connection_) { 815 if (agent_.loggingEnabled()) { 816 agent_.logWriter_.traceEntry(this, "setBytes", parameterIndex, x); 817 } 818 setBytesX(parameterIndex, x); 819 } 820 } 821 catch ( SqlException se ) 822 { 823 throw se.getSQLException(); 824 } 825 } 826 827 public void setBytesX(int parameterIndex, byte[] x) throws SqlException { 829 parameterIndex = checkSetterPreconditions(parameterIndex); 830 parameterMetaData_.clientParamtertype_[parameterIndex - 1] = java.sql.Types.LONGVARBINARY; 831 if (x == null) { 832 setNullX(parameterIndex, java.sql.Types.LONGVARBINARY); 833 return; 834 } 835 setInput(parameterIndex, x); 836 837 } 838 839 847 848 public void setBinaryStream(int parameterIndex, 849 java.io.InputStream x, 850 long length) throws SQLException { 851 try 852 { 853 synchronized (connection_) { 854 if (agent_.loggingEnabled()) { 855 agent_.logWriter_.traceEntry(this, "setBinaryStream", parameterIndex, "<input stream>", new Long (length)); 856 } 857 if(length > Integer.MAX_VALUE) { 858 throw new SqlException(agent_.logWriter_, 859 new ClientMessageId(SQLState.CLIENT_LENGTH_OUTSIDE_RANGE_FOR_DATATYPE), 860 new Long (length), new Integer (Integer.MAX_VALUE)).getSQLException(); 861 } 862 setBinaryStreamX(parameterIndex, x, (int)length); 863 } 864 } 865 catch ( SqlException se ) 866 { 867 throw se.getSQLException(); 868 } 869 } 870 871 879 880 public void setBinaryStream(int parameterIndex, 881 java.io.InputStream x, 882 int length) throws SQLException { 883 setBinaryStream(parameterIndex,x,(long)length); 884 } 885 886 protected void setBinaryStreamX(int parameterIndex, 887 java.io.InputStream x, 888 int length) throws SqlException { 889 parameterIndex = checkSetterPreconditions(parameterIndex); 890 parameterMetaData_.clientParamtertype_[parameterIndex - 1] = java.sql.Types.BLOB; 891 if (x == null) { 892 setNullX(parameterIndex, java.sql.Types.BLOB); 893 return; 894 } 895 Blob blob; 896 if (length == -1) { 897 blob = new Blob(agent_, x); 901 } else { 902 blob = new Blob(agent_, x, length); 903 } 904 setInput(parameterIndex, blob); 905 } 906 907 916 917 public void setAsciiStream(int parameterIndex, 918 java.io.InputStream x, 919 long length) throws SQLException { 920 try 921 { 922 synchronized (connection_) { 923 if (agent_.loggingEnabled()) { 924 agent_.logWriter_.traceEntry(this, "setAsciiStream", parameterIndex, "<input stream>", new Long (length)); 925 } 926 parameterIndex = checkSetterPreconditions(parameterIndex); 927 parameterMetaData_.clientParamtertype_[parameterIndex - 1] = java.sql.Types.CLOB; 928 if (x == null) { 929 setNull(parameterIndex, java.sql.Types.CLOB); 930 return; 931 } 932 if(length > Integer.MAX_VALUE) { 933 throw new SqlException(agent_.logWriter_, 934 new ClientMessageId(SQLState.CLIENT_LENGTH_OUTSIDE_RANGE_FOR_DATATYPE), 935 new Long (length), new Integer (Integer.MAX_VALUE)).getSQLException(); 936 } 937 setInput(parameterIndex, new Clob(agent_, x, "US-ASCII", (int)length)); 938 } 939 } 940 catch ( SqlException se ) 941 { 942 throw se.getSQLException(); 943 } 944 } 945 946 955 public void setAsciiStream(int parameterIndex, 956 java.io.InputStream x, 957 int length) throws SQLException { 958 setAsciiStream(parameterIndex,x,(long)length); 959 } 960 961 972 public void setUnicodeStream(int parameterIndex, 973 java.io.InputStream x, 974 int length) throws SQLException { 975 if (agent_.loggingEnabled()) { 976 agent_.logWriter_.traceDeprecatedEntry(this, "setUnicodeStream", 977 parameterIndex, 978 "<input stream>", length); 979 } 980 981 throw SQLExceptionFactory.notImplemented ("setUnicodeStream"); 982 } 983 984 998 public void setCharacterStream(int parameterIndex, Reader x) 999 throws SQLException { 1000 synchronized (connection_) { 1001 if (agent_.loggingEnabled()) { 1002 agent_.logWriter_.traceEntry(this, "setCharacterStream", 1003 parameterIndex, x); 1004 } 1005 try { 1006 parameterIndex = checkSetterPreconditions(parameterIndex); 1007 parameterMetaData_.clientParamtertype_[parameterIndex -1] = 1008 java.sql.Types.CLOB; 1009 if (x == null) { 1010 setNull(parameterIndex, java.sql.Types.CLOB); 1011 return; 1012 } 1013 setInput(parameterIndex, new Clob(agent_, x)); 1014 } catch (SqlException se) { 1015 throw se.getSQLException(); 1016 } 1017 } 1018 } 1019 1020 1031 1032 public void setCharacterStream(int parameterIndex, 1033 java.io.Reader x, 1034 long length) throws SQLException { 1035 try 1036 { 1037 synchronized (connection_) { 1038 if (agent_.loggingEnabled()) { 1039 agent_.logWriter_.traceEntry(this, "setCharacterStream", parameterIndex, x, new Long (length)); 1040 } 1041 parameterIndex = checkSetterPreconditions(parameterIndex); 1042 parameterMetaData_.clientParamtertype_[parameterIndex - 1] = java.sql.Types.CLOB; 1043 if (x == null) { 1044 setNull(parameterIndex, java.sql.Types.CLOB); 1045 return; 1046 } 1047 if(length > Integer.MAX_VALUE) { 1048 throw new SqlException(agent_.logWriter_, 1049 new ClientMessageId(SQLState.CLIENT_LENGTH_OUTSIDE_RANGE_FOR_DATATYPE), 1050 new Long (length), new Integer (Integer.MAX_VALUE)).getSQLException(); 1051 } 1052 setInput(parameterIndex, new Clob(agent_, x, (int)length)); 1053 } 1054 } 1055 catch ( SqlException se ) 1056 { 1057 throw se.getSQLException(); 1058 } 1059 } 1060 1061 1072 1073 public void setCharacterStream(int parameterIndex, 1074 java.io.Reader x, 1075 int length) throws SQLException { 1076 setCharacterStream(parameterIndex,x,(long)length); 1077 } 1078 1079 public void setBlob(int parameterIndex, java.sql.Blob x) throws SQLException { 1080 try 1081 { 1082 synchronized (connection_) { 1083 if (agent_.loggingEnabled()) { 1084 agent_.logWriter_.traceEntry(this, "setBlob", parameterIndex, x); 1085 } 1086 setBlobX(parameterIndex, x); 1087 } 1088 } 1089 catch ( SqlException se ) 1090 { 1091 throw se.getSQLException(); 1092 } 1093 } 1094 1095 public void setBlobX(int parameterIndex, java.sql.Blob x) throws SqlException { 1097 parameterIndex = checkSetterPreconditions(parameterIndex); 1098 parameterMetaData_.clientParamtertype_[parameterIndex - 1] = java.sql.Types.BLOB; 1099 if (x == null) { 1100 setNullX(parameterIndex, java.sql.Types.BLOB); 1101 return; 1102 } 1103 setInput(parameterIndex, x); 1104 } 1105 1106 public void setClob(int parameterIndex, java.sql.Clob x) throws SQLException { 1107 try 1108 { 1109 synchronized (connection_) { 1110 if (agent_.loggingEnabled()) { 1111 agent_.logWriter_.traceEntry(this, "setClob", parameterIndex, x); 1112 } 1113 setClobX(parameterIndex, x); 1114 } 1115 } 1116 catch ( SqlException se ) 1117 { 1118 throw se.getSQLException(); 1119 } 1120 } 1121 1122 void setClobX(int parameterIndex, java.sql.Clob x) throws SqlException { 1124 parameterIndex = checkSetterPreconditions(parameterIndex); 1125 parameterMetaData_.clientParamtertype_[parameterIndex - 1] = java.sql.Types.CLOB; 1126 if (x == null) { 1127 this.setNullX(parameterIndex, Types.CLOB); 1128 return; 1129 } 1130 setInput(parameterIndex, x); 1131 } 1132 1133 1134 public void setArray(int parameterIndex, java.sql.Array x) throws SQLException { 1135 try 1136 { 1137 synchronized (connection_) { 1138 if (agent_.loggingEnabled()) { 1139 agent_.logWriter_.traceEntry(this, "setArray", parameterIndex, x); 1140 } 1141 parameterIndex = checkSetterPreconditions(parameterIndex); 1142 throw new SqlException(agent_.logWriter_, 1143 new ClientMessageId(SQLState.JDBC_METHOD_NOT_IMPLEMENTED)); 1144 } 1145 } 1146 catch ( SqlException se ) 1147 { 1148 throw se.getSQLException(); 1149 } 1150 } 1151 1152 public void setRef(int parameterIndex, java.sql.Ref x) throws SQLException { 1153 try 1154 { 1155 synchronized (connection_) { 1156 if (agent_.loggingEnabled()) { 1157 agent_.logWriter_.traceEntry(this, "setRef", parameterIndex, x); 1158 } 1159 parameterIndex = checkSetterPreconditions(parameterIndex); 1160 throw new SqlException(agent_.logWriter_, 1161 new ClientMessageId(SQLState.JDBC_METHOD_NOT_IMPLEMENTED)); 1162 } 1163 } 1164 catch ( SqlException se ) 1165 { 1166 throw se.getSQLException(); 1167 } 1168 } 1169 1170 public void setObject(int parameterIndex, Object x) throws SQLException { 1174 try 1175 { 1176 synchronized (connection_) { 1177 if (agent_.loggingEnabled()) { 1178 agent_.logWriter_.traceEntry(this, "setObject", parameterIndex, x); 1179 } 1180 super.checkForClosedStatement(); 1181 if (x instanceof String ) { 1182 setString(parameterIndex, (String ) x); 1183 } else if (x instanceof Integer ) { 1184 setInt(parameterIndex, ((Integer ) x).intValue()); 1185 } else if (x instanceof Double ) { 1186 setDouble(parameterIndex, ((Double ) x).doubleValue()); 1187 } else if (x instanceof Float ) { 1188 setFloat(parameterIndex, ((Float ) x).floatValue()); 1189 } else if (x instanceof Boolean ) { 1190 setBoolean(parameterIndex, ((Boolean ) x).booleanValue()); 1191 } else if (x instanceof Long ) { 1192 setLong(parameterIndex, ((Long ) x).longValue()); 1193 } else if (x instanceof byte[]) { 1194 setBytes(parameterIndex, (byte[]) x); 1195 } else if (x instanceof java.math.BigDecimal ) { 1196 setBigDecimal(parameterIndex, (java.math.BigDecimal ) x); 1197 } else if (x instanceof java.sql.Date ) { 1198 setDate(parameterIndex, (java.sql.Date ) x); 1199 } else if (x instanceof java.sql.Time ) { 1200 setTime(parameterIndex, (java.sql.Time ) x); 1201 } else if (x instanceof java.sql.Timestamp ) { 1202 setTimestamp(parameterIndex, (java.sql.Timestamp ) x); 1203 } else if (x instanceof java.sql.Blob ) { 1204 setBlob(parameterIndex, (java.sql.Blob ) x); 1205 } else if (x instanceof java.sql.Clob ) { 1206 setClob(parameterIndex, (java.sql.Clob ) x); 1207 } else if (x instanceof java.sql.Array ) { 1208 setArray(parameterIndex, (java.sql.Array ) x); 1209 } else if (x instanceof java.sql.Ref ) { 1210 setRef(parameterIndex, (java.sql.Ref ) x); 1211 } else if (x instanceof Short ) { 1212 setShort(parameterIndex, ((Short ) x).shortValue()); 1213 } else if (x instanceof Byte ) { 1214 setByte(parameterIndex, ((Byte ) x).byteValue()); 1215 } else { 1216 checkSetterPreconditions(parameterIndex); 1217 throw new SqlException(agent_.logWriter_, 1218 new ClientMessageId(SQLState.UNSUPPORTED_TYPE)); 1219 } 1220 } 1221 } 1222 catch ( SqlException se ) 1223 { 1224 throw se.getSQLException(); 1225 } 1226 } 1227 1228 public void setObject(int parameterIndex, Object x, int targetJdbcType) throws SQLException { 1229 try 1230 { 1231 synchronized (connection_) { 1232 if (agent_.loggingEnabled()) { 1233 agent_.logWriter_.traceEntry(this, "setObject", parameterIndex, x, targetJdbcType); 1234 } 1235 setObjectX(parameterIndex, x, targetJdbcType, 0); 1236 } 1237 } 1238 catch ( SqlException se ) 1239 { 1240 throw se.getSQLException(); 1241 } 1242 } 1243 1244 public void setObject(int parameterIndex, 1245 Object x, 1246 int targetJdbcType, 1247 int scale) throws SQLException { 1248 try 1249 { 1250 synchronized (connection_) { 1251 if (agent_.loggingEnabled()) { 1252 agent_.logWriter_.traceEntry(this, "setObject", parameterIndex, x, targetJdbcType, scale); 1253 } 1254 setObjectX(parameterIndex, x, targetJdbcType, scale); 1255 } 1256 } 1257 catch ( SqlException se ) 1258 { 1259 throw se.getSQLException(); 1260 } 1261 } 1262 1263 private void setObjectX(int parameterIndex, 1264 Object x, 1265 int targetJdbcType, 1266 int scale) throws SqlException { 1267 parameterIndex = checkSetterPreconditions(parameterIndex); 1268 checkForValidScale(scale); 1269 1270 if (x == null) { 1271 setNullX(parameterIndex, targetJdbcType); 1272 return; 1273 } 1274 1275 checkForSupportedDataType(targetJdbcType); 1276 1277 1280 int inputParameterType = CrossConverters.getInputJdbcType(targetJdbcType); 1281 parameterMetaData_.clientParamtertype_[parameterIndex - 1] = inputParameterType; 1282 x = agent_.crossConverters_.setObject(inputParameterType, x); 1283 1284 try { 1286 if (targetJdbcType == java.sql.Types.DECIMAL || targetJdbcType == java.sql.Types.NUMERIC) { 1287 x = ((java.math.BigDecimal ) x).setScale(scale, java.math.BigDecimal.ROUND_DOWN); 1288 } 1289 } catch (ArithmeticException ae) { 1290 throw new SqlException(agent_.logWriter_, 1293 new ClientMessageId(SQLState.JAVA_EXCEPTION), 1294 new Object [] {ae.getClass().getName(), ae.getMessage()}, ae); 1295 } 1296 try { 1297 setObject(parameterIndex, x); 1298 } catch ( SQLException se ) { 1299 throw new SqlException(se); 1300 } 1301 } 1302 1303 public void clearParameters() throws SQLException { 1306 try 1307 { 1308 synchronized (connection_) { 1309 if (agent_.loggingEnabled()) { 1310 agent_.logWriter_.traceEntry(this, "clearParameters"); 1311 } 1312 checkForClosedStatement(); 1313 if (parameterMetaData_ != null) { 1314 for (int i = 0; i < parameters_.length; i++) { 1315 parameters_[i] = null; 1316 } 1317 1318 for (int i = 0; i < parameterSet_.length; i++) { 1319 parameterSet_[i] = false; 1320 } 1321 } 1322 } 1323 } 1324 catch ( SqlException se ) 1325 { 1326 throw se.getSQLException(); 1327 } 1328 } 1329 1330 public boolean execute() throws SQLException { 1331 try 1332 { 1333 synchronized (connection_) { 1334 if (agent_.loggingEnabled()) { 1335 agent_.logWriter_.traceEntry(this, "execute"); 1336 } 1337 boolean b = executeX(); 1338 if (agent_.loggingEnabled()) { 1339 agent_.logWriter_.traceExit(this, "execute", b); 1340 } 1341 return b; 1342 } 1343 } 1344 catch ( SqlException se ) { 1345 checkStatementValidity(se); 1346 throw se.getSQLException(); 1347 } 1348 } 1349 1350 boolean executeX() throws SqlException { 1352 flowExecute(executeMethod__); 1353 1354 return resultSet_ != null; 1355 } 1356 1357 1359 public void addBatch() throws SQLException { 1360 try 1361 { 1362 synchronized (connection_) { 1363 if (agent_.loggingEnabled()) { 1364 agent_.logWriter_.traceEntry(this, "addBatch"); 1365 } 1366 checkForClosedStatement(); 1367 checkThatAllParametersAreSet(); 1368 1369 if (parameterTypeList == null) { 1370 parameterTypeList = new ArrayList (); 1371 } 1372 1373 1377 1379 if (parameterMetaData_ != null) { 1380 Object [] inputsClone = new Object [parameters_.length]; 1381 System.arraycopy(parameters_, 0, inputsClone, 0, parameters_.length); 1382 1383 batch_.add(inputsClone); 1384 1385 parameterTypeList.add(parameterMetaData_.clientParamtertype_.clone()); 1388 } else { 1389 batch_.add(null); 1390 parameterTypeList.add(null); 1391 } 1392 } 1393 } 1394 catch ( SqlException se ) 1395 { 1396 throw se.getSQLException(); 1397 } 1398 } 1399 1400 public int[] executeBatch() throws SQLException , BatchUpdateException { 1403 try 1404 { 1405 synchronized (connection_) { 1406 if (agent_.loggingEnabled()) { 1407 agent_.logWriter_.traceEntry(this, "executeBatch"); 1408 } 1409 int[] updateCounts = null; 1410 updateCounts = executeBatchX(false); 1411 1412 if (agent_.loggingEnabled()) { 1413 agent_.logWriter_.traceExit(this, "executeBatch", updateCounts); 1414 } 1415 return updateCounts; 1416 } 1417 } 1418 catch ( SqlException se ) 1419 { 1420 throw se.getSQLException(); 1421 } 1422 } 1423 1424 public java.sql.ResultSetMetaData getMetaData() throws SQLException { 1425 try 1426 { 1427 synchronized (connection_) { 1428 if (agent_.loggingEnabled()) { 1429 agent_.logWriter_.traceEntry(this, "getMetaData"); 1430 } 1431 ColumnMetaData resultSetMetaData = getMetaDataX(); 1432 if (agent_.loggingEnabled()) { 1433 agent_.logWriter_.traceExit(this, "getMetaData", resultSetMetaData); 1434 } 1435 return resultSetMetaData; 1436 } 1437 } 1438 catch ( SqlException se ) 1439 { 1440 throw se.getSQLException(); 1441 } 1442 } 1443 1444 private ColumnMetaData getMetaDataX() throws SqlException { 1445 super.checkForClosedStatement(); 1446 return resultSetMetaData_; 1447 } 1448 1449 1451 public boolean execute(String sql, int autoGeneratedKeys) throws SQLException { 1452 if (agent_.loggingEnabled()) { 1453 agent_.logWriter_.traceEntry(this, "execute", sql, autoGeneratedKeys); 1454 } 1455 throw new SqlException(agent_.logWriter_, 1456 new ClientMessageId(SQLState.NOT_FOR_PREPARED_STATEMENT), 1457 "execute(String, int)").getSQLException(); 1458 } 1459 1460 public boolean execute(String sql, String [] columnNames) throws SQLException { 1461 if (agent_.loggingEnabled()) { 1462 agent_.logWriter_.traceEntry(this, "execute", sql, columnNames); 1463 } 1464 throw new SqlException(agent_.logWriter_, 1465 new ClientMessageId(SQLState.NOT_FOR_PREPARED_STATEMENT), 1466 "execute(String, String[])").getSQLException(); 1467 } 1468 1469 public boolean execute(String sql, int[] columnIndexes) throws SQLException { 1470 if (agent_.loggingEnabled()) { 1471 agent_.logWriter_.traceEntry(this, "execute", sql, columnIndexes); 1472 } 1473 throw new SqlException(agent_.logWriter_, 1474 new ClientMessageId(SQLState.NOT_FOR_PREPARED_STATEMENT), 1475 "execute(String, int[])").getSQLException(); 1476 } 1477 1478 public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException { 1479 if (agent_.loggingEnabled()) { 1480 agent_.logWriter_.traceEntry(this, "executeUpdate", autoGeneratedKeys); 1481 } 1482 throw new SqlException(agent_.logWriter_, 1483 new ClientMessageId(SQLState.NOT_FOR_PREPARED_STATEMENT), 1484 "executeUpdate(String, int)").getSQLException(); 1485 } 1486 1487 public int executeUpdate(String sql, String [] columnNames) throws SQLException { 1488 if (agent_.loggingEnabled()) { 1489 agent_.logWriter_.traceEntry(this, "executeUpdate", columnNames); 1490 } 1491 throw new SqlException(agent_.logWriter_, 1492 new ClientMessageId(SQLState.NOT_FOR_PREPARED_STATEMENT), 1493 "executeUpdate(String, String[])").getSQLException(); 1494 } 1495 1496 public int executeUpdate(String sql, int[] columnIndexes) throws SQLException { 1497 if (agent_.loggingEnabled()) { 1498 agent_.logWriter_.traceEntry(this, "executeUpdate", columnIndexes); 1499 } 1500 throw new SqlException(agent_.logWriter_, 1501 new ClientMessageId(SQLState.NOT_FOR_PREPARED_STATEMENT), 1502 "execute(String, int[])").getSQLException(); 1503 } 1504 1505 public void setURL(int parameterIndex, java.net.URL x) throws SQLException { 1506 if (agent_.loggingEnabled()) { 1507 agent_.logWriter_.traceEntry(this, "setURL", parameterIndex, x); 1508 } 1509 jdbc3FeatureNotSupported(false); 1510 } 1511 1512 public java.sql.ParameterMetaData getParameterMetaData() throws SQLException { 1513 try 1514 { 1515 synchronized (connection_) { 1516 if (agent_.loggingEnabled()) { 1517 agent_.logWriter_.traceEntry(this, "getParameterMetaData"); 1518 } 1519 Object parameterMetaData = getParameterMetaDataX(); 1520 if (agent_.loggingEnabled()) { 1521 agent_.logWriter_.traceExit(this, "getParameterMetaData", parameterMetaData); 1522 } 1523 return (java.sql.ParameterMetaData ) parameterMetaData; 1524 } 1525 } 1526 catch ( SqlException se ) 1527 { 1528 throw se.getSQLException(); 1529 } 1530 } 1531 1532 private ParameterMetaData getParameterMetaDataX() throws SqlException { 1533 super.checkForClosedStatement(); 1534 ParameterMetaData pm = ClientDriver.getFactory().newParameterMetaData 1535 (parameterMetaData_ != null 1536 ? parameterMetaData_ 1537 : ClientDriver.getFactory().newColumnMetaData(agent_.logWriter_, 0)); 1538 if (escapedProcedureCallWithResult_) { 1539 pm.escapedProcedureCallWithResult_ = true; 1540 } 1541 return pm; 1542 } 1543 1544 1546 public void writeExecute(Section section, 1547 ColumnMetaData parameterMetaData, 1548 Object [] inputs, 1549 int numInputColumns, 1550 boolean outputExpected, 1551 boolean chainedWritesFollowingSetLob) throws SqlException { 1557 materialPreparedStatement_.writeExecute_(section, 1558 parameterMetaData, 1559 inputs, 1560 numInputColumns, 1561 outputExpected, 1562 chainedWritesFollowingSetLob); 1563 } 1564 1565 1566 public void readExecute() throws SqlException { 1567 materialPreparedStatement_.readExecute_(); 1568 } 1569 1570 public void writeOpenQuery(Section section, 1571 int fetchSize, 1572 int resultSetType, 1573 int numInputColumns, 1574 ColumnMetaData parameterMetaData, 1575 Object [] inputs) throws SqlException { 1576 materialPreparedStatement_.writeOpenQuery_(section, 1577 fetchSize, 1578 resultSetType, 1579 numInputColumns, 1580 parameterMetaData, 1581 inputs); 1582 } 1583 1584 public void writeDescribeInput(Section section) throws SqlException { 1585 materialPreparedStatement_.writeDescribeInput_(section); 1586 } 1587 1588 public void readDescribeInput() throws SqlException { 1589 materialPreparedStatement_.readDescribeInput_(); 1590 } 1591 1592 public void completeDescribeInput(ColumnMetaData parameterMetaData, Sqlca sqlca) { 1593 int sqlcode = super.completeSqlca(sqlca); 1594 if (sqlcode < 0) { 1595 return; 1596 } 1597 1598 1599 parameterMetaData_ = parameterMetaData; 1600 1601 if (sqlMode_ != isCall__ && parameterMetaData_ != null) { 1610 for (int i = 0; i < parameterMetaData_.columns_; i++) { 1611 parameterMetaData_.sqlxParmmode_[i] = 1; } 1613 } 1614 1615 if (agent_.loggingEnabled()) { 1616 agent_.logWriter_.traceParameterMetaData(this, parameterMetaData_); 1617 } 1618 } 1619 1620 public void writeDescribeOutput(Section section) throws SqlException { 1621 materialPreparedStatement_.writeDescribeOutput_(section); 1622 } 1623 1624 public void readDescribeOutput() throws SqlException { 1625 materialPreparedStatement_.readDescribeOutput_(); 1626 } 1627 1628 public void completeDescribeOutput(ColumnMetaData resultSetMetaData, Sqlca sqlca) { 1629 int sqlcode = super.completeSqlca(sqlca); 1630 if (sqlcode < 0) { 1631 return; 1632 } 1633 resultSetMetaData_ = resultSetMetaData; 1634 if (agent_.loggingEnabled()) { 1635 agent_.logWriter_.traceResultSetMetaData(this, resultSetMetaData); 1636 } 1637 } 1638 1639 void writePrepareDescribeInputOutput() throws SqlException { 1640 writePrepareDescribeOutput(sql_, section_); 1642 writeDescribeInput(section_); 1643 } 1644 1645 void readPrepareDescribeInputOutput() throws SqlException { 1646 readPrepareDescribeOutput(); 1647 readDescribeInput(); 1648 completePrepareDescribe(); 1649 } 1650 1651 void writePrepareDescribeInput() throws SqlException { 1652 writePrepare(sql_, section_); 1655 writeDescribeInput(section_); 1656 } 1657 1658 void readPrepareDescribeInput() throws SqlException { 1659 readPrepare(); 1660 readDescribeInput(); 1661 completePrepareDescribe(); 1662 } 1663 1664 void completePrepareDescribe() { 1665 if (parameterMetaData_ == null) { 1666 return; 1667 } 1668 parameters_ = expandObjectArray(parameters_, parameterMetaData_.columns_); 1669 parameterSet_ = expandBooleanArray(parameterSet_, parameterMetaData_.columns_); 1670 parameterRegistered_ = expandBooleanArray(parameterRegistered_, parameterMetaData_.columns_); 1671 } 1672 1673 private Object [] expandObjectArray(Object [] array, int newLength) { 1674 if (array == null) { 1675 Object [] newArray = new Object [newLength]; 1676 return newArray; 1677 } 1678 if (array.length < newLength) { 1679 Object [] newArray = new Object [newLength]; 1680 System.arraycopy(array, 0, newArray, 0, array.length); 1681 return newArray; 1682 } 1683 return array; 1684 } 1685 1686 private boolean[] expandBooleanArray(boolean[] array, int newLength) { 1687 if (array == null) { 1688 boolean[] newArray = new boolean[newLength]; 1689 return newArray; 1690 } 1691 if (array.length < newLength) { 1692 boolean[] newArray = new boolean[newLength]; 1693 System.arraycopy(array, 0, newArray, 0, array.length); 1694 return newArray; 1695 } 1696 return array; 1697 } 1698 1699 void flowPrepareForSelectFromInsert() throws SqlException { 1700 agent_.beginWriteChain(this); 1701 writePrepareDescribeInputOutput(constructSelectFromInsertSQL(sql_), section_); 1702 agent_.flow(this); 1703 readPrepareDescribeInputOutput(); 1704 agent_.endReadChain(); 1705 } 1706 1707 void writePrepareDescribeInputOutput(String sql, 1708 Section section) throws SqlException { 1709 writePrepareDescribeOutput(sql, section); 1711 writeDescribeInput(section); 1712 } 1713 1714 void flowPrepareDescribeInputOutput() throws SqlException { 1715 agent_.beginWriteChain(this); 1716 if (sqlMode_ == isCall__) { 1717 writePrepareDescribeInput(); 1718 agent_.flow(this); 1719 readPrepareDescribeInput(); 1720 agent_.endReadChain(); 1721 } else { 1722 writePrepareDescribeInputOutput(); 1723 agent_.flow(this); 1724 readPrepareDescribeInputOutput(); 1725 agent_.endReadChain(); 1726 } 1727 } 1728 1729 void flowExecute(int executeType) throws SqlException { 1730 super.checkForClosedStatement(); 1731 super.clearWarningsX(); 1732 super.checkForAppropriateSqlMode(executeType, sqlMode_); 1733 checkThatAllParametersAreSet(); 1734 1735 if (sqlMode_ == isUpdate__) { 1736 updateCount_ = 0; 1737 } else { 1738 updateCount_ = -1; 1739 } 1740 1741 1746 if (sqlMode_ == isQuery__) { 1747 checkForDuplicateCursorName(); 1748 } 1749 1750 agent_.beginWriteChain(this); 1751 1752 boolean piggybackedAutocommit = super.writeCloseResultSets(true); 1754 int numInputColumns; 1755 boolean outputExpected; 1756 try 1757 { 1758 numInputColumns = (parameterMetaData_ != null) ? parameterMetaData_.getColumnCount() : 0; 1759 outputExpected = (resultSetMetaData_ != null && resultSetMetaData_.getColumnCount() > 0); 1760 } 1761 catch ( SQLException se ) 1762 { 1763 throw new SqlException(se); 1766 } 1767 boolean chainAutoCommit = false; 1768 boolean commitSubstituted = false; 1769 boolean repositionedCursor = false; 1770 boolean timeoutSent = false; 1771 ResultSet scrollableRS = null; 1772 1773 if (doWriteTimeout) { 1774 timeoutArrayList.set(0, TIMEOUT_STATEMENT + timeout_); 1775 writeSetSpecialRegister(timeoutArrayList); 1776 doWriteTimeout = false; 1777 timeoutSent = true; 1778 } 1779 switch (sqlMode_) { 1780 case isUpdate__: 1781 if (positionedUpdateCursorName_ != null) { 1782 scrollableRS = agent_.sectionManager_.getPositionedUpdateResultSet(positionedUpdateCursorName_); 1783 } 1784 if (scrollableRS != null && !scrollableRS.isRowsetCursor_) { 1785 repositionedCursor = 1786 scrollableRS.repositionScrollableResultSetBeforeJDBC1PositionedUpdateDelete(); 1787 if (!repositionedCursor) { 1788 scrollableRS = null; 1789 } 1790 } 1791 1792 chainAutoCommit = connection_.willAutoCommitGenerateFlow() && isAutoCommittableStatement_; 1793 1794 if (sqlUpdateMode_ == isInsertSql__ && generatedKeysColumnNames_ != null) { 1795 writeOpenQuery(section_, 1796 fetchSize_, 1797 resultSetType_, 1798 numInputColumns, 1799 parameterMetaData_, 1800 parameters_); 1801 } else { 1802 boolean chainOpenQueryForAutoGeneratedKeys = (sqlUpdateMode_ == isInsertSql__ && autoGeneratedKeys_ == RETURN_GENERATED_KEYS); 1803 writeExecute(section_, 1804 parameterMetaData_, 1805 parameters_, 1806 numInputColumns, 1807 outputExpected, 1808 (chainAutoCommit || chainOpenQueryForAutoGeneratedKeys) ); 1811 if (chainOpenQueryForAutoGeneratedKeys) { 1812 prepareAutoGeneratedKeysStatement(); 1813 writeOpenQuery(preparedStatementForAutoGeneratedKeys_.section_, 1814 preparedStatementForAutoGeneratedKeys_.fetchSize_, 1815 preparedStatementForAutoGeneratedKeys_.resultSetType_); 1816 } 1817 } 1818 1819 if (chainAutoCommit) { 1820 if (agent_.accumulatedReadExceptions_ != null) { 1823 connection_.writeCommitSubstitute_(); 1826 commitSubstituted = true; 1827 } else { 1828 connection_.writeCommit(); 1830 } 1831 } 1832 break; 1833 1834 case isQuery__: 1835 writeOpenQuery(section_, 1836 fetchSize_, 1837 resultSetType_, 1838 numInputColumns, 1839 parameterMetaData_, 1840 parameters_); 1841 break; 1842 1843 case isCall__: 1844 writeExecuteCall(outputRegistered_, null, 1846 section_, 1847 fetchSize_, 1848 false, resultSetType_, 1850 parameterMetaData_, 1851 parameters_); break; 1853 } 1854 1855 agent_.flow(this); 1856 1857 super.readCloseResultSets(true); 1859 if (piggybackedAutocommit) { 1863 connection_.completeTransactionStart(); 1864 } 1865 1866 super.markResultSetsClosed(true); 1868 if (timeoutSent) { 1869 readSetSpecialRegister(); } 1871 1872 switch (sqlMode_) { 1873 case isUpdate__: 1874 if (scrollableRS != null && !scrollableRS.isRowsetCursor_) { 1876 scrollableRS.readPositioningFetch_(); 1877 } 1878 1879 if (sqlUpdateMode_ == isInsertSql__ && generatedKeysColumnNames_ != null) { 1880 readOpenQuery(); 1881 if (resultSet_ != null) { 1882 generatedKeysResultSet_ = resultSet_; 1883 resultSet_ = null; 1884 updateCount_ = 1; 1885 } 1886 } else { 1887 readExecute(); 1888 1889 if (sqlUpdateMode_ == isInsertSql__ && autoGeneratedKeys_ == RETURN_GENERATED_KEYS) { 1890 readPrepareAutoGeneratedKeysStatement(); 1891 preparedStatementForAutoGeneratedKeys_.readOpenQuery(); 1892 generatedKeysResultSet_ = preparedStatementForAutoGeneratedKeys_.resultSet_; 1893 preparedStatementForAutoGeneratedKeys_.resultSet_ = null; 1894 } 1895 } 1896 1897 if (chainAutoCommit) { 1898 if (commitSubstituted) { 1899 connection_.readCommitSubstitute_(); 1900 } else { 1901 connection_.readCommit(); 1902 } 1903 } 1904 break; 1905 1906 case isQuery__: 1907 try { 1908 readOpenQuery(); 1909 } catch (DisconnectException dise) { 1910 throw dise; 1911 } catch (SqlException e) { 1912 throw e; 1913 } 1914 if (resultSet_ != null) { 1917 resultSet_.parseScrollableRowset(); 1918 1920 setupCursorNameCacheAndMappings(); 1926 } 1927 break; 1928 1929 case isCall__: 1930 readExecuteCall(); 1931 break; 1932 1933 } 1934 1935 1936 try { 1937 agent_.endReadChain(); 1938 } catch (SqlException e) { 1939 throw e; 1940 1941 } 1942 1943 if (sqlMode_ == isCall__) { 1944 parseStorProcReturnedScrollableRowset(); 1945 checkForStoredProcResultSetCount(executeType); 1946 if (connection_.autoCommit_ && resultSet_ == null && resultSetList_ == null && isAutoCommittableStatement_) { 1949 connection_.flowAutoCommit(); 1950 } 1951 } 1952 1953 if (executeType == executeUpdateMethod__ && updateCount_ < 0) { 1956 updateCount_ = 0; 1957 } 1958 1959 if (resultSet_ != null && resultSet_.resultSetHoldability_ != resultSetHoldability_ && sqlMode_ != isCall__) { 1961 throw new SqlException(agent_.logWriter_, 1962 new ClientMessageId(SQLState.UNABLE_TO_OPEN_RESULTSET_WITH_REQUESTED_HOLDABILTY), 1963 new Integer (resultSetHoldability_)); 1964 } 1965 } 1966 1967 public int[] executeBatchX(boolean supportsQueryBatchRequest) 1968 throws SqlException, SQLException , BatchUpdateException { 1969 synchronized (connection_) { 1970 checkForClosedStatement(); clearWarningsX(); return executeBatchRequestX(supportsQueryBatchRequest); 1973 } 1974 } 1975 1976 1977 private int[] executeBatchRequestX(boolean supportsQueryBatchRequest) 1978 throws SqlException, BatchUpdateException { 1979 SqlException chainBreaker = null; 1980 int batchSize = batch_.size(); 1981 int[] updateCounts = new int[batchSize]; 1982 int numInputColumns; 1983 try { 1984 numInputColumns = parameterMetaData_ == null ? 0 : parameterMetaData_.getColumnCount(); 1985 } catch ( SQLException se ) { 1986 throw new SqlException(se); 1987 } 1988 Object [] savedInputs = null; boolean timeoutSent = false; 1990 1991 if (batchSize == 0) { 1992 return updateCounts; 1993 } 1994 if (batchSize > 65534) 1999 throw new BatchUpdateException(agent_.logWriter_, 2000 new ClientMessageId(SQLState.TOO_MANY_COMMANDS_FOR_BATCH), 2001 new Integer (65534), updateCounts); 2002 2003 for (int i = 0; i < batchSize; i++) { 2007 updateCounts[i] = -3; 2008 } 2009 2010 if (!supportsQueryBatchRequest && sqlMode_ == isQuery__) { 2011 throw new BatchUpdateException(agent_.logWriter_, 2012 new ClientMessageId(SQLState.CANNOT_BATCH_QUERIES), updateCounts); 2013 } 2014 if (supportsQueryBatchRequest && sqlMode_ != isQuery__) { 2015 throw new BatchUpdateException(agent_.logWriter_, 2016 new ClientMessageId(SQLState.QUERY_BATCH_ON_NON_QUERY_STATEMENT), 2017 updateCounts); 2018 } 2019 2020 resultSetList_ = null; 2021 2022 2023 if (sqlMode_ == isQuery__) { 2024 indexOfCurrentResultSet_ = -1; resultSetList_ = new ResultSet[batchSize]; 2026 } 2027 2028 2029 savedInputs = parameters_; 2031 2032 agent_.beginBatchedWriteChain(this); 2033 boolean chainAutoCommit = connection_.willAutoCommitGenerateFlow() && isAutoCommittableStatement_; 2034 2035 if (doWriteTimeout) { 2036 timeoutArrayList.set(0, TIMEOUT_STATEMENT + timeout_); 2037 writeSetSpecialRegister(timeoutArrayList); 2038 doWriteTimeout = false; 2039 timeoutSent = true; 2040 } 2041 2042 for (int i = 0; i < batchSize; i++) { 2043 parameterMetaData_.clientParamtertype_ = (int[]) parameterTypeList.get(i); 2044 parameters_ = (Object []) batch_.get(i); 2045 2046 if (sqlMode_ != isCall__) { 2047 boolean outputExpected; 2048 try { 2049 outputExpected = (resultSetMetaData_ != null && resultSetMetaData_.getColumnCount() > 0); 2050 } catch ( SQLException se ) { 2051 throw new SqlException(se); 2052 } 2053 2054 writeExecute(section_, 2055 parameterMetaData_, 2056 parameters_, 2057 numInputColumns, 2058 outputExpected, 2059 chainAutoCommit || (i != batchSize - 1)); } else if (outputRegistered_) { 2062 throw new BatchUpdateException(agent_.logWriter_, 2063 new ClientMessageId(SQLState.OUTPUT_PARAMS_NOT_ALLOWED), 2064 updateCounts); 2065 } else { 2066 writeExecuteCall(false, null, section_, 2069 fetchSize_, 2070 true, resultSetType_, 2072 parameterMetaData_, 2073 parameters_); 2074 } 2075 } 2076 2077 boolean commitSubstituted = false; 2078 if (chainAutoCommit) { 2079 if (agent_.accumulatedReadExceptions_ != null) { 2082 connection_.writeCommitSubstitute_(); 2085 commitSubstituted = true; 2086 } else { 2087 connection_.writeCommit(); 2089 } 2090 } 2091 2092 agent_.flowBatch(this, batchSize); 2093 2094 if (timeoutSent) { 2095 readSetSpecialRegister(); } 2097 2098 try { 2099 for (int i = 0; i < batchSize; i++) { 2100 agent_.setBatchedExceptionLabelIndex(i); 2101 parameters_ = (Object []) batch_.get(i); 2102 if (sqlMode_ != isCall__) { 2103 readExecute(); 2104 } else { 2105 readExecuteCall(); 2106 } 2107 updateCounts[i] = updateCount_; 2108 2109 } 2110 2111 agent_.disableBatchedExceptionTracking(); if (chainAutoCommit) { 2113 if (!commitSubstituted) { 2114 connection_.readCommit(); 2115 } else { 2116 connection_.readCommitSubstitute_(); 2117 } 2118 } 2119 } 2120 2121 catch (SqlException e) { chainBreaker = e; 2127 chainBreaker.setNextException(new SqlException(agent_.logWriter_, 2128 new ClientMessageId(SQLState.BATCH_CHAIN_BREAKING_EXCEPTION))); 2129 } 2130 batch_.clear(); 2132 parameterTypeList = null; 2133 2134 parameters_ = savedInputs; 2136 2137 agent_.endBatchedReadChain(updateCounts, chainBreaker); 2138 2139 return updateCounts; 2140 2141 } 2142 2143 2144 2146 boolean listenToUnitOfWork_ = false; 2147 2148 public void listenToUnitOfWork() { 2149 if (!listenToUnitOfWork_) { 2150 listenToUnitOfWork_ = true; 2151 connection_.CommitAndRollbackListeners_.put(this,null); 2152 } 2153 } 2154 2155 public void completeLocalCommit(java.util.Iterator listenerIterator) { 2156 if (section_ != null) { 2157 openOnServer_ = false; 2158 } 2159 listenerIterator.remove(); 2160 listenToUnitOfWork_ = false; 2161 } 2162 2163 public void completeLocalRollback(java.util.Iterator listenerIterator) { 2164 if (section_ != null) { 2165 openOnServer_ = false; 2166 } 2167 listenerIterator.remove(); 2168 listenToUnitOfWork_ = false; 2169 } 2170 2171 2173 2177 protected String getJdbcStatementInterfaceName() { 2178 return "java.sql.PreparedStatement"; 2179 } 2180 2181 private int checkSetterPreconditions(int parameterIndex) throws SqlException { 2182 super.checkForClosedStatement(); 2183 parameterIndex = checkForEscapedCallWithResult(parameterIndex); 2184 checkForValidParameterIndex(parameterIndex); 2185 return parameterIndex; 2186 } 2187 2188 void checkForValidParameterIndex(int parameterIndex) throws SqlException { 2189 if (parameterMetaData_ == null || parameterIndex < 1 || parameterIndex > parameterMetaData_.columns_) { 2190 throw new SqlException(agent_.logWriter_, 2191 new ClientMessageId(SQLState.LANG_INVALID_PARAM_POSITION), 2192 new Integer (parameterIndex), 2193 new Integer (parameterMetaData_.columns_)); 2194 } 2195 } 2196 2197 private void checkThatAllParametersAreSet() throws SqlException { 2198 if (parameterMetaData_ != null) { 2199 for (int i = 0; i < parameterMetaData_.columns_; i++) { 2200 if (!parameterSet_[i] && !parameterRegistered_[i]) { 2201 throw new SqlException(agent_.logWriter_, 2202 new ClientMessageId(SQLState.LANG_MISSING_PARMS)); 2203 } 2204 } 2205 } 2206 } 2207 2208 2209 private int checkForEscapedCallWithResult(int parameterIndex) throws SqlException { 2210 if (escapedProcedureCallWithResult_) { 2211 if (parameterIndex == 1) { 2212 throw new SqlException(agent_.logWriter_, 2213 new ClientMessageId(SQLState.LANG_RETURN_OUTPUT_PARAM_CANNOT_BE_SET)); 2214 } else { 2215 parameterIndex--; 2216 } 2217 } 2218 return parameterIndex; 2219 } 2220 2221 void checkForValidScale(int scale) throws SqlException { 2222 if (scale < 0 || scale > 31) { 2223 throw new SqlException(agent_.logWriter_, 2224 new ClientMessageId(SQLState.BAD_SCALE_VALUE), 2225 new Integer (scale)); 2226 } 2227 } 2228 2229 2237 private void checkForSupportedDataType(int dataType) throws SqlException { 2238 2239 2250 switch (dataType) { 2251 case java.sql.Types.ARRAY: 2252 case java.sql.Types.DATALINK: 2253 case JDBC40Translation.NCHAR: 2254 case JDBC40Translation.NCLOB: 2255 case JDBC40Translation.NVARCHAR: 2256 case JDBC40Translation.LONGNVARCHAR: 2257 case java.sql.Types.REF: 2258 case JDBC40Translation.ROWID: 2259 case JDBC40Translation.SQLXML: 2260 case java.sql.Types.STRUCT: 2261 throw new SqlException 2262 (agent_.logWriter_, 2263 new ClientMessageId(SQLState.DATA_TYPE_NOT_SUPPORTED), 2264 Types.getTypeString(dataType)); 2265 } 2266 } 2267 2268 void checkScaleForINOUTDecimal(int parameterIndex, int registerOutScale) throws SqlException { 2269 java.math.BigDecimal decimalInput = (java.math.BigDecimal ) parameters_[parameterIndex - 1]; 2270 if (decimalInput == null) { 2271 return; 2272 } 2273 if (registerOutScale > parameterMetaData_.sqlScale_[parameterIndex - 1]) { 2275 int inputLength = decimalInput.toString().length(); 2276 int scaleDifference = registerOutScale - decimalInput.scale(); 2277 if (decimalInput.signum() == -1) { 2278 inputLength--; 2279 } 2280 if ((32 - scaleDifference) < inputLength) { 2282 throw new SqlException(agent_.logWriter_, 2284 new ClientMessageId(SQLState.REGOUTPARAM_SCALE_DOESNT_MATCH_SETTER)); 2285 } 2286 else { 2288 parameters_[parameterIndex - 1] = decimalInput.setScale(registerOutScale); 2289 parameterMetaData_.sqlScale_[parameterIndex - 1] = registerOutScale; 2290 } 2291 } 2292 else if (registerOutScale < parameterMetaData_.sqlScale_[parameterIndex - 1]) { 2294 try { 2296 parameters_[parameterIndex - 1] = decimalInput.setScale(registerOutScale); 2298 parameterMetaData_.sqlScale_[parameterIndex - 1] = registerOutScale; 2299 } catch (ArithmeticException e) { 2300 throw new SqlException(agent_.logWriter_, 2302 new ClientMessageId(SQLState.REGOUTPARAM_SCALE_DOESNT_MATCH_SETTER)); 2303 } 2304 } 2305 } 2306 2307 2310 protected void markClosed(boolean removeListener){ 2311 if(pooledConnection_ != null) 2312 pooledConnection_.onStatementClose(this); 2313 super.markClosed(removeListener); 2314 2315 if (parameterMetaData_ != null) { 2316 parameterMetaData_.markClosed(); 2317 parameterMetaData_ = null; 2318 } 2319 sql_ = null; 2320 2321 if (parameters_ != null) { 2324 for (int i = 0; i < parameters_.length; i++) { 2325 parameters_[i] = null; 2326 } 2327 } 2328 parameters_ = null; 2329 2330 if(removeListener) 2331 connection_.CommitAndRollbackListeners_.remove(this); 2332 } 2333 2334 2336 2349 public void setAsciiStream(int parameterIndex, InputStream x) 2350 throws SQLException { 2351 synchronized (connection_) { 2352 if (agent_.loggingEnabled()) { 2353 agent_.logWriter_.traceEntry(this, "setAsciiStream", 2354 parameterIndex, x); 2355 } 2356 try { 2357 parameterIndex = checkSetterPreconditions(parameterIndex); 2358 parameterMetaData_.clientParamtertype_[parameterIndex - 1] = java.sql.Types.CLOB; 2359 if (x == null) { 2360 setNull(parameterIndex, java.sql.Types.CLOB); 2361 return; 2362 } 2363 setInput(parameterIndex, new Clob(agent_, x, "US-ASCII")); 2364 } catch (SqlException se) { 2365 throw se.getSQLException(); 2366 } 2367 } 2368 } 2369 2370 2382 public void setBinaryStream(int parameterIndex, InputStream x) 2383 throws SQLException { 2384 synchronized (connection_) { 2385 if (agent_.loggingEnabled()) { 2386 agent_.logWriter_.traceEntry(this, "setBinaryStream", 2387 parameterIndex, x); 2388 } 2389 try { 2390 setBinaryStreamX(parameterIndex, x, -1); 2391 } catch (SqlException se) { 2392 throw se.getSQLException(); 2393 } 2394 } 2395 } 2396 2397 2410 public void setClob(int parameterIndex, Reader reader) 2411 throws SQLException { 2412 synchronized (connection_) { 2413 if (agent_.loggingEnabled()) { 2414 agent_.logWriter_.traceEntry(this, "setClob", 2415 parameterIndex, reader); 2416 } 2417 try { 2418 checkForClosedStatement(); 2419 } catch (SqlException se) { 2420 throw se.getSQLException(); 2421 } 2422 setInput(parameterIndex, new Clob(agent_, reader)); 2423 } 2424 } 2425 2426 2436 2437 public void setClob(int parameterIndex, Reader reader, long length) 2438 throws SQLException { 2439 synchronized (connection_) { 2440 if (agent_.loggingEnabled()) { 2441 agent_.logWriter_.traceEntry(this, "setClob", 2442 parameterIndex, reader, new Long (length)); 2443 } 2444 try { 2445 checkForClosedStatement(); 2446 } catch (SqlException se) { 2447 throw se.getSQLException(); 2448 } 2449 if(length > Integer.MAX_VALUE) 2450 throw new SqlException(agent_.logWriter_, 2451 new ClientMessageId(SQLState.BLOB_TOO_LARGE_FOR_CLIENT), 2452 new Long (length), new Integer (Integer.MAX_VALUE)).getSQLException(); 2453 else 2454 setInput(parameterIndex, new Clob(agent_, reader, (int)length)); 2455 } 2456 } 2457 2458 2476 public void setBlob(int parameterIndex, InputStream inputStream) 2477 throws SQLException { 2478 synchronized (connection_) { 2479 if (agent_.loggingEnabled()) { 2480 agent_.logWriter_.traceEntry(this, "setBlob", parameterIndex, 2481 inputStream); 2482 } 2483 try { 2484 setBinaryStreamX(parameterIndex, inputStream, -1); 2485 } catch (SqlException se) { 2486 throw se.getSQLException(); 2487 } 2488 } 2489 } 2490 2491 2505 2506 public void setBlob(int parameterIndex, InputStream inputStream, long length) 2507 throws SQLException { 2508 synchronized (connection_) { 2509 if (agent_.loggingEnabled()) { 2510 agent_.logWriter_.traceEntry(this, "setBlob", parameterIndex, 2511 inputStream, new Long (length)); 2512 } 2513 if(length > Integer.MAX_VALUE) 2514 throw new SqlException(agent_.logWriter_, 2515 new ClientMessageId(SQLState.BLOB_TOO_LARGE_FOR_CLIENT), 2516 new Long (length), new Integer (Integer.MAX_VALUE)).getSQLException(); 2517 else { 2518 try { 2519 setBinaryStreamX(parameterIndex, inputStream, (int)length); 2520 } catch(SqlException se){ 2521 throw se.getSQLException(); 2522 } 2523 } 2524 } 2525 } 2526 2527 2534 2535 private void checkStatementValidity(SqlException sqle) 2536 throws SQLException { 2537 2543 if(pooledConnection_!=null && isClosed()){ 2544 pooledConnection_.onStatementErrorOccurred(this, 2545 sqle.getSQLException()); 2546 } 2547 } 2548 2549} 2550 | Popular Tags |