1 21 22 package org.apache.derby.client.am; 23 24 import org.apache.derby.jdbc.ClientBaseDataSource; 25 import org.apache.derby.jdbc.ClientDataSource; 26 import org.apache.derby.shared.common.reference.JDBC30Translation; 27 import org.apache.derby.shared.common.reference.SQLState; 28 29 import java.sql.SQLException ; 30 31 public abstract class Connection implements java.sql.Connection , 32 ConnectionCallbackInterface { 33 35 36 public Agent agent_; 37 38 public DatabaseMetaData databaseMetaData_; 39 45 final java.util.WeakHashMap openStatements_ = new java.util.WeakHashMap (); 48 49 final java.util.WeakHashMap CommitAndRollbackListeners_ = new java.util.WeakHashMap (); 56 private SqlWarning warnings_ = null; 57 58 60 public transient String user_; 62 public boolean retrieveMessageText_; 63 protected boolean jdbcReadOnly_; 64 70 private int holdability = JDBC30Translation.HOLD_CURSORS_OVER_COMMIT; 71 72 public String databaseName_; 73 74 public String productID_; 78 79 protected EncryptionManager encryptionManager_; 81 82 private Statement setTransactionIsolationStmt = null; 84 85 private Statement getTransactionIsolationStmt = null; 87 88 90 protected boolean open_ = true; 91 protected boolean availableForReuse_ = false; 92 93 public int isolation_ = Configuration.defaultIsolation; 94 public boolean autoCommit_ = true; 95 protected boolean inUnitOfWork_ = false; 97 private boolean accumulated440ForMessageProcFailure_ = false; 98 private boolean accumulated444ForMessageProcFailure_ = false; 99 private boolean accumulatedSetReadOnlyWarning_ = false; 100 101 102 103 105 protected boolean isXAConnection_ = false; 107 118 public static final int XA_T0_NOT_ASSOCIATED = 0; 119 120 124 public static final int XA_T1_ASSOCIATED = 1; 125 126 129 130 private int xaState_ = XA_T0_NOT_ASSOCIATED; 131 132 public int xaHostVersion_ = 0; 134 135 public int loginTimeout_; 136 public org.apache.derby.jdbc.ClientBaseDataSource dataSource_; 137 public String serverNameIP_; 138 public int portNumber_; 139 140 public java.util.Hashtable clientCursorNameCache_ = new java.util.Hashtable (); 141 public boolean canUseCachedConnectBytes_ = false; 142 public int commBufferSize_ = 32767; 143 144 public boolean resetConnectionAtFirstSql_ = false; 146 147 149 protected Connection(org.apache.derby.client.am.LogWriter logWriter, 151 String user, 152 String password, 153 org.apache.derby.jdbc.ClientBaseDataSource dataSource) 154 throws SqlException { 155 initConnection(logWriter, user, dataSource); 156 } 157 158 protected Connection(org.apache.derby.client.am.LogWriter logWriter, 159 String user, 160 String password, 161 boolean isXAConn, 162 org.apache.derby.jdbc.ClientBaseDataSource dataSource) 163 throws SqlException { 164 isXAConnection_ = isXAConn; 165 initConnection(logWriter, user, dataSource); 166 } 167 168 protected void initConnection(org.apache.derby.client.am.LogWriter logWriter, 170 String user, 171 org.apache.derby.jdbc.ClientBaseDataSource 172 dataSource) throws SqlException { 173 if (logWriter != null) { 174 logWriter.traceConnectEntry(dataSource); 175 } 176 177 user_ = user; 178 179 databaseName_ = dataSource.getDatabaseName(); 185 String connAtrrs = dataSource.getConnectionAttributes(); 186 if(databaseName_ != null && connAtrrs != null) 187 databaseName_ = databaseName_ + ";" + connAtrrs; 188 189 retrieveMessageText_ = dataSource.getRetrieveMessageText(); 190 191 loginTimeout_ = dataSource.getLoginTimeout(); 192 dataSource_ = dataSource; 193 194 serverNameIP_ = dataSource.getServerName(); 195 portNumber_ = dataSource.getPortNumber(); 196 197 198 agent_ = newAgent_(logWriter, 199 loginTimeout_, 200 serverNameIP_, 201 portNumber_); 202 } 203 204 protected Connection(org.apache.derby.client.am.LogWriter logWriter, 206 boolean isXAConn, 207 org.apache.derby.jdbc.ClientBaseDataSource dataSource) 208 throws SqlException { 209 if (logWriter != null) { 210 logWriter.traceConnectEntry(dataSource); 211 } 212 isXAConnection_ = isXAConn; 213 214 user_ = ClientDataSource.propertyDefault_user; 215 216 databaseName_ = dataSource.getDatabaseName(); 218 retrieveMessageText_ = dataSource.getRetrieveMessageText(); 219 220 loginTimeout_ = dataSource.getLoginTimeout(); 221 dataSource_ = dataSource; 222 223 serverNameIP_ = dataSource.getServerName(); 224 portNumber_ = dataSource.getPortNumber(); 225 226 227 agent_ = newAgent_(logWriter, 228 loginTimeout_, 229 serverNameIP_, 230 portNumber_); 231 } 232 233 protected void resetConnection(LogWriter logWriter, 235 String user, 236 ClientBaseDataSource ds, 237 boolean recomputeFromDataSource) throws SqlException { 238 clearWarningsX(); 240 241 user_ = (user != null) ? user : user_; 242 243 if (ds != null && recomputeFromDataSource) { user_ = (user != null) ? user : ds.getUser(); 245 ; 246 247 retrieveMessageText_ = ds.getRetrieveMessageText(); 248 249 250 encryptionManager_ = null; 253 254 257 isolation_ = Configuration.defaultIsolation; 258 autoCommit_ = true; 259 inUnitOfWork_ = false; 260 261 loginTimeout_ = ds.getLoginTimeout(); 262 dataSource_ = ds; 263 264 holdability = JDBC30Translation.HOLD_CURSORS_OVER_COMMIT; 265 } 266 267 268 if (recomputeFromDataSource) { 269 this.agent_.resetAgent(this, logWriter, loginTimeout_, serverNameIP_, portNumber_); 270 } 271 } 272 273 protected void resetConnection(LogWriter logWriter, 274 String databaseName, 275 java.util.Properties properties) throws SqlException { 276 clearWarningsX(); 280 281 databaseName_ = databaseName; 282 user_ = ClientDataSource.getUser(properties); 283 284 retrieveMessageText_ = ClientDataSource.getRetrieveMessageText(properties); 285 286 287 encryptionManager_ = null; 290 291 294 isolation_ = Configuration.defaultIsolation; 295 autoCommit_ = true; 296 inUnitOfWork_ = false; 297 298 this.agent_.resetAgent(this, logWriter, loginTimeout_, serverNameIP_, portNumber_); 299 300 } 301 302 303 protected Connection(LogWriter logWriter, 305 int driverManagerLoginTimeout, 306 String serverName, 307 int portNumber, 308 String databaseName, 309 java.util.Properties properties) throws SqlException { 310 if (logWriter != null) { 311 logWriter.traceConnectEntry(serverName, portNumber, databaseName, properties); 312 } 313 314 databaseName_ = databaseName; 315 316 user_ = ClientDataSource.getUser(properties); 318 retrieveMessageText_ = ClientDataSource.getRetrieveMessageText(properties); 319 320 loginTimeout_ = driverManagerLoginTimeout; 321 serverNameIP_ = serverName; 322 portNumber_ = portNumber; 323 324 agent_ = newAgent_(logWriter, 325 loginTimeout_, 326 serverNameIP_, 327 portNumber_); 328 } 329 330 protected void finalize() throws java.lang.Throwable { 339 if (agent_.loggingEnabled()) { 340 agent_.logWriter_.traceEntry(this, "finalize"); 341 } 342 343 354 if (!open_) { 355 return; 356 } 357 agent_.disconnectEvent(); 358 super.finalize(); 359 } 360 361 363 synchronized public java.sql.Statement createStatement() throws SQLException { 364 try 365 { 366 if (agent_.loggingEnabled()) { 367 agent_.logWriter_.traceEntry(this, "createStatement"); 368 } 369 Statement s = createStatementX(java.sql.ResultSet.TYPE_FORWARD_ONLY, java.sql.ResultSet.CONCUR_READ_ONLY, holdability()); 370 if (agent_.loggingEnabled()) { 371 agent_.logWriter_.traceExit(this, "createStatement", s); 372 } 373 return s; 374 } 375 catch ( SqlException se ) 376 { 377 throw se.getSQLException(); 378 } 379 } 380 381 synchronized public java.sql.PreparedStatement prepareStatement(String sql) throws SQLException { 382 try 383 { 384 if (agent_.loggingEnabled()) { 385 agent_.logWriter_.traceEntry(this, "prepareStatement", sql); 386 } 387 PreparedStatement ps = prepareStatementX(sql, 388 java.sql.ResultSet.TYPE_FORWARD_ONLY, 389 java.sql.ResultSet.CONCUR_READ_ONLY, 390 holdability(), 391 java.sql.Statement.NO_GENERATED_KEYS, 392 null); 393 if (agent_.loggingEnabled()) { 394 agent_.logWriter_.traceExit(this, "prepareStatement", ps); 395 } 396 return ps; 397 } 398 catch ( SqlException se ) 399 { 400 throw se.getSQLException(); 401 } 402 } 403 404 synchronized public PreparedStatement preparePositionedUpdateStatement(String sql, Section querySection) throws SqlException { 406 checkForClosedConnection(); 407 PreparedStatement preparedStatement = newPositionedUpdatePreparedStatement_(sql, querySection); 409 preparedStatement.flowPrepareDescribeInputOutput(); 410 return preparedStatement; 420 } 421 422 synchronized public java.sql.CallableStatement prepareCall(String sql) throws SQLException { 423 try 424 { 425 if (agent_.loggingEnabled()) { 426 agent_.logWriter_.traceEntry(this, "prepareCall", sql); 427 } 428 CallableStatement cs = prepareCallX(sql, java.sql.ResultSet.TYPE_FORWARD_ONLY, java.sql.ResultSet.CONCUR_READ_ONLY, holdability()); 429 if (agent_.loggingEnabled()) { 430 agent_.logWriter_.traceExit(this, "prepareCall", cs); 431 } 432 return cs; 433 } 434 catch ( SqlException se ) 435 { 436 throw se.getSQLException(); 437 } 438 } 439 440 synchronized PreparedStatement prepareDynamicCatalogQuery(String sql) throws SqlException { 441 PreparedStatement ps = newPreparedStatement_(sql, java.sql.ResultSet.TYPE_FORWARD_ONLY, java.sql.ResultSet.CONCUR_READ_ONLY, holdability(), java.sql.Statement.NO_GENERATED_KEYS, null); 442 ps.isCatalogQuery_ = true; 443 ps.prepare(); 444 openStatements_.put(ps, null); 445 return ps; 446 } 447 448 public String nativeSQL(String sql) throws SQLException { 449 try 450 { 451 if (agent_.loggingEnabled()) { 452 agent_.logWriter_.traceEntry(this, "nativeSQL", sql); 453 } 454 String nativeSql = nativeSQLX(sql); 455 if (agent_.loggingEnabled()) { 456 agent_.logWriter_.traceExit(this, "nativeSQL", nativeSql); 457 } 458 return nativeSql; 459 } 460 catch ( SqlException se ) 461 { 462 throw se.getSQLException(); 463 } 464 465 } 466 467 synchronized public String nativeSQLX(String sql) throws SqlException { 468 checkForClosedConnection(); 469 if (sql == null) { 470 throw new SqlException(agent_.logWriter_, 471 new ClientMessageId (SQLState.NULL_SQL_TEXT)); 472 } 473 474 String trimSql = sql.trim(); 477 if (trimSql.startsWith("{")) { 478 if (trimSql.lastIndexOf("}") >= 0) { 479 return trimSql.substring(1, trimSql.lastIndexOf("}")); 480 } 481 } 482 483 return trimSql; 484 } 485 486 protected abstract boolean allowLocalCommitRollback_() throws org.apache.derby.client.am.SqlException; 489 490 synchronized public void setAutoCommit(boolean autoCommit) throws SQLException { 491 try 492 { 493 if (agent_.loggingEnabled()) { 494 agent_.logWriter_.traceEntry(this, "setAutoCommit", autoCommit); 495 } 496 checkForClosedConnection(); 497 498 if (! allowLocalCommitRollback_()) { 499 if (autoCommit) { throw new SqlException(agent_.logWriter_, 501 new ClientMessageId (SQLState.DRDA_NO_AUTOCOMMIT_UNDER_XA)); 502 } 503 } else { 504 if (autoCommit == autoCommit_) { 505 return; } 507 if (inUnitOfWork_) { 508 flowCommit(); } 510 } 511 autoCommit_ = autoCommit; 512 } 513 catch ( SqlException se ) 514 { 515 throw se.getSQLException(); 516 } 517 } 518 519 public boolean getAutoCommit() throws SQLException { 520 try 521 { 522 checkForClosedConnection(); 523 if (agent_.loggingEnabled()) { 524 agent_.logWriter_.traceExit(this, "getAutoCommit", autoCommit_); 525 } 526 if (! allowLocalCommitRollback_()) { return false; 528 } 529 return autoCommit_; 530 } 531 catch ( SqlException se ) 532 { 533 throw se.getSQLException(); 534 } 535 } 536 537 synchronized public void commit() throws SQLException { 538 try 539 { 540 if (agent_.loggingEnabled()) { 541 agent_.logWriter_.traceEntry(this, "commit"); 542 } 543 checkForClosedConnection(); 544 545 checkForInvalidXAStateOnCommitOrRollback(); 551 flowCommit(); 552 } 553 catch ( SqlException se ) 554 { 555 throw se.getSQLException(); 556 } 557 } 558 559 private void checkForInvalidXAStateOnCommitOrRollback() throws SqlException { 560 if (! allowLocalCommitRollback_()) { 561 throw new SqlException(agent_.logWriter_, 562 new ClientMessageId(SQLState.DRDA_INVALID_XA_STATE_ON_COMMIT_OR_ROLLBACK)); 563 } 564 } 565 public void flowCommit() throws SqlException { 566 573 if (isXAConnection_) { 579 agent_.beginWriteChainOutsideUOW(); 580 writeCommit(); 581 agent_.flowOutsideUOW(); 582 readCommit(); agent_.endReadChain(); 584 } else { 585 agent_.beginWriteChain(null); 586 writeCommit(); 587 agent_.flow(null); 588 readCommit(); agent_.endReadChain(); 590 } 591 592 } 593 594 public boolean flowAutoCommit() throws SqlException { 596 if (willAutoCommitGenerateFlow()) { 597 flowCommit(); 598 return true; 599 } 600 return false; 601 } 602 603 public boolean willAutoCommitGenerateFlow() throws org.apache.derby.client.am.SqlException { 604 if (!autoCommit_) { 605 return false; 606 } 607 if (! allowLocalCommitRollback_()) { 608 return false; 609 } 610 return true; 611 } 612 613 void writeAutoCommit() throws SqlException { 615 if (willAutoCommitGenerateFlow()) { 616 writeCommit(); 617 } 618 } 619 620 public void writeCommit() throws SqlException { 621 if (isXAConnection_) { 622 writeXACommit_ (); 623 } else { 624 writeLocalCommit_(); 625 } 626 } 627 628 void readAutoCommit() throws SqlException { 630 if (willAutoCommitGenerateFlow()) { 631 readCommit(); 632 } 633 } 634 635 public void readCommit() throws SqlException { 636 if (isXAConnection_) { 637 readXACommit_ (); 638 } else { 639 readLocalCommit_(); 640 } 641 } 642 643 synchronized public void rollback() throws SQLException { 644 try 645 { 646 if (agent_.loggingEnabled()) { 647 agent_.logWriter_.traceEntry(this, "rollback"); 648 } 649 650 checkForClosedConnection(); 651 checkForInvalidXAStateOnCommitOrRollback(); 652 653 flowRollback(); 654 } 655 catch ( SqlException se ) 656 { 657 throw se.getSQLException(); 658 } 659 } 660 661 protected void flowRollback() throws SqlException { 678 if (isXAConnection_) { 679 agent_.beginWriteChainOutsideUOW(); 680 writeRollback(); 681 agent_.flowOutsideUOW(); 682 readRollback(); agent_.endReadChain(); 684 } else { 685 agent_.beginWriteChain(null); 686 writeRollback(); 687 agent_.flow(null); 688 readRollback(); agent_.endReadChain(); 690 } 691 } 692 693 public void writeRollback() throws SqlException { 694 if (isXAConnection_) { 695 writeXARollback_ (); 696 } else { 697 writeLocalRollback_(); 698 } 699 } 700 701 public void readRollback() throws SqlException { 702 if (isXAConnection_) { 703 readLocalXARollback_(); 704 } else { 705 readLocalRollback_(); 706 } 707 } 708 709 synchronized public void close() throws SQLException { 710 if (agent_.loggingEnabled()) { 711 agent_.logWriter_.traceEntry(this, "close"); 712 } 713 closeX(); 714 } 715 716 void checkForTransactionInProgress() throws SqlException { 717 if (transactionInProgress() && !allowCloseInUOW_()) { 719 throw new SqlException(agent_.logWriter_, 720 new ClientMessageId (SQLState.CANNOT_CLOSE_ACTIVE_CONNECTION)); 721 } 722 } 723 724 public boolean transactionInProgress() { 725 return !autoCommit_ && inUnitOfWork_; 726 } 727 728 synchronized public void closeX() throws SQLException { 730 if (!open_) { 731 return; 732 } 733 closeResourcesX(); 734 } 735 736 synchronized public void closeResources() throws SQLException { 739 if (open_ || (!open_ && availableForReuse_)) { 740 availableForReuse_ = false; 741 closeResourcesX(); 742 } 743 } 744 745 private void closeResourcesX() throws SQLException { 746 try 747 { 748 checkForTransactionInProgress(); 749 } 750 catch ( SqlException e ) 751 { 752 throw e.getSQLException(); 753 } 754 755 resetConnectionAtFirstSql_ = false; SQLException accumulatedExceptions = null; 757 if (setTransactionIsolationStmt != null) { 758 try { 759 setTransactionIsolationStmt.close(); 760 } catch (SQLException se) { 761 accumulatedExceptions = se; 762 } 763 } 764 setTransactionIsolationStmt = null; 765 if (getTransactionIsolationStmt != null) { 766 try { 767 getTransactionIsolationStmt.close(); 768 } catch (SQLException se) { 769 accumulatedExceptions = Utils.accumulateSQLException( 770 se, accumulatedExceptions); 771 } 772 } 773 getTransactionIsolationStmt = null; 774 try { 775 flowClose(); 776 } catch (SqlException e) { 777 accumulatedExceptions = 778 Utils.accumulateSQLException( 779 e.getSQLException(), accumulatedExceptions); 780 } 781 782 markClosed(); 783 try { 784 agent_.close(); 785 } catch (SqlException e) { 786 throw Utils.accumulateSQLException(e.getSQLException(), 787 accumulatedExceptions); 788 } 789 } 790 791 protected abstract boolean isGlobalPending_(); 792 793 synchronized public void closeForReuse() throws SqlException { 796 if (!open_) { 797 return; 798 } 799 resetConnectionAtFirstSql_ = false; SqlException accumulatedExceptions = null; 801 try { 802 flowClose(); 803 } catch (SqlException e) { 804 accumulatedExceptions = e; 805 } 806 if (open_) { 807 markClosedForReuse(); 808 } 809 if (accumulatedExceptions != null) { 810 throw accumulatedExceptions; 811 } 812 } 813 814 private void flowClose() throws SqlException { 815 agent_.beginWriteChainOutsideUOW(); 816 if (doCloseStatementsOnClose_()) { 817 writeCloseStatements(); 818 } 819 if (autoCommit_) { 820 writeAutoCommit(); 821 } 822 agent_.flowOutsideUOW(); 823 if (doCloseStatementsOnClose_()) { 824 readCloseStatements(); 825 } 826 if (autoCommit_) { 827 readAutoCommit(); 828 } 829 agent_.endReadChain(); 830 } 831 832 protected abstract void markClosed_(); 833 834 public void markClosed() { 836 open_ = false; 837 inUnitOfWork_ = false; 838 markStatementsClosed(); 839 CommitAndRollbackListeners_.clear(); 840 markClosed_(); 841 } 842 843 844 private void markClosedForReuse() { 845 availableForReuse_ = true; 846 markClosed(); 847 } 848 849 private void markStatementsClosed() { 850 java.util.Set keySet = openStatements_.keySet(); 851 for (java.util.Iterator i = keySet.iterator(); i.hasNext();) { 852 Statement stmt = (Statement) i.next(); 853 stmt.markClosed(); 854 i.remove(); 855 } 856 } 857 858 private void writeCloseStatements() throws SqlException { 859 java.util.Set keySet = openStatements_.keySet(); 860 for (java.util.Iterator i = keySet.iterator(); i.hasNext();) { 861 ((Statement) i.next()).writeClose(false); } 863 } 864 865 private void readCloseStatements() throws SqlException { 866 java.util.Set keySet = openStatements_.keySet(); 867 for (java.util.Iterator i = keySet.iterator(); i.hasNext();) { 868 ((Statement) i.next()).readClose(false); } 870 } 871 872 877 public boolean isPhysicalConnClosed() { 878 return !open_ && !availableForReuse_; 879 } 880 881 882 public boolean isClosed() { 883 if (agent_.loggingEnabled()) { 884 agent_.logWriter_.traceExit(this, "isClosed", !open_); 885 } 886 return !open_; 887 } 888 889 890 public boolean isClosedX() { 891 return !open_; 892 } 893 894 private static String DERBY_TRANSACTION_REPEATABLE_READ = "RS"; 895 private static String DERBY_TRANSACTION_SERIALIZABLE = "RR"; 896 private static String DERBY_TRANSACTION_READ_COMMITTED = "CS"; 897 private static String DERBY_TRANSACTION_READ_UNCOMMITTED = "UR"; 898 899 synchronized public void setTransactionIsolation(int level) throws SQLException { 900 try 901 { 902 if (agent_.loggingEnabled()) { 903 agent_.logWriter_.traceEntry(this, "setTransactionIsolation", level); 904 } 905 checkForClosedConnection(); 907 908 String levelString = null; 919 switch (level) { 920 case java.sql.Connection.TRANSACTION_REPEATABLE_READ: 921 levelString = DERBY_TRANSACTION_REPEATABLE_READ; 922 break; 923 case java.sql.Connection.TRANSACTION_READ_COMMITTED: 924 levelString = DERBY_TRANSACTION_READ_COMMITTED; 925 break; 926 case java.sql.Connection.TRANSACTION_SERIALIZABLE: 927 levelString = DERBY_TRANSACTION_SERIALIZABLE; 928 break; 929 case java.sql.Connection.TRANSACTION_READ_UNCOMMITTED: 930 levelString = DERBY_TRANSACTION_READ_UNCOMMITTED; 931 break; 932 case java.sql.Connection.TRANSACTION_NONE: 935 default: 936 throw new SqlException(agent_.logWriter_, 937 new ClientMessageId (SQLState.UNIMPLEMENTED_ISOLATION_LEVEL), 938 new Integer (level)); 939 } 940 if (setTransactionIsolationStmt == null || 941 !(setTransactionIsolationStmt.openOnClient_ && 942 setTransactionIsolationStmt.openOnServer_)) { 943 setTransactionIsolationStmt = 944 createStatementX(java.sql.ResultSet.TYPE_FORWARD_ONLY, 945 java.sql.ResultSet.CONCUR_READ_ONLY, 946 holdability()); 947 } 948 949 setTransactionIsolationStmt.executeUpdate("SET CURRENT ISOLATION = " + levelString); 950 951 completeLocalCommit(); 954 955 isolation_ = level; 956 } 957 catch ( SqlException se ) 958 { 959 throw se.getSQLException(); 960 } 961 } 962 963 public int getTransactionIsolation() throws SQLException { 964 965 boolean currentAutoCommit = autoCommit_; 968 java.sql.ResultSet rs = null; 969 970 try 971 { 972 checkForClosedConnection(); 973 if (agent_.loggingEnabled()) { 974 agent_.logWriter_.traceExit(this, "getTransactionIsolation", isolation_); 975 } 976 977 autoCommit_ = false; 980 981 if (getTransactionIsolationStmt == null || 988 !(getTransactionIsolationStmt.openOnClient_ && 989 getTransactionIsolationStmt.openOnServer_)) { 990 getTransactionIsolationStmt = 991 createStatementX(java.sql.ResultSet.TYPE_FORWARD_ONLY, 992 java.sql.ResultSet.CONCUR_READ_ONLY, 993 holdability()); 994 } 995 996 boolean savedInUnitOfWork = inUnitOfWork_; 997 rs = getTransactionIsolationStmt.executeQuery("values current isolation"); 998 rs.next(); 999 String isolationStr = rs.getString(1); 1000 isolation_ = translateIsolation(isolationStr); 1001 rs.close(); 1002 inUnitOfWork_ = savedInUnitOfWork; 1007 } 1008 catch ( SqlException se ) 1009 { 1010 throw se.getSQLException(); 1011 } 1012 finally { 1013 autoCommit_ = currentAutoCommit; 1015 if(rs != null) 1016 rs.close(); 1017 } 1018 1019 return isolation_; 1020 } 1021 1022 1028 private int translateIsolation(String isolationStr) { 1029 if(isolationStr.compareTo(DERBY_TRANSACTION_REPEATABLE_READ) == 0) 1030 return java.sql.Connection.TRANSACTION_REPEATABLE_READ; 1031 else if (isolationStr.compareTo(DERBY_TRANSACTION_SERIALIZABLE) == 0) 1032 return java.sql.Connection.TRANSACTION_SERIALIZABLE; 1033 else if (isolationStr.compareTo(DERBY_TRANSACTION_READ_COMMITTED) == 0) 1034 return java.sql.Connection.TRANSACTION_READ_COMMITTED; 1035 else if (isolationStr.compareTo(DERBY_TRANSACTION_READ_UNCOMMITTED) == 0) 1036 return java.sql.Connection.TRANSACTION_READ_UNCOMMITTED; 1037 else 1038 return java.sql.Connection.TRANSACTION_NONE; 1039 } 1040 1041 public java.sql.SQLWarning getWarnings() throws SQLException { 1042 if (agent_.loggingEnabled()) { 1043 agent_.logWriter_.traceExit(this, "getWarnings", warnings_); 1044 } 1045 try { 1046 checkForClosedConnection(); 1047 } catch (SqlException se) { 1048 throw se.getSQLException(); 1049 } 1050 return warnings_ == null ? null : warnings_.getSQLWarning(); 1051 } 1052 1053 synchronized public void clearWarnings() throws SQLException { 1054 try 1055 { 1056 if (agent_.loggingEnabled()) { 1057 agent_.logWriter_.traceEntry(this, "clearWarnings"); 1058 } 1059 checkForClosedConnection(); 1060 clearWarningsX(); 1061 } 1062 catch ( SqlException se ) 1063 { 1064 throw se.getSQLException(); 1065 } 1066 } 1067 1068 public void clearWarningsX() throws SqlException { 1070 warnings_ = null; 1071 accumulated440ForMessageProcFailure_ = false; 1072 accumulated444ForMessageProcFailure_ = false; 1073 accumulatedSetReadOnlyWarning_ = false; 1074 } 1075 1076 1079 public java.sql.DatabaseMetaData getMetaData() throws SQLException { 1080 try 1081 { 1082 checkForClosedConnection(); 1083 if (agent_.loggingEnabled()) { 1084 agent_.logWriter_.traceExit(this, "getMetaData", databaseMetaData_); 1085 } 1086 return databaseMetaData_; 1087 } 1088 catch ( SqlException se ) 1089 { 1090 throw se.getSQLException(); 1091 } 1092 } 1093 1094 synchronized public void setReadOnly(boolean readOnly) throws SQLException { 1095 try 1096 { 1097 if (agent_.loggingEnabled()) { 1100 agent_.logWriter_.traceEntry(this, "setReadOnly", readOnly); 1101 } 1102 checkForClosedConnection(); 1103 } 1104 catch ( SqlException se ) 1105 { 1106 throw se.getSQLException(); 1107 } 1108 } 1109 1110 public boolean isReadOnly() throws SQLException { 1111 try 1112 { 1113 checkForClosedConnection(); 1114 if (agent_.loggingEnabled()) { 1115 agent_.logWriter_.traceExit(this, "isReadOnly", jdbcReadOnly_); 1116 } 1117 return false; 1118 } 1119 catch ( SqlException se ) 1120 { 1121 throw se.getSQLException(); 1122 } 1123 } 1124 1125 synchronized public void setCatalog(String catalog) throws SQLException { 1126 try 1127 { 1128 if (agent_.loggingEnabled()) { 1129 agent_.logWriter_.traceEntry(this, "setCatalog", catalog); 1130 } 1131 checkForClosedConnection(); 1132 } 1134 catch ( SqlException se ) 1135 { 1136 throw se.getSQLException(); 1137 } 1138 } 1139 1140 public String getCatalog() throws SQLException { 1141 try 1142 { 1143 checkForClosedConnection(); 1144 if (agent_.loggingEnabled()) { 1145 agent_.logWriter_.traceExit(this, "getCatalog", (String ) null); 1146 } 1147 return null; 1148 } 1149 catch ( SqlException se ) 1150 { 1151 throw se.getSQLException(); 1152 } 1153 } 1154 1155 1157 synchronized public java.sql.Statement createStatement(int resultSetType, 1158 int resultSetConcurrency) throws SQLException { 1159 try 1160 { 1161 if (agent_.loggingEnabled()) { 1162 agent_.logWriter_.traceEntry(this, "createStatement", resultSetType, resultSetConcurrency); 1163 } 1164 Statement s = createStatementX(resultSetType, resultSetConcurrency, holdability()); 1165 if (agent_.loggingEnabled()) { 1166 agent_.logWriter_.traceExit(this, "createStatement", s); 1167 } 1168 return s; 1169 } 1170 catch ( SqlException se ) 1171 { 1172 throw se.getSQLException(); 1173 } 1174 } 1175 1176 synchronized public java.sql.PreparedStatement prepareStatement(String sql, 1177 int resultSetType, 1178 int resultSetConcurrency) throws SQLException { 1179 try 1180 { 1181 if (agent_.loggingEnabled()) { 1182 agent_.logWriter_.traceEntry(this, "prepareStatement", sql, resultSetType, resultSetConcurrency); 1183 } 1184 PreparedStatement ps = prepareStatementX(sql, 1185 resultSetType, 1186 resultSetConcurrency, 1187 holdability(), 1188 java.sql.Statement.NO_GENERATED_KEYS, 1189 null); 1190 if (agent_.loggingEnabled()) { 1191 agent_.logWriter_.traceExit(this, "prepareStatement", ps); 1192 } 1193 return ps; 1194 } 1195 catch ( SqlException se ) 1196 { 1197 throw se.getSQLException(); 1198 } 1199 } 1200 1201 synchronized public java.sql.CallableStatement prepareCall(String sql, 1202 int resultSetType, 1203 int resultSetConcurrency) throws SQLException { 1204 try 1205 { 1206 if (agent_.loggingEnabled()) { 1207 agent_.logWriter_.traceEntry(this, "prepareCall", sql, resultSetType, resultSetConcurrency); 1208 } 1209 CallableStatement cs = prepareCallX(sql, resultSetType, resultSetConcurrency, holdability()); 1210 if (agent_.loggingEnabled()) { 1211 agent_.logWriter_.traceExit(this, "prepareCall", cs); 1212 } 1213 return cs; 1214 } 1215 catch ( SqlException se ) 1216 { 1217 throw se.getSQLException(); 1218 } 1219 } 1220 1221 synchronized public CallableStatement prepareMessageProc(String sql) throws SqlException { 1222 checkForClosedConnection(); 1223 1224 CallableStatement cs = prepareCallX(sql, java.sql.ResultSet.TYPE_FORWARD_ONLY, java.sql.ResultSet.CONCUR_READ_ONLY, holdability()); 1225 return cs; 1226 } 1227 1228 private int downgradeResultSetType(int resultSetType) { 1231 if (resultSetType == java.sql.ResultSet.TYPE_SCROLL_SENSITIVE) { 1232 accumulateWarning(new SqlWarning(agent_.logWriter_, 1233 new ClientMessageId(SQLState.SCROLL_SENSITIVE_NOT_SUPPORTED))); 1234 return java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE; 1235 } 1236 return resultSetType; 1237 } 1238 1239 public java.util.Map getTypeMap() throws SQLException { 1240 try 1241 { 1242 if (agent_.loggingEnabled()) { 1243 agent_.logWriter_.traceEntry(this, "getTypeMap"); 1244 } 1245 checkForClosedConnection(); 1246 java.util.Map map = new java.util.HashMap (); 1247 if (agent_.loggingEnabled()) { 1248 agent_.logWriter_.traceExit(this, "getTypeMap", map); 1249 } 1250 return map; 1251 } 1252 catch ( SqlException se ) 1253 { 1254 throw se.getSQLException(); 1255 } 1256 } 1257 1258 synchronized public void setTypeMap(java.util.Map map) throws SQLException { 1259 try 1260 { 1261 if (agent_.loggingEnabled()) { 1262 agent_.logWriter_.traceEntry(this, "setTypeMap", map); 1263 } 1264 checkForClosedConnection(); 1265 throw new SqlException(agent_.logWriter_, 1266 new ClientMessageId (SQLState.NOT_IMPLEMENTED), 1267 "setTypeMap"); 1268 } 1269 catch ( SqlException se ) 1270 { 1271 throw se.getSQLException(); 1272 } 1273 } 1274 1275 1277 synchronized public void setHoldability(int holdability) throws SQLException { 1278 try 1279 { 1280 if (agent_.loggingEnabled()) { 1281 agent_.logWriter_.traceEntry(this, "setHoldability", holdability); 1282 } 1283 checkForClosedConnection(); 1284 if (this.isXAConnection_ && this.xaState_ == XA_T1_ASSOCIATED) 1288 { 1289 if (holdability == JDBC30Translation.HOLD_CURSORS_OVER_COMMIT) 1290 throw new SqlException(agent_.logWriter_, 1291 new ClientMessageId(SQLState.CANNOT_HOLD_CURSOR_XA)); 1292 } 1293 this.holdability = holdability; 1294 1295 } 1296 catch ( SqlException se ) 1297 { 1298 throw se.getSQLException(); 1299 } 1300 } 1301 1302 public int getHoldability() throws SQLException { 1303 try 1304 { 1305 checkForClosedConnection(); 1306 if (agent_.loggingEnabled()) { 1307 agent_.logWriter_.traceExit(this, "getHoldability", holdability()); 1308 } 1309 return holdability(); 1310 } 1311 catch ( SqlException se ) 1312 { 1313 throw se.getSQLException(); 1314 } 1315 } 1316 1317 public int dncGeneratedSavepointId_; 1318 public static final String dncGeneratedSavepointNamePrefix__ = "DNC_GENENERATED_NAME_"; 1320 1321 synchronized public java.sql.Savepoint setSavepoint() throws SQLException { 1322 try 1323 { 1324 if (agent_.loggingEnabled()) { 1325 agent_.logWriter_.traceEntry(this, "setSavepoint"); 1326 } 1327 checkForClosedConnection(); 1328 if (autoCommit_) { 1330 throw new SqlException(agent_.logWriter_, 1331 new ClientMessageId (SQLState.NO_SAVEPOINT_WHEN_AUTO)); 1332 } 1333 if ((++dncGeneratedSavepointId_) < 0) { 1335 dncGeneratedSavepointId_ = 1; } 1337 Object s = setSavepointX(new Savepoint(agent_, dncGeneratedSavepointId_)); 1338 return (java.sql.Savepoint ) s; 1339 } 1340 catch ( SqlException se ) 1341 { 1342 throw se.getSQLException(); 1343 } 1344 } 1345 1346 synchronized public java.sql.Savepoint setSavepoint(String name) throws SQLException { 1347 try 1348 { 1349 if (agent_.loggingEnabled()) { 1350 agent_.logWriter_.traceEntry(this, "setSavepoint", name); 1351 } 1352 checkForClosedConnection(); 1353 if (name == null) { 1355 throw new SqlException(agent_.logWriter_, 1356 new ClientMessageId (SQLState.NULL_NAME_FOR_SAVEPOINT)); 1357 } else if (autoCommit_) { 1359 throw new SqlException(agent_.logWriter_, 1360 new ClientMessageId (SQLState.NO_SAVEPOINT_WHEN_AUTO)); 1361 } 1362 Object s = setSavepointX(new Savepoint(agent_, name)); 1364 return (java.sql.Savepoint ) s; 1365 } 1366 catch ( SqlException se ) 1367 { 1368 throw se.getSQLException(); 1369 } 1370 } 1371 1372 private Savepoint setSavepointX(Savepoint savepoint) throws SQLException { 1373 Statement stmt = null; 1375 try { 1376 stmt = (Statement) createStatementX(java.sql.ResultSet.TYPE_FORWARD_ONLY, 1377 java.sql.ResultSet.CONCUR_READ_ONLY, 1378 holdability()); 1379 String savepointName; 1380 try { 1381 savepointName = savepoint.getSavepointName(); 1382 } catch (SQLException e) { 1383 savepointName = dncGeneratedSavepointNamePrefix__ + 1385 savepoint.getSavepointId(); 1386 } 1387 String sql = "SAVEPOINT \"" + savepointName + "\" ON ROLLBACK RETAIN CURSORS"; 1388 stmt.executeX(sql); 1389 } catch ( SqlException se ) 1390 { 1391 throw se.getSQLException(); 1392 } finally { 1393 if (stmt != null) { 1394 try { 1395 stmt.closeX(); 1396 } catch (SqlException doNothing) { 1397 } 1398 } 1399 } 1400 1401 return savepoint; 1402 } 1403 1404 synchronized public void rollback(java.sql.Savepoint savepoint) throws SQLException { 1405 try 1406 { 1407 int saveXaState = xaState_; 1408 if (agent_.loggingEnabled()) { 1409 agent_.logWriter_.traceEntry(this, "rollback", savepoint); 1410 } 1411 checkForClosedConnection(); 1412 if (savepoint == null) { 1414 throw new SqlException(agent_.logWriter_, 1415 new ClientMessageId (SQLState.XACT_SAVEPOINT_RELEASE_ROLLBACK_FAIL)); 1416 } else if (autoCommit_) { 1418 throw new SqlException(agent_.logWriter_, 1419 new ClientMessageId (SQLState.NO_SAVEPOINT_ROLLBACK_OR_RELEASE_WHEN_AUTO)); 1420 } 1421 try { 1423 if (this != ((Savepoint) savepoint).agent_.connection_) { 1424 throw new SqlException(agent_.logWriter_, 1425 new ClientMessageId (SQLState.SAVEPOINT_NOT_CREATED_BY_CONNECTION)); 1426 } 1427 } catch (java.lang.ClassCastException e) { throw new SqlException(agent_.logWriter_, 1429 new ClientMessageId (SQLState.SAVEPOINT_NOT_CREATED_BY_CONNECTION)); 1430 } 1431 1432 Statement stmt = null; 1434 try { 1435 stmt = createStatementX(java.sql.ResultSet.TYPE_FORWARD_ONLY, 1436 java.sql.ResultSet.CONCUR_READ_ONLY, 1437 holdability()); 1438 String savepointName; 1439 try { 1440 savepointName = ((Savepoint) savepoint).getSavepointName(); 1441 } catch (SQLException e) { 1442 savepointName = dncGeneratedSavepointNamePrefix__ + 1444 ((Savepoint) savepoint).getSavepointId(); 1445 } 1446 String sql = "ROLLBACK TO SAVEPOINT \"" + savepointName + "\""; 1447 stmt.executeX(sql); 1448 } finally { 1449 if (stmt != null) { 1450 try { 1451 stmt.closeX(); 1452 } catch (SqlException doNothing) { 1453 } 1454 } 1455 xaState_ = saveXaState; 1456 } 1457 } 1458 catch ( SqlException se ) 1459 { 1460 throw se.getSQLException(); 1461 } 1462 } 1463 1464 synchronized public void releaseSavepoint(java.sql.Savepoint savepoint) throws SQLException { 1465 try 1466 { 1467 int saveXaState = xaState_; 1468 if (agent_.loggingEnabled()) { 1469 agent_.logWriter_.traceEntry(this, "releaseSavepoint", savepoint); 1470 } 1471 checkForClosedConnection(); 1472 if (savepoint == null) { 1474 throw new SqlException(agent_.logWriter_, 1475 new ClientMessageId (SQLState.XACT_SAVEPOINT_RELEASE_ROLLBACK_FAIL)); 1476 } else if (autoCommit_) { 1478 throw new SqlException(agent_.logWriter_, 1479 new ClientMessageId (SQLState.NO_SAVEPOINT_ROLLBACK_OR_RELEASE_WHEN_AUTO)); 1480 } 1481 try { 1483 if (this != ((Savepoint) savepoint).agent_.connection_) { 1484 throw new SqlException(agent_.logWriter_, new ClientMessageId 1485 (SQLState.SAVEPOINT_NOT_CREATED_BY_CONNECTION)); 1486 } 1487 } catch (java.lang.ClassCastException e) { throw new SqlException(agent_.logWriter_, new ClientMessageId 1489 (SQLState.SAVEPOINT_NOT_CREATED_BY_CONNECTION)); 1490 1491 } 1492 1493 Statement stmt = null; 1495 try { 1496 stmt = (Statement) createStatementX(java.sql.ResultSet.TYPE_FORWARD_ONLY, 1497 java.sql.ResultSet.CONCUR_READ_ONLY, 1498 holdability()); 1499 String savepointName; 1500 try { 1501 savepointName = ((Savepoint) savepoint).getSavepointName(); 1502 } catch (SQLException e) { 1503 savepointName = dncGeneratedSavepointNamePrefix__ + 1505 ((Savepoint) savepoint).getSavepointId(); 1506 } 1507 String sql = "RELEASE SAVEPOINT \"" + savepointName + "\""; 1508 stmt.executeX(sql); 1509 } finally { 1510 if (stmt != null) { 1511 try { 1512 stmt.closeX(); 1513 } catch (SqlException doNothing) { 1514 } 1515 } 1516 xaState_ = saveXaState; 1517 } 1518 } 1519 catch ( SqlException se ) 1520 { 1521 throw se.getSQLException(); 1522 } 1523 } 1524 1525 synchronized public java.sql.Statement createStatement(int resultSetType, 1526 int resultSetConcurrency, 1527 int resultSetHoldability) throws SQLException { 1528 try 1529 { 1530 if (agent_.loggingEnabled()) { 1531 agent_.logWriter_.traceEntry(this, "createStatement", resultSetType, resultSetConcurrency, resultSetHoldability); 1532 } 1533 Statement s = createStatementX(resultSetType, resultSetConcurrency, resultSetHoldability); 1534 if (agent_.loggingEnabled()) { 1535 agent_.logWriter_.traceExit(this, "createStatement", s); 1536 } 1537 return s; 1538 } 1539 catch ( SqlException se ) 1540 { 1541 throw se.getSQLException(); 1542 } 1543 } 1544 1545 private Statement createStatementX(int resultSetType, 1546 int resultSetConcurrency, 1547 int resultSetHoldability) throws SqlException { 1548 checkForClosedConnection(); 1549 resultSetType = downgradeResultSetType(resultSetType); 1550 if (this.isXAConnection_ && this.xaState_ == XA_T1_ASSOCIATED) 1560 { 1561 if (resultSetHoldability == JDBC30Translation.HOLD_CURSORS_OVER_COMMIT) { 1562 resultSetHoldability = JDBC30Translation.CLOSE_CURSORS_AT_COMMIT; 1563 accumulateWarning(new SqlWarning(agent_.logWriter_, 1564 new ClientMessageId(SQLState.HOLDABLE_RESULT_SET_NOT_AVAILABLE))); 1565 } 1566 } 1567 Statement s = newStatement_(resultSetType, resultSetConcurrency, resultSetHoldability); 1568 s.cursorAttributesToSendOnPrepare_ = s.cacheCursorAttributesToSendOnPrepare(); 1569 openStatements_.put(s, null); 1570 return s; 1571 } 1572 1573 protected void resetStatement(Statement s) throws SqlException { 1577 String cursorAttributesToSendOnPrepare = s.cursorAttributesToSendOnPrepare_; 1578 resetStatement_(s, s.resultSetType_, s.resultSetConcurrency_, s.resultSetHoldability_); 1579 s.cursorAttributesToSendOnPrepare_ = cursorAttributesToSendOnPrepare; 1580 } 1581 1582 synchronized public java.sql.PreparedStatement prepareStatement(String sql, 1583 int resultSetType, 1584 int resultSetConcurrency, 1585 int resultSetHoldability) throws SQLException { 1586 try 1587 { 1588 if (agent_.loggingEnabled()) { 1589 agent_.logWriter_.traceEntry(this, "prepareStatement", sql, resultSetType, resultSetConcurrency, resultSetHoldability); 1590 } 1591 PreparedStatement ps = prepareStatementX(sql, 1592 resultSetType, 1593 resultSetConcurrency, 1594 resultSetHoldability, 1595 java.sql.Statement.NO_GENERATED_KEYS, 1596 null); 1597 if (agent_.loggingEnabled()) { 1598 agent_.logWriter_.traceExit(this, "prepareStatement", ps); 1599 } 1600 return ps; 1601 } 1602 catch ( SqlException se ) 1603 { 1604 throw se.getSQLException(); 1605 } 1606 } 1607 1608 PreparedStatement prepareStatementX(String sql, 1610 int resultSetType, 1611 int resultSetConcurrency, 1612 int resultSetHoldability, 1613 int autoGeneratedKeys, 1614 String [] columnNames) throws SqlException { 1615 checkForClosedConnection(); 1616 checkAutoGeneratedKeysParameters(autoGeneratedKeys, columnNames); 1617 resultSetType = downgradeResultSetType(resultSetType); 1618 PreparedStatement ps = newPreparedStatement_(sql, resultSetType, resultSetConcurrency, resultSetHoldability, autoGeneratedKeys, columnNames); 1619 ps.cursorAttributesToSendOnPrepare_ = ps.cacheCursorAttributesToSendOnPrepare(); 1620 ps.prepare(); 1621 openStatements_.put(ps,null); 1622 return ps; 1623 } 1624 1625 protected void resetPrepareStatement(PreparedStatement ps) throws SqlException { 1629 String cursorAttributesToSendOnPrepare = ps.cursorAttributesToSendOnPrepare_; 1630 resetPreparedStatement_(ps, ps.sql_, ps.resultSetType_, ps.resultSetConcurrency_, ps.resultSetHoldability_, ps.autoGeneratedKeys_, ps.generatedKeysColumnNames_); 1631 ps.cursorAttributesToSendOnPrepare_ = cursorAttributesToSendOnPrepare; 1632 ps.prepare(); 1633 } 1634 1635 synchronized public java.sql.CallableStatement prepareCall(String sql, 1636 int resultSetType, 1637 int resultSetConcurrency, 1638 int resultSetHoldability) throws SQLException { 1639 try 1640 { 1641 if (agent_.loggingEnabled()) { 1642 agent_.logWriter_.traceEntry(this, "prepareCall", sql, resultSetType, resultSetConcurrency, resultSetHoldability); 1643 } 1644 CallableStatement cs = prepareCallX(sql, resultSetType, resultSetConcurrency, resultSetHoldability); 1645 if (agent_.loggingEnabled()) { 1646 agent_.logWriter_.traceExit(this, "prepareCall", cs); 1647 } 1648 return cs; 1649 } 1650 catch ( SqlException se ) 1651 { 1652 throw se.getSQLException(); 1653 } 1654 } 1655 1656 private CallableStatement prepareCallX(String sql, 1657 int resultSetType, 1658 int resultSetConcurrency, 1659 int resultSetHoldability) throws SqlException { 1660 checkForClosedConnection(); 1661 resultSetType = downgradeResultSetType(resultSetType); 1662 CallableStatement cs = newCallableStatement_(sql, resultSetType, resultSetConcurrency, resultSetHoldability); 1663 cs.cursorAttributesToSendOnPrepare_ = cs.cacheCursorAttributesToSendOnPrepare(); 1664 cs.prepare(); 1665 openStatements_.put(cs,null); 1666 return cs; 1667 } 1668 1669 protected void resetPrepareCall(CallableStatement cs) throws SqlException { 1670 String cursorAttributesToSendOnPrepare = cs.cursorAttributesToSendOnPrepare_; 1671 resetCallableStatement_(cs, cs.sql_, cs.resultSetType_, cs.resultSetConcurrency_, cs.resultSetHoldability_); 1672 cs.cursorAttributesToSendOnPrepare_ = cursorAttributesToSendOnPrepare; 1673 cs.prepare(); 1674 } 1675 1676 public java.sql.PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException { 1677 try 1678 { 1679 if (agent_.loggingEnabled()) { 1680 agent_.logWriter_.traceEntry(this, "prepareStatement", sql, autoGeneratedKeys); 1681 } 1682 PreparedStatement ps = prepareStatementX(sql, 1683 java.sql.ResultSet.TYPE_FORWARD_ONLY, 1684 java.sql.ResultSet.CONCUR_READ_ONLY, 1685 holdability(), 1686 autoGeneratedKeys, 1687 null); 1688 if (agent_.loggingEnabled()) { 1689 agent_.logWriter_.traceExit(this, "prepareStatement", ps); 1690 } 1691 return ps; 1692 } 1693 catch ( SqlException se ) 1694 { 1695 throw se.getSQLException(); 1696 } 1697 } 1698 1699 public java.sql.PreparedStatement prepareStatement(String sql, int columnIndexes[]) throws SQLException { 1700 try 1701 { 1702 if (agent_.loggingEnabled()) { 1703 agent_.logWriter_.traceEntry(this, "prepareStatement", sql, columnIndexes); 1704 } 1705 checkForClosedConnection(); 1706 throw new SqlException(agent_.logWriter_, 1707 new ClientMessageId (SQLState.NOT_IMPLEMENTED), 1708 "prepareStatement(String, int[])"); 1709 } 1710 catch ( SqlException se ) 1711 { 1712 throw se.getSQLException(); 1713 } 1714 } 1715 1716 public java.sql.PreparedStatement prepareStatement(String sql, String columnNames[]) throws SQLException { 1717 try 1718 { 1719 if (agent_.loggingEnabled()) { 1720 agent_.logWriter_.traceEntry(this, "prepareStatement", sql, columnNames); 1721 } 1722 PreparedStatement ps = prepareStatementX(sql, 1723 java.sql.ResultSet.TYPE_FORWARD_ONLY, 1724 java.sql.ResultSet.CONCUR_READ_ONLY, 1725 holdability(), 1726 java.sql.Statement.RETURN_GENERATED_KEYS, 1727 columnNames); 1728 if (agent_.loggingEnabled()) { 1729 agent_.logWriter_.traceExit(this, "prepareStatement", ps); 1730 } 1731 return ps; 1732 } 1733 catch ( SqlException se ) 1734 { 1735 throw se.getSQLException(); 1736 } 1737 } 1738 1739 1740 1742 protected abstract boolean allowCloseInUOW_(); 1743 1744 protected abstract boolean doCloseStatementsOnClose_(); 1745 1746 public abstract SectionManager newSectionManager(String collection, 1747 Agent agent, 1748 String databaseName); 1749 1751 protected abstract Agent newAgent_(LogWriter logWriter, int loginTimeout, String serverName, int portNumber) throws SqlException; 1752 1753 1754 protected abstract DatabaseMetaData newDatabaseMetaData_(); 1755 1756 protected abstract Statement newStatement_(int type, 1757 int concurrency, 1758 int holdability) throws SqlException; 1759 1760 protected abstract void resetStatement_(Statement statement, 1761 int type, 1762 int concurrency, 1763 int holdability) throws SqlException; 1764 1765 1766 protected abstract PreparedStatement newPositionedUpdatePreparedStatement_(String sql, Section section) throws SqlException; 1767 1768 protected abstract PreparedStatement newPreparedStatement_(String sql, 1769 int type, 1770 int concurrency, 1771 int holdability, 1772 int autoGeneratedKeys, 1773 String [] columnNames) throws SqlException; 1774 1775 protected abstract void resetPreparedStatement_(PreparedStatement ps, 1776 String sql, 1777 int resultSetType, 1778 int resultSetConcurrency, 1779 int resultSetHoldability, 1780 int autoGeneratedKeys, 1781 String [] columnNames) throws SqlException; 1782 1783 protected abstract CallableStatement newCallableStatement_(String sql, 1784 int type, 1785 int concurrency, 1786 int holdability) throws SqlException; 1787 1788 protected abstract void resetCallableStatement_(CallableStatement cs, 1789 String sql, 1790 int resultSetType, 1791 int resultSetConcurrency, 1792 int resultSetHoldability) throws SqlException; 1793 1794 1797 1798 public void completeConnect() throws SqlException { 1799 open_ = true; 1800 databaseMetaData_ = newDatabaseMetaData_(); 1801 1802 agent_.sectionManager_ = 1803 newSectionManager("NULLID", 1804 agent_, 1805 databaseName_); 1806 if (agent_.loggingEnabled()) { 1807 agent_.logWriter_.traceConnectExit(this); 1808 } 1809 } 1810 1811 public abstract void writeCommitSubstitute_() throws SqlException; 1812 1813 public abstract void readCommitSubstitute_() throws SqlException; 1814 1815 public abstract void writeLocalXAStart_() throws SqlException; 1816 1817 public abstract void readLocalXAStart_() throws SqlException; 1818 1819 public abstract void writeLocalXACommit_() throws SqlException; 1820 1821 protected abstract void writeXACommit_() throws SqlException; 1822 1823 public abstract void readLocalXACommit_() throws SqlException; 1824 1825 protected abstract void readXACommit_() throws SqlException; 1826 1827 public abstract void writeLocalCommit_() throws SqlException; 1828 1829 public abstract void readLocalCommit_() throws SqlException; 1830 1831 protected abstract void writeXATransactionStart(Statement statement) 1832 throws SqlException; 1833 1834 public void completeLocalCommit() { 1835 java.util.Set keySet = CommitAndRollbackListeners_.keySet(); 1836 for (java.util.Iterator i = keySet.iterator(); i.hasNext();) { 1837 UnitOfWorkListener listener = (UnitOfWorkListener) i.next(); 1838 listener.completeLocalCommit(i); 1839 } 1840 inUnitOfWork_ = false; 1841 } 1842 1843 public abstract void writeLocalRollback_() throws SqlException; 1844 1845 public abstract void readLocalRollback_() throws SqlException; 1846 1847 public void completeLocalRollback() { 1851 java.util.Set keySet = CommitAndRollbackListeners_.keySet(); 1852 for (java.util.Iterator i = keySet.iterator(); i.hasNext();) { 1853 UnitOfWorkListener listener = (UnitOfWorkListener) i.next(); 1854 listener.completeLocalRollback(i); 1855 } 1856 inUnitOfWork_ = false; 1857 } 1858 1859 1865 public void completeSpecificRollback(UnitOfWorkListener uwl) { 1866 java.util.Set keySet = CommitAndRollbackListeners_.keySet(); 1867 for (java.util.Iterator i = keySet.iterator(); i.hasNext();) { 1868 UnitOfWorkListener listener = (UnitOfWorkListener) i.next(); 1869 if(listener == uwl) { 1870 listener.completeLocalRollback(i); 1871 break; 1872 } 1873 } 1874 inUnitOfWork_ = false; 1875 } 1876 1877 1878 public abstract void writeLocalXARollback_() throws SqlException; 1879 1880 protected abstract void writeXARollback_() throws SqlException; 1881 1882 public abstract void readLocalXARollback_() throws SqlException; 1883 1884 protected abstract void readXARollback_() throws SqlException; 1885 1886 public void writeTransactionStart(Statement statement) throws SqlException { 1887 if (isXAConnection_) { 1888 writeXATransactionStart (statement); 1889 } 1890 } 1891 1892 public void readTransactionStart() throws SqlException { 1893 completeTransactionStart(); 1894 } 1895 1896 void completeTransactionStart() { 1897 inUnitOfWork_ = true; 1898 } 1899 1900 public void completeAbnormalUnitOfWork() { 1902 completeLocalRollback(); 1903 } 1904 1905 1911 public void completeAbnormalUnitOfWork(UnitOfWorkListener uwl) { 1912 completeSpecificRollback(uwl); 1913 } 1914 1915 public void completeChainBreakingDisconnect() { 1921 open_ = false; 1922 completeLocalRollback(); 1923 markStatementsClosed(); 1924 } 1925 1926 public void completeSqlca(Sqlca sqlca) { 1927 if (sqlca == null) { 1928 } else if (sqlca.getSqlCode() > 0) { 1929 accumulateWarning(new SqlWarning(agent_.logWriter_, sqlca)); 1930 } else if (sqlca.getSqlCode() < 0) { 1931 agent_.accumulateReadException(new SqlException(agent_.logWriter_, sqlca)); 1932 } 1933 } 1934 1935 public abstract void addSpecialRegisters(String s); 1936 1937 synchronized public void reset(LogWriter logWriter, String user, 1943 String password, ClientBaseDataSource ds, 1944 boolean recomputeFromDataSource) throws SqlException { 1945 if (logWriter != null) { 1946 logWriter.traceConnectResetEntry(this, logWriter, user, 1947 (ds != null) ? ds : dataSource_); 1948 } 1949 try { 1950 reset_(logWriter, user, password, ds, recomputeFromDataSource); 1951 } catch (SqlException sqle) { 1952 DisconnectException de = new DisconnectException(agent_, 1953 new ClientMessageId(SQLState.CONNECTION_FAILED_ON_RESET)); 1954 de.setNextException(sqle); 1955 throw de; 1956 } 1957 } 1958 1959 synchronized public void reset(LogWriter logWriter, ClientBaseDataSource ds, 1960 boolean recomputeFromDataSource) throws SqlException { 1961 if (logWriter != null) { 1962 logWriter.traceConnectResetEntry(this, logWriter, null, (ds != null) ? ds : dataSource_); 1963 } 1964 try { 1965 reset_(logWriter, ds, recomputeFromDataSource); 1966 } catch (SqlException sqle) { 1967 DisconnectException de = new DisconnectException(agent_, 1968 new ClientMessageId(SQLState.CONNECTION_FAILED_ON_RESET)); 1969 de.setNextException(sqle); 1970 throw de; 1971 } 1972 } 1973 1974 synchronized public void lightReset() throws SqlException { 1975 if (!open_ && !availableForReuse_) { 1976 return; 1977 } 1978 open_ = true; 1979 availableForReuse_ = false; 1980 } 1981 1982 abstract protected void reset_(LogWriter logWriter, String user, 1983 String password, ClientBaseDataSource ds, 1984 boolean recomputerFromDataSource) throws SqlException; 1985 1986 abstract protected void reset_(LogWriter logWriter, 1987 ClientBaseDataSource ds, 1988 boolean recomputerFromDataSource) throws SqlException; 1989 1990 protected void completeReset(boolean isDeferredReset, boolean recomputeFromDataSource) throws SqlException { 1991 open_ = true; 1992 1993 completeLocalRollback(); 1995 1999 java.util.Set keySet = openStatements_.keySet(); 2000 for (java.util.Iterator i = keySet.iterator(); i.hasNext();) { 2001 Object o = i.next(); 2002 ((Statement) o).reset(recomputeFromDataSource); 2003 2004 } 2005 2006 if (!isDeferredReset && agent_.loggingEnabled()) { 2007 agent_.logWriter_.traceConnectResetExit(this); 2008 } 2009 } 2010 2011 2012 2014 protected void checkForClosedConnection() throws SqlException { 2015 if (!open_) { 2016 agent_.checkForDeferredExceptions(); 2017 throw new SqlException(agent_.logWriter_, 2018 new ClientMessageId (SQLState.NO_CURRENT_CONNECTION)); 2019 } else { 2020 agent_.checkForDeferredExceptions(); 2021 } 2022 } 2023 2024 void checkAutoGeneratedKeysParameters(int autoGeneratedKeys, String [] columnNames) throws SqlException { 2025 if (autoGeneratedKeys != java.sql.Statement.NO_GENERATED_KEYS && 2026 autoGeneratedKeys != java.sql.Statement.RETURN_GENERATED_KEYS) { 2027 throw new SqlException(agent_.logWriter_, 2028 new ClientMessageId(SQLState.BAD_AUTO_GEN_KEY_VALUE), 2029 new Integer (autoGeneratedKeys)); 2030 } 2031 2032 if (columnNames != null) { 2033 throw new SqlException(agent_.logWriter_, 2034 new ClientMessageId (SQLState.NOT_IMPLEMENTED), 2035 "getAutoGeneratedKeys(columnNames == null)"); 2036 } 2037 2038 } 2039 2040 public boolean isXAConnection() { 2041 return isXAConnection_; 2042 } 2043 2044 public int getXAState() { 2045 return xaState_; 2046 } 2047 2048 public void setXAState(int state) { 2049 xaState_ = state; 2050 } 2051 2052 public void accumulateWarning(SqlWarning e) { 2053 if (warnings_ == null) { 2054 warnings_ = e; 2055 } else { 2056 warnings_.setNextException(e); 2057 } 2058 } 2059 2060 public void accumulate440WarningForMessageProcFailure(SqlWarning e) { 2061 if (!accumulated440ForMessageProcFailure_) { 2062 accumulateWarning(e); 2063 accumulated440ForMessageProcFailure_ = true; 2064 } 2065 } 2066 2067 public void accumulate444WarningForMessageProcFailure(SqlWarning e) { 2068 if (!accumulated444ForMessageProcFailure_) { 2069 accumulateWarning(e); 2070 accumulated444ForMessageProcFailure_ = true; 2071 } 2072 } 2073 2074 public int getServerVersion() { 2076 return databaseMetaData_.productLevel_.versionLevel_; 2077 } 2078 2079 public void setInUnitOfWork(boolean inUnitOfWork) { 2080 inUnitOfWork_ = inUnitOfWork; 2081 } 2082 2083 2089 final int holdability() 2090 { 2091 if (this.isXAConnection_ && this.xaState_ == XA_T1_ASSOCIATED) 2092 return JDBC30Translation.CLOSE_CURSORS_AT_COMMIT; 2093 return holdability; 2094 } 2095 2096} 2097 | Popular Tags |