1 21 22 package org.apache.derbyTesting.unitTests.store; 23 24 import org.apache.derbyTesting.unitTests.harness.T_Generic; 25 import org.apache.derbyTesting.unitTests.harness.T_Fail; 26 27 import org.apache.derby.iapi.store.access.xa.*; 28 import org.apache.derby.iapi.store.access.*; 29 30 import org.apache.derby.iapi.services.io.FormatableBitSet; 31 32 import org.apache.derby.iapi.reference.Property; 33 34 import org.apache.derby.iapi.services.context.ContextService; 35 import org.apache.derby.iapi.services.context.ContextManager; 36 37 import org.apache.derby.iapi.services.monitor.Monitor; 38 39 import org.apache.derby.iapi.services.sanity.SanityManager; 40 41 import org.apache.derby.iapi.services.io.FormatIdUtil; 42 43 import org.apache.derby.iapi.error.StandardException; 44 45 import java.util.Properties ; 46 47 import javax.transaction.xa.XAResource ; 48 import javax.transaction.xa.Xid ; 49 50 51 public class T_XA extends T_Generic 52 { 53 private static final String testService = "XaTest"; 54 55 byte[] global_id = 56 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 57 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 58 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 59 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 60 40, 41, 42, 44, 44, 45, 46, 47, 48, 49, 61 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 62 60, 61, 62, 63}; 63 64 byte[] branch_id = 65 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 66 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 67 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 68 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 69 40, 41, 42, 44, 44, 45, 46, 47, 48, 49, 70 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 71 60, 61, 62, 63}; 72 73 AccessFactory store = null; 74 75 public T_XA() 76 { 77 super(); 78 } 79 80 83 84 87 88 public String getModuleToTestProtocolName() 89 { 90 return AccessFactory.MODULE; 91 } 92 93 96 97 protected void runTests() throws T_Fail 98 { 99 101 if (startParams == null) 103 { 104 startParams = new Properties (); 105 } 106 startParams.put(Property.NO_AUTO_BOOT, Boolean.TRUE.toString()); 107 startParams.put(Property.DELETE_ON_CREATE, Boolean.TRUE.toString()); 109 110 startParams = T_Util.setEncryptionParam(startParams); 112 113 try { 114 store = (AccessFactory) Monitor.createPersistentService( 115 getModuleToTestProtocolName(), testService, startParams); 116 } catch (StandardException mse) { 117 throw T_Fail.exceptionFail(mse); 118 } 119 120 121 if (store == null) 122 { 123 throw T_Fail.testFailMsg( 124 getModuleToTestProtocolName() + " service not started."); 125 } 126 127 REPORT("(unitTestMain) Testing " + testService); 128 129 try { 130 131 XATest_1(new commit_method(store, true)); 132 XATest_2(new commit_method(store, true)); 133 XATest_3(new commit_method(store, true)); 134 XATest_4(new commit_method(store, true)); 135 XATest_5(new commit_method(store, true)); 136 XATest_6(new commit_method(store, true)); 137 138 XATest_1(new commit_method(store, false)); 139 XATest_2(new commit_method(store, false)); 140 XATest_3(new commit_method(store, false)); 141 XATest_4(new commit_method(store, false)); 142 XATest_5(new commit_method(store, false)); 143 XATest_6(new commit_method(store, false)); 144 } 145 catch (StandardException e) 146 { 147 String msg = e.getMessage(); 148 if (msg == null) 149 msg = e.getClass().getName(); 150 REPORT(msg); 151 e.printStackTrace(); 152 throw T_Fail.exceptionFail(e); 153 } 154 catch (Throwable t) 155 { 156 t.printStackTrace(); 157 } 158 } 159 160 164 165 169 170 175 void XATest_1( 176 commit_method commit_method) 177 throws StandardException, T_Fail 178 { 179 REPORT("(XATest_1) starting"); 180 181 ContextManager cm = 182 ContextService.getFactory().getCurrentContextManager(); 183 184 186 XATransactionController xa_tc = (XATransactionController) 188 store.startXATransaction( 189 cm, 190 42, global_id, 192 branch_id); 193 194 commit_method.commit(true, 42, global_id, branch_id, xa_tc); 196 197 xa_tc.destroy(); 199 200 202 xa_tc = (XATransactionController) 204 store.startXATransaction( 205 cm, 206 42, global_id, 208 branch_id); 209 210 T_AccessRow template_row = new T_AccessRow(1); 212 long conglomid = 213 xa_tc.createConglomerate( 214 "heap", template_row.getRowArray(), null, null, TransactionController.IS_DEFAULT); 220 221 commit_method.commit(true, 42, global_id, branch_id, xa_tc); 223 224 xa_tc.destroy(); 226 227 229 xa_tc = (XATransactionController) 231 store.startXATransaction( 232 cm, 233 42, global_id, 235 branch_id); 236 237 ScanController scan1 = xa_tc.openScan( 239 conglomid, 240 false, 0, TransactionController.MODE_RECORD, 243 TransactionController.ISOLATION_SERIALIZABLE, 244 (FormatableBitSet) null, null, 0, null, null, 0); 251 scan1.next(); 252 scan1.close(); 253 254 commit_method.commit(true, 42, global_id, branch_id, xa_tc); 256 257 xa_tc.destroy(); 259 260 REPORT("(XATest_1) finishing"); 261 } 262 263 268 void XATest_2( 269 commit_method commit_method) 270 throws StandardException, T_Fail 271 { 272 REPORT("(XATest_2) starting"); 273 ContextManager cm = 274 ContextService.getFactory().getCurrentContextManager(); 275 276 278 XATransactionController xa_tc = (XATransactionController) 280 store.startXATransaction( 281 cm, 282 42, global_id, 284 branch_id); 285 286 if (!xa_tc.isGlobal()) 287 { 288 throw T_Fail.testFailMsg("should be a global transaction."); 289 } 290 291 if (xa_tc.xa_prepare() != XATransactionController.XA_RDONLY) 293 { 294 throw T_Fail.testFailMsg( 295 "prepare of idle xact did not return XA_RDONLY."); 296 } 297 298 try 300 { 301 306 commit_method.commit(false, 42, null, null, xa_tc); 307 308 throw T_Fail.testFailMsg( 309 "A XA_RDONLY prepare-committed xact cant be 2P xa_committed."); 310 } 311 catch (StandardException se) 312 { 313 } 315 316 if (((XAResourceManager) store.getXAResourceManager()).find( 318 new XAXactId(42, global_id, branch_id)) != null) 319 { 320 throw T_Fail.testFailMsg( 321 "A XA_RDONLY prepare-committed xact should not be findable."); 322 } 323 324 xa_tc.destroy(); 326 327 329 xa_tc = (XATransactionController) 331 store.startXATransaction( 332 cm, 333 42, global_id, 335 branch_id); 336 337 T_AccessRow template_row = new T_AccessRow(1); 339 long conglomid = 340 xa_tc.createConglomerate( 341 "heap", template_row.getRowArray(), null, null, TransactionController.IS_DEFAULT); 347 if (xa_tc.xa_prepare() != XATransactionController.XA_OK) 349 { 350 throw T_Fail.testFailMsg( 351 "prepare of update xact did not return XA_OK."); 352 } 353 354 commit_method.commit(false, 42, global_id, branch_id, xa_tc); 356 357 xa_tc.destroy(); 359 360 362 xa_tc = (XATransactionController) 364 store.startXATransaction( 365 cm, 366 42, global_id, 368 branch_id); 369 370 ScanController scan1 = xa_tc.openScan( 372 conglomid, 373 false, 0, TransactionController.MODE_RECORD, 376 TransactionController.ISOLATION_SERIALIZABLE, 377 (FormatableBitSet) null, null, 0, null, null, 0); 384 scan1.next(); 385 scan1.close(); 386 387 if (xa_tc.xa_prepare() != XATransactionController.XA_RDONLY) 389 { 390 throw T_Fail.testFailMsg( 391 "prepare of idle xact did not return XA_RDONLY."); 392 } 393 394 try 396 { 397 402 commit_method.commit(false, 42, null, null, xa_tc); 403 404 throw T_Fail.testFailMsg( 405 "A XA_RDONLY prepare-committed xact cant be 2P xa_committed."); 406 } 407 catch (StandardException se) 408 { 409 } 411 412 if (((XAResourceManager) store.getXAResourceManager()).find( 414 new XAXactId(42, global_id, branch_id)) != null) 415 { 416 throw T_Fail.testFailMsg( 417 "A XA_RDONLY prepare-committed xact should not be findable."); 418 } 419 420 xa_tc.destroy(); 422 423 REPORT("(XATest_2) finishing"); 424 } 425 426 431 void XATest_3( 432 commit_method commit_method) 433 throws StandardException, T_Fail 434 { 435 REPORT("(XATest_3) starting"); 436 437 ContextManager cm = 438 ContextService.getFactory().getCurrentContextManager(); 439 440 442 XATransactionController xa_tc = (XATransactionController) 444 store.startXATransaction( 445 cm, 446 42, global_id, 448 branch_id); 449 450 commit_method.rollback(42, global_id, branch_id, xa_tc); 452 453 xa_tc.destroy(); 455 456 458 xa_tc = (XATransactionController) 460 store.startXATransaction( 461 cm, 462 42, global_id, 464 branch_id); 465 466 T_AccessRow template_row = new T_AccessRow(1); 468 long conglomid = 469 xa_tc.createConglomerate( 470 "heap", template_row.getRowArray(), null, null, TransactionController.IS_DEFAULT); 476 477 commit_method.rollback(42, global_id, branch_id, xa_tc); 479 480 xa_tc.destroy(); 482 483 485 xa_tc = (XATransactionController) 487 store.startXATransaction( 488 cm, 489 42, global_id, 491 branch_id); 492 493 template_row = new T_AccessRow(1); 495 conglomid = 496 xa_tc.createConglomerate( 497 "heap", template_row.getRowArray(), null, null, TransactionController.IS_DEFAULT); 503 504 commit_method.commit(true, 42, global_id, branch_id, xa_tc); 506 507 xa_tc.destroy(); 509 510 xa_tc = (XATransactionController) 512 store.startXATransaction( 513 cm, 514 42, global_id, 516 branch_id); 517 518 ScanController scan1 = xa_tc.openScan( 520 conglomid, 521 false, 0, TransactionController.MODE_RECORD, 524 TransactionController.ISOLATION_SERIALIZABLE, 525 (FormatableBitSet) null, null, 0, null, null, 0); 532 scan1.next(); 533 scan1.close(); 534 535 commit_method.rollback(42, global_id, branch_id, xa_tc); 537 538 xa_tc.destroy(); 540 541 REPORT("(XATest_3) finishing"); 542 } 543 544 549 void XATest_4( 550 commit_method commit_method) 551 throws StandardException, T_Fail 552 { 553 REPORT("(XATest_4) starting"); 554 555 ContextManager cm = 556 ContextService.getFactory().getCurrentContextManager(); 557 558 560 XATransactionController xa_tc = (XATransactionController) 562 store.startXATransaction( 563 cm, 564 42, global_id, 566 branch_id); 567 568 if (xa_tc.xa_prepare() != XATransactionController.XA_RDONLY) 570 { 571 throw T_Fail.testFailMsg( 572 "prepare of idle xact did not return XA_RDONLY."); 573 } 574 575 577 commit_method.commit(true, 42, null, null, xa_tc); 579 580 581 582 if (((XAResourceManager) store.getXAResourceManager()).find( 584 new XAXactId(42, global_id, branch_id)) != null) 585 { 586 throw T_Fail.testFailMsg( 587 "A XA_RDONLY prepare-committed xact should not be findable."); 588 } 589 590 xa_tc.destroy(); 592 593 595 xa_tc = (XATransactionController) 597 store.startXATransaction( 598 cm, 599 42, global_id, 601 branch_id); 602 603 T_AccessRow template_row = new T_AccessRow(1); 605 long conglomid = 606 xa_tc.createConglomerate( 607 "heap", template_row.getRowArray(), null, null, TransactionController.IS_DEFAULT); 613 614 615 ScanController scan1 = xa_tc.openScan( 618 conglomid, 619 false, 0, TransactionController.MODE_RECORD, 622 TransactionController.ISOLATION_SERIALIZABLE, 623 (FormatableBitSet) null, null, 0, null, null, 0); 630 scan1.next(); 631 scan1.close(); 632 633 if (xa_tc.xa_prepare() != XATransactionController.XA_OK) 635 { 636 throw T_Fail.testFailMsg( 637 "prepare of update xact did not return XA_OK."); 638 } 639 640 try 641 { 642 scan1 = xa_tc.openScan( 644 conglomid, 645 false, 0, TransactionController.MODE_RECORD, 648 TransactionController.ISOLATION_SERIALIZABLE, 649 (FormatableBitSet) null, null, 0, null, null, 0); 656 scan1.next(); 657 scan1.close(); 658 659 throw T_Fail.testFailMsg( 660 "Should not be able to do anything on xact after prepare."); 661 } 662 catch (StandardException se) 663 { 664 } 666 667 668 commit_method.rollback(42, global_id, branch_id, xa_tc); 670 671 commit_method.commit(true, 42, null, null, xa_tc); 672 673 if (((XAResourceManager) store.getXAResourceManager()).find( 675 new XAXactId(42, global_id, branch_id)) != null) 676 { 677 throw T_Fail.testFailMsg( 678 "A xa_rollbacked xact should not be findable."); 679 } 680 681 682 xa_tc.destroy(); 684 685 xa_tc = (XATransactionController) 687 store.startXATransaction( 688 cm, 689 42, global_id, 691 branch_id); 692 693 try 694 { 695 scan1 = xa_tc.openScan( 697 conglomid, 698 false, 0, TransactionController.MODE_RECORD, 701 TransactionController.ISOLATION_SERIALIZABLE, 702 (FormatableBitSet) null, null, 0, null, null, 0); 709 scan1.next(); 710 scan1.close(); 711 712 throw T_Fail.testFailMsg( 713 "Should not be able to open conglom, the create was aborted."); 714 } 715 catch (StandardException se) 716 { 717 } 719 720 xa_tc.destroy(); 721 722 723 725 xa_tc = (XATransactionController) 727 store.startXATransaction( 728 cm, 729 42, global_id, 731 branch_id); 732 733 template_row = new T_AccessRow(1); 735 conglomid = 736 xa_tc.createConglomerate( 737 "heap", template_row.getRowArray(), null, null, TransactionController.IS_DEFAULT); 743 commit_method.commit(true, 42, global_id, branch_id, xa_tc); 744 745 xa_tc.destroy(); 746 747 748 xa_tc = (XATransactionController) 750 store.startXATransaction( 751 cm, 752 42, global_id, 754 branch_id); 755 756 scan1 = xa_tc.openScan( 758 conglomid, 759 false, 0, TransactionController.MODE_RECORD, 762 TransactionController.ISOLATION_SERIALIZABLE, 763 (FormatableBitSet) null, null, 0, null, null, 0); 770 scan1.next(); 771 scan1.close(); 772 773 if (xa_tc.xa_prepare() != XATransactionController.XA_RDONLY) 775 { 776 throw T_Fail.testFailMsg( 777 "prepare of idle xact did not return XA_RDONLY."); 778 } 779 780 commit_method.commit(true, 42, null, null, xa_tc); 782 783 if (((XAResourceManager) store.getXAResourceManager()).find( 785 new XAXactId(42, global_id, branch_id)) != null) 786 { 787 throw T_Fail.testFailMsg( 788 "A XA_RDONLY prepare-committed xact should not be findable."); 789 } 790 791 xa_tc.destroy(); 793 794 REPORT("(XATest_5) finishing"); 795 } 796 797 802 void XATest_5( 803 commit_method commit_method) 804 throws StandardException, T_Fail 805 { 806 REPORT("(XATest_5) starting"); 807 808 if (((XAResourceManager) store.getXAResourceManager()).recover( 810 XAResource.TMSTARTRSCAN).length != 0) 811 { 812 throw T_Fail.testFailMsg( 813 "recover incorrectly returned prepared xacts."); 814 } 815 816 if (((XAResourceManager) store.getXAResourceManager()).recover( 818 XAResource.TMNOFLAGS).length != 0) 819 { 820 throw T_Fail.testFailMsg("NOFLAGS should always return 0."); 821 } 822 823 ContextManager cm = 824 ContextService.getFactory().getCurrentContextManager(); 825 826 828 XATransactionController xa_tc = (XATransactionController) 830 store.startXATransaction( 831 cm, 832 42, global_id, 834 branch_id); 835 836 if (((XAResourceManager) store.getXAResourceManager()).recover( 838 XAResource.TMSTARTRSCAN).length != 0) 839 { 840 throw T_Fail.testFailMsg( 841 "recover incorrectly returned prepared xacts."); 842 } 843 844 commit_method.commit(true, 42, global_id, branch_id, xa_tc); 846 847 xa_tc.destroy(); 849 850 852 xa_tc = (XATransactionController) 854 store.startXATransaction( 855 cm, 856 42, global_id, 858 branch_id); 859 860 T_AccessRow template_row = new T_AccessRow(1); 862 long conglomid = 863 xa_tc.createConglomerate( 864 "heap", template_row.getRowArray(), null, null, TransactionController.IS_DEFAULT); 870 if (((XAResourceManager) store.getXAResourceManager()).recover( 872 XAResource.TMSTARTRSCAN).length != 0) 873 { 874 throw T_Fail.testFailMsg( 875 "recover incorrectly returned prepared xacts."); 876 } 877 878 commit_method.commit(true, 42, global_id, branch_id, xa_tc); 880 881 xa_tc.destroy(); 883 884 886 xa_tc = (XATransactionController) 888 store.startXATransaction( 889 cm, 890 42, global_id, 892 branch_id); 893 894 ScanController scan1 = xa_tc.openScan( 896 conglomid, 897 false, 0, TransactionController.MODE_RECORD, 900 TransactionController.ISOLATION_SERIALIZABLE, 901 (FormatableBitSet) null, null, 0, null, null, 0); 908 scan1.next(); 909 scan1.close(); 910 911 if (((XAResourceManager) store.getXAResourceManager()).recover( 913 XAResource.TMSTARTRSCAN).length != 0) 914 { 915 throw T_Fail.testFailMsg( 916 "recover incorrectly returned prepared xacts."); 917 } 918 919 920 commit_method.commit(true, 42, global_id, branch_id, xa_tc); 922 923 xa_tc.destroy(); 925 926 928 xa_tc = (XATransactionController) 930 store.startXATransaction( 931 cm, 932 42, global_id, 934 branch_id); 935 936 template_row = new T_AccessRow(1); 938 conglomid = 939 xa_tc.createConglomerate( 940 "heap", template_row.getRowArray(), null, null, TransactionController.IS_DEFAULT); 946 if (((XAResourceManager) store.getXAResourceManager()).recover( 948 XAResource.TMSTARTRSCAN).length != 0) 949 { 950 throw T_Fail.testFailMsg( 951 "recover incorrectly returned prepared xacts."); 952 } 953 954 if (xa_tc.xa_prepare() != XATransactionController.XA_OK) 956 { 957 throw T_Fail.testFailMsg( 958 "prepare of update xact did not return XA_OK."); 959 } 960 961 try 962 { 963 scan1 = xa_tc.openScan( 965 conglomid, 966 false, 0, TransactionController.MODE_RECORD, 969 TransactionController.ISOLATION_SERIALIZABLE, 970 (FormatableBitSet) null, null, 0, null, null, 0); 977 scan1.next(); 978 scan1.close(); 979 980 throw T_Fail.testFailMsg( 981 "Should not be able to do anything on xact after prepare."); 982 } 983 catch (StandardException se) 984 { 985 } 987 988 Xid [] prepared_xacts = 990 ((XAResourceManager) store.getXAResourceManager()).recover( 991 XAResource.TMSTARTRSCAN); 992 993 if (prepared_xacts.length != 1) 994 { 995 throw T_Fail.testFailMsg( 996 "recover incorrectly returned wrong prepared xacts."); 997 } 998 999 if (prepared_xacts[0].getFormatId() != 42) 1000 throw T_Fail.testFailMsg( 1001 "bad format id = " + prepared_xacts[0].getFormatId()); 1002 1003 byte[] gid = prepared_xacts[0].getGlobalTransactionId(); 1004 1005 if (!java.util.Arrays.equals(gid, global_id)) 1006 { 1007 throw T_Fail.testFailMsg( 1008 "bad global id = " + org.apache.derbyTesting.unitTests.util.BitUtil.hexDump(gid)); 1009 } 1010 1011 byte[] bid = prepared_xacts[0].getBranchQualifier(); 1012 1013 if (!java.util.Arrays.equals(bid, branch_id)) 1014 { 1015 throw T_Fail.testFailMsg( 1016 "bad branch id = " + org.apache.derbyTesting.unitTests.util.BitUtil.hexDump(bid)); 1017 } 1018 1019 if (((XAResourceManager) store.getXAResourceManager()).recover( 1020 XAResource.TMNOFLAGS).length != 0) 1021 { 1022 throw T_Fail.testFailMsg("NOFLAGS should always return 0."); 1023 } 1024 1025 commit_method.commit(false, 42, global_id, branch_id, xa_tc); 1027 1028 if (((XAResourceManager) store.getXAResourceManager()).recover( 1030 XAResource.TMSTARTRSCAN).length != 0) 1031 { 1032 throw T_Fail.testFailMsg( 1033 "recover incorrectly returned prepared xacts."); 1034 } 1035 1036 xa_tc.destroy(); 1038 1039 if (((XAResourceManager) store.getXAResourceManager()).recover( 1041 XAResource.TMSTARTRSCAN).length != 0) 1042 { 1043 throw T_Fail.testFailMsg( 1044 "recover incorrectly returned prepared xacts."); 1045 } 1046 1047 REPORT("(XATest_5) finishing"); 1048 1049 } 1050 1051 1056 void XATest_6( 1057 commit_method commit_method) 1058 throws StandardException, T_Fail 1059 { 1060 REPORT("(XATest_5) starting"); 1061 1062 ContextManager cm = 1063 ContextService.getFactory().getCurrentContextManager(); 1064 1065 TransactionController tc = store.getTransaction(cm); 1066 1067 T_AccessRow template_row = new T_AccessRow(1); 1069 long conglomid = 1070 tc.createConglomerate( 1071 "heap", template_row.getRowArray(), null, null, TransactionController.IS_DEFAULT); 1077 tc.commit(); 1078 1079 1081 XATransactionController xa_tc = (XATransactionController) 1083 tc.createXATransactionFromLocalTransaction( 1084 42, global_id, 1086 branch_id); 1087 1088 if (!xa_tc.isGlobal()) 1089 { 1090 throw T_Fail.testFailMsg("should be a global transaction."); 1091 } 1092 1093 1094 ScanController scan1 = xa_tc.openScan( 1096 conglomid, 1097 false, 0, TransactionController.MODE_RECORD, 1100 TransactionController.ISOLATION_SERIALIZABLE, 1101 (FormatableBitSet) null, null, 0, null, null, 0); 1108 1109 scan1.next(); 1110 scan1.close(); 1111 1112 1113 template_row = new T_AccessRow(1); 1115 conglomid = 1116 xa_tc.createConglomerate( 1117 "heap", template_row.getRowArray(), null, null, TransactionController.IS_DEFAULT); 1123 if (((XAResourceManager) store.getXAResourceManager()).recover( 1125 XAResource.TMSTARTRSCAN).length != 0) 1126 { 1127 throw T_Fail.testFailMsg( 1128 "recover incorrectly returned prepared xacts."); 1129 } 1130 1131 if (xa_tc.xa_prepare() != XATransactionController.XA_OK) 1133 { 1134 throw T_Fail.testFailMsg( 1135 "prepare of update xact did not return XA_OK."); 1136 } 1137 1138 try 1139 { 1140 scan1 = xa_tc.openScan( 1142 conglomid, 1143 false, 0, TransactionController.MODE_RECORD, 1146 TransactionController.ISOLATION_SERIALIZABLE, 1147 (FormatableBitSet) null, null, 0, null, null, 0); 1154 scan1.next(); 1155 scan1.close(); 1156 1157 throw T_Fail.testFailMsg( 1158 "Should not be able to do anything on xact after prepare."); 1159 } 1160 catch (StandardException se) 1161 { 1162 } 1164 1165 commit_method.commit(false, 42, global_id, branch_id, xa_tc); 1167 1168 xa_tc.destroy(); 1169 1170 REPORT("(XATest_6) finishing"); 1171 } 1172 1173} 1174 1175class commit_method 1176{ 1177 private boolean online_xact; 1178 private AccessFactory store; 1179 1180 public commit_method( 1181 AccessFactory store, 1182 boolean online_xact) 1183 { 1184 this.store = store; 1185 this.online_xact = online_xact; 1186 } 1187 1188 public void commit( 1189 boolean one_phase, 1190 int format_id, 1191 byte[] global_id, 1192 byte[] branch_id, 1193 XATransactionController xa_tc) 1194 throws StandardException 1195 { 1196 if (SanityManager.DEBUG) 1197 SanityManager.ASSERT((global_id != null) || (xa_tc != null)); 1198 1199 boolean local_online_xact = online_xact; 1200 1201 if (global_id == null) 1202 local_online_xact = true; 1203 if (xa_tc == null) 1204 local_online_xact = false; 1205 1206 if (local_online_xact) 1207 { 1208 xa_tc.xa_commit(one_phase); 1209 } 1210 else 1211 { 1212 Xid xid = new XAXactId(format_id, global_id, branch_id); 1213 1214 ContextManager cm = 1215 ((XAResourceManager) store.getXAResourceManager()).find(xid); 1216 1217 if (SanityManager.DEBUG) 1218 { 1219 SanityManager.ASSERT(cm != null, "could not find xid = " + xid); 1220 1221 SanityManager.ASSERT( 1222 cm == 1223 ContextService.getFactory().getCurrentContextManager(), 1224 "cm = " + cm + 1225 "current = " + 1226 ContextService.getFactory().getCurrentContextManager()); 1227 } 1228 1229 ((XAResourceManager) store.getXAResourceManager()).commit( 1230 cm, xid, one_phase); 1231 } 1232 } 1233 1234 public void rollback( 1235 int format_id, 1236 byte[] global_id, 1237 byte[] branch_id, 1238 XATransactionController xa_tc) 1239 throws StandardException 1240 { 1241 if (SanityManager.DEBUG) 1242 SanityManager.ASSERT((global_id != null) || (xa_tc != null)); 1243 1244 boolean local_online_xact = online_xact; 1245 1246 if (global_id == null) 1247 local_online_xact = true; 1248 if (xa_tc == null) 1249 local_online_xact = false; 1250 1251 if (local_online_xact) 1252 { 1253 xa_tc.xa_rollback(); 1254 } 1255 else 1256 { 1257 Xid xid = new XAXactId(format_id, global_id, branch_id); 1258 1259 ContextManager cm = 1260 ((XAResourceManager) store.getXAResourceManager()).find(xid); 1261 1262 if (SanityManager.DEBUG) 1263 { 1264 SanityManager.ASSERT(cm != null, "could not find xid = " + xid); 1265 1266 SanityManager.ASSERT( 1267 cm == 1268 ContextService.getFactory().getCurrentContextManager(), 1269 "cm = " + cm + 1270 "current = " + 1271 ContextService.getFactory().getCurrentContextManager()); 1272 } 1273 1274 ((XAResourceManager) store.getXAResourceManager()).rollback( 1275 cm, xid); 1276 } 1277 } 1278} 1279 | Popular Tags |