1 21 22 package org.apache.derby.impl.store.access; 23 24 import java.util.ArrayList ; 25 import java.util.Enumeration ; 26 import java.util.Hashtable ; 27 import java.util.Properties ; 28 import java.util.Vector ; 29 30 import org.apache.derby.iapi.reference.SQLState; 31 import org.apache.derby.iapi.util.ReuseFactory; 32 33 import org.apache.derby.iapi.services.context.ContextManager; 34 35 import org.apache.derby.iapi.services.io.Storable; 36 37 import org.apache.derby.iapi.services.daemon.Serviceable; 38 import org.apache.derby.iapi.services.monitor.Monitor; 39 import org.apache.derby.iapi.services.sanity.SanityManager; 40 import org.apache.derby.iapi.error.StandardException; 41 import org.apache.derby.iapi.store.access.conglomerate.Conglomerate; 42 import org.apache.derby.iapi.store.access.conglomerate.ConglomerateFactory; 43 import org.apache.derby.iapi.store.access.conglomerate.ScanManager; 44 import org.apache.derby.iapi.store.access.conglomerate.MethodFactory; 45 import org.apache.derby.iapi.store.access.conglomerate.ScanControllerRowSource; 46 import org.apache.derby.iapi.store.access.conglomerate.Sort; 47 import org.apache.derby.iapi.store.access.conglomerate.SortFactory; 48 import org.apache.derby.iapi.store.access.conglomerate.TransactionManager; 49 import org.apache.derby.iapi.store.access.AccessFactory; 50 import org.apache.derby.iapi.store.access.AccessFactoryGlobals; 51 import org.apache.derby.iapi.store.access.ColumnOrdering; 52 import org.apache.derby.iapi.store.access.ConglomerateController; 53 import org.apache.derby.iapi.store.access.DynamicCompiledOpenConglomInfo; 54 import org.apache.derby.iapi.store.access.FileResource; 55 import org.apache.derby.iapi.store.access.GroupFetchScanController; 56 import org.apache.derby.iapi.store.access.Qualifier; 57 import org.apache.derby.iapi.store.access.RowLocationRetRowSource; 58 import org.apache.derby.iapi.store.access.RowSource; 59 import org.apache.derby.iapi.store.access.ScanController; 60 import org.apache.derby.iapi.store.access.SortController; 61 import org.apache.derby.iapi.store.access.SortCostController; 62 import org.apache.derby.iapi.store.access.SortObserver; 63 import org.apache.derby.iapi.store.access.StaticCompiledOpenConglomInfo; 64 import org.apache.derby.iapi.store.access.StoreCostController; 65 import org.apache.derby.iapi.store.access.TransactionController; 66 67 import org.apache.derby.iapi.store.access.XATransactionController; 68 69 70 import org.apache.derby.iapi.store.raw.ContainerHandle; 71 import org.apache.derby.iapi.store.raw.LockingPolicy; 72 73 74 import org.apache.derby.iapi.store.raw.Loggable; 75 import org.apache.derby.iapi.store.raw.Page; 76 import org.apache.derby.iapi.store.raw.Transaction; 77 78 import org.apache.derby.iapi.types.DataValueDescriptor; 79 80 import org.apache.derby.impl.store.access.conglomerate.ConglomerateUtil; 81 82 import org.apache.derby.iapi.store.access.DatabaseInstant; 83 84 import org.apache.derby.iapi.store.access.BackingStoreHashtable; 85 import org.apache.derby.iapi.services.io.FormatableBitSet; 86 87 import java.io.Serializable ; 88 89 90 import org.apache.derby.iapi.services.stream.HeaderPrintWriter; 92 import org.apache.derby.iapi.services.stream.InfoStreams; 93 94 public class RAMTransaction 95 implements XATransactionController, TransactionManager 96 { 97 98 101 protected Transaction rawtran; 102 103 106 protected RAMAccessManager accessmanager; 107 108 111 protected RAMTransactionContext context; 112 113 116 protected RAMTransaction parent_tran; 117 118 private Vector scanControllers; 121 private Vector conglomerateControllers; 122 private Vector sorts; 123 private Vector sortControllers; 124 125 128 private ArrayList freeSortIds; 129 130 133 protected Hashtable tempCongloms = null; 134 135 138 private long nextTempConglomId = -1; 139 140 145 private boolean alterTableCallMade = false; 146 147 154 private int transaction_lock_level; 155 156 160 161 private final void init( 162 RAMAccessManager myaccessmanager, 163 Transaction theRawTran, 164 RAMTransaction parent_tran) 165 { 166 this.rawtran = theRawTran; 167 this.parent_tran = parent_tran; 168 accessmanager = myaccessmanager; 169 scanControllers = new Vector (); 170 conglomerateControllers = new Vector (); 171 172 sorts = null; freeSortIds = null; sortControllers = null; 176 if (parent_tran != null) 177 { 178 183 tempCongloms = parent_tran.tempCongloms; 184 } 185 else 186 { 187 tempCongloms = null; } 189 } 190 191 protected RAMTransaction( 192 RAMAccessManager myaccessmanager, 193 Transaction theRawTran, 194 RAMTransaction parent_transaction) 195 throws StandardException 196 { 197 init(myaccessmanager, theRawTran, parent_transaction); 198 } 199 200 RAMTransaction( 201 RAMAccessManager myaccessmanager, 202 RAMTransaction tc, 203 int format_id, 204 byte[] global_id, 205 byte[] branch_id) 206 throws StandardException 207 { 208 init(myaccessmanager, tc.getRawStoreXact(), null); 209 210 if (SanityManager.DEBUG) 211 SanityManager.ASSERT(tc.getRawStoreXact().isIdle()); 212 213 this.context = tc.context; 214 215 this.context.setTransaction(this); 217 218 this.rawtran.createXATransactionFromLocalTransaction( 219 format_id, global_id, branch_id); 220 221 tc.rawtran = null; 225 } 226 227 228 RAMTransaction() 229 { 230 } 231 232 233 237 238 239 protected void closeControllers(boolean closeHeldControllers) 241 throws StandardException 242 { 243 Enumeration e; 244 245 if (!scanControllers.isEmpty()) 246 { 247 for (int i = scanControllers.size() - 1; i >= 0; i--) 249 { 250 ScanManager sc = (ScanManager) scanControllers.elementAt(i); 251 252 if (sc.closeForEndTransaction(closeHeldControllers)) 253 { 254 257 } 258 } 259 260 if (closeHeldControllers) 261 { 262 if (SanityManager.DEBUG) 263 { 264 SanityManager.ASSERT(scanControllers.isEmpty()); 265 } 266 scanControllers.removeAllElements(); 268 } 269 } 270 271 if (!conglomerateControllers.isEmpty()) 272 { 273 for (int i = conglomerateControllers.size() - 1; i >= 0; i--) 275 { 276 ConglomerateController cc = 277 (ConglomerateController) 278 conglomerateControllers.elementAt(i); 279 280 if (cc.closeForEndTransaction(closeHeldControllers)) 281 { 282 285 } 286 } 287 288 if (closeHeldControllers) 289 { 290 if (SanityManager.DEBUG) 291 { 292 SanityManager.ASSERT(scanControllers.isEmpty()); 293 } 294 conglomerateControllers.removeAllElements(); 296 } 297 } 298 299 if ((sortControllers != null) && !sortControllers.isEmpty()) 300 { 301 if (closeHeldControllers) 302 { 303 e = sortControllers.elements(); 304 while (e.hasMoreElements()) 305 { 306 SortController sc = (SortController) e.nextElement(); 307 sc.close(); 308 } 309 sortControllers.removeAllElements(); 310 } 311 } 312 313 if ((sorts != null) && (!sorts.isEmpty())) 314 { 315 if (closeHeldControllers) 316 { 317 e = sorts.elements(); 318 while (e.hasMoreElements()) 319 { 320 Sort sort = (Sort) e.nextElement(); 321 if (sort != null) 322 sort.drop(this); 323 } 324 sorts.removeAllElements(); 325 freeSortIds.clear(); 326 } 327 } 328 } 329 330 331 346 private LockingPolicy determine_locking_policy( 347 int requested_lock_level, 348 int isolation_level) 349 { 350 LockingPolicy ret_locking_policy; 351 352 if ((accessmanager.getSystemLockLevel() == 353 TransactionController.MODE_TABLE) || 354 (requested_lock_level == TransactionController.MODE_TABLE)) 355 { 356 ret_locking_policy = 357 accessmanager.table_level_policy[isolation_level]; 358 } 359 else 360 { 361 ret_locking_policy = 362 accessmanager.record_level_policy[isolation_level]; 363 364 } 365 return(ret_locking_policy); 366 } 367 368 private int determine_lock_level( 369 int requested_lock_level) 370 { 371 int ret_lock_level; 372 373 if ((accessmanager.getSystemLockLevel() == 374 TransactionController.MODE_TABLE) || 375 (requested_lock_level == TransactionController.MODE_TABLE)) 376 { 377 ret_lock_level = TransactionController.MODE_TABLE; 378 } 379 else 380 { 381 ret_lock_level = TransactionController.MODE_RECORD; 382 383 } 384 return(ret_lock_level); 385 } 386 387 private Conglomerate findExistingConglomerate(long conglomId) 388 throws StandardException 389 { 390 Conglomerate conglom = null; 391 392 if (conglomId < 0) 393 { 394 if (tempCongloms != null) 395 conglom = (Conglomerate) tempCongloms.get(new Long (conglomId)); 396 } 397 else 398 { 399 conglom = accessmanager.conglomCacheFind(this, conglomId); 400 } 401 402 if (conglom == null) 403 { 404 throw StandardException.newException( 405 SQLState.STORE_CONGLOMERATE_DOES_NOT_EXIST, 406 new Long (conglomId)); 407 } 408 else 409 { 410 return(conglom); 411 } 412 } 413 414 private Conglomerate findConglomerate(long conglomId) 415 throws StandardException 416 { 417 Conglomerate conglom = null; 418 419 if (conglomId >= 0) 420 { 421 conglom = accessmanager.conglomCacheFind(this, conglomId); 422 } 423 else 424 { 425 if (tempCongloms != null) 426 conglom = (Conglomerate) tempCongloms.get(new Long (conglomId)); 427 } 428 429 return(conglom); 430 } 431 432 void setContext(RAMTransactionContext rtc) 433 { 434 context = rtc; 435 } 436 437 440 public long[] getCacheStats(String cacheName) { 441 return getRawStoreXact().getCacheStats(cacheName); 442 } 443 444 private ConglomerateController openConglomerate( 445 Conglomerate conglom, 446 boolean hold, 447 int open_mode, 448 int lock_level, 449 int isolation_level, 450 StaticCompiledOpenConglomInfo static_info, 451 DynamicCompiledOpenConglomInfo dynamic_info) 452 throws StandardException 453 { 454 if (SanityManager.DEBUG) 455 { 456 if ((open_mode & 457 ~(ContainerHandle.MODE_UNLOGGED | 458 ContainerHandle.MODE_CREATE_UNLOGGED | 459 ContainerHandle.MODE_FORUPDATE | 460 ContainerHandle.MODE_READONLY | 461 ContainerHandle.MODE_TRUNCATE_ON_COMMIT | 462 ContainerHandle.MODE_DROP_ON_COMMIT | 463 ContainerHandle.MODE_OPEN_FOR_LOCK_ONLY | 464 ContainerHandle.MODE_LOCK_NOWAIT | 465 ContainerHandle.MODE_TRUNCATE_ON_ROLLBACK | 466 ContainerHandle.MODE_FLUSH_ON_COMMIT | 467 ContainerHandle.MODE_NO_ACTIONS_ON_COMMIT | 468 ContainerHandle.MODE_TEMP_IS_KEPT | 469 ContainerHandle.MODE_USE_UPDATE_LOCKS | 470 ContainerHandle.MODE_SECONDARY_LOCKED | 471 ContainerHandle.MODE_BASEROW_INSERT_LOCKED)) != 0) 472 { 473 SanityManager.THROWASSERT( 474 "Bad open mode to openConglomerate:" + 475 Integer.toHexString(open_mode)); 476 } 477 478 SanityManager.ASSERT(conglom != null); 479 480 if (lock_level != MODE_RECORD && lock_level != MODE_TABLE) 481 { 482 SanityManager.THROWASSERT( 483 "Bad lock level to openConglomerate:" + lock_level); 484 } 485 } 486 487 ConglomerateController cc = 489 conglom.open( 490 this, rawtran, hold, open_mode, 491 determine_lock_level(lock_level), 492 determine_locking_policy(lock_level, isolation_level), 493 static_info, 494 dynamic_info); 495 496 conglomerateControllers.addElement(cc); 498 499 return cc; 500 } 501 502 private ScanController openScan( 503 Conglomerate conglom, 504 boolean hold, 505 int open_mode, 506 int lock_level, 507 int isolation_level, 508 FormatableBitSet scanColumnList, 509 DataValueDescriptor[] startKeyValue, 510 int startSearchOperator, 511 Qualifier qualifier[][], 512 DataValueDescriptor[] stopKeyValue, 513 int stopSearchOperator, 514 StaticCompiledOpenConglomInfo static_info, 515 DynamicCompiledOpenConglomInfo dynamic_info) 516 throws StandardException 517 { 518 if (SanityManager.DEBUG) 519 { 520 if ((open_mode & 521 ~(TransactionController.OPENMODE_FORUPDATE | 522 TransactionController.OPENMODE_USE_UPDATE_LOCKS | 523 TransactionController.OPENMODE_FOR_LOCK_ONLY | 524 TransactionController.OPENMODE_LOCK_NOWAIT | 525 TransactionController.OPENMODE_SECONDARY_LOCKED)) != 0) 526 { 527 SanityManager.THROWASSERT( 528 "Bad open mode to openScan:" + 529 Integer.toHexString(open_mode)); 530 } 531 532 if (!((lock_level == MODE_RECORD | lock_level == MODE_TABLE))) 533 { 534 SanityManager.THROWASSERT( 535 "Bad lock level to openScan:" + lock_level); 536 } 537 } 538 539 ScanManager sm = 541 conglom.openScan( 542 this, rawtran, hold, open_mode, 543 determine_lock_level(lock_level), 544 determine_locking_policy(lock_level, isolation_level), 545 isolation_level, 546 scanColumnList, 547 startKeyValue, startSearchOperator, 548 qualifier, 549 stopKeyValue, stopSearchOperator, 550 static_info, 551 dynamic_info); 552 553 scanControllers.addElement(sm); 555 556 return(sm); 557 } 558 559 560 561 564 public void resetCacheStats(String cacheName) { 565 getRawStoreXact().resetCacheStats(cacheName); 566 } 567 568 574 protected void invalidateConglomerateCache() 575 throws StandardException 576 { 577 if (alterTableCallMade) 578 { 579 accessmanager.conglomCacheInvalidate(); 580 alterTableCallMade = false; 581 } 582 } 583 584 585 589 590 612 public void addColumnToConglomerate( 613 long conglomId, 614 int column_id, 615 Storable template_column) 616 throws StandardException 617 { 618 boolean is_temporary = (conglomId < 0); 619 620 Conglomerate conglom = findConglomerate(conglomId); 621 if (conglom == null) 622 { 623 throw StandardException.newException( 624 SQLState.AM_NO_SUCH_CONGLOMERATE_DROP, new Long (conglomId)); 625 } 626 627 ConglomerateController cc = 629 conglom.open( 630 this, rawtran, false, OPENMODE_FORUPDATE, 631 MODE_TABLE, 632 accessmanager.table_level_policy[ 633 TransactionController.ISOLATION_SERIALIZABLE], 634 (StaticCompiledOpenConglomInfo) null, 635 (DynamicCompiledOpenConglomInfo) null); 636 637 conglom.addColumn(this, column_id, template_column); 638 639 if (is_temporary) 642 { 643 if (tempCongloms != null) 645 tempCongloms.remove(new Long (conglomId)); 646 tempCongloms.put(new Long (conglomId), conglom); 647 } 648 else 649 { 650 alterTableCallMade = true; 651 652 accessmanager.conglomCacheUpdateEntry(conglomId, conglom); 654 } 655 656 cc.close(); 657 658 return; 659 } 660 661 680 public StaticCompiledOpenConglomInfo getStaticCompiledConglomInfo( 681 long conglomId) 682 throws StandardException 683 { 684 return( 685 findExistingConglomerate( 686 conglomId).getStaticCompiledConglomInfo(this, conglomId)); 687 } 688 689 707 public DynamicCompiledOpenConglomInfo getDynamicCompiledConglomInfo( 708 long conglomId) 709 throws StandardException 710 { 711 return( 712 findExistingConglomerate( 713 conglomId).getDynamicCompiledConglomInfo(conglomId)); 714 } 715 716 717 private final int countCreatedSorts() 718 { 719 int ret_val = 0; 720 if (sorts != null) 721 { 722 for (int i = 0; i < sorts.size(); i++) 723 { 724 if (sorts.elementAt(i) != null) 725 ret_val++; 726 } 727 } 728 729 return(ret_val); 730 } 731 732 765 public int countOpens(int which_to_count) 766 throws StandardException 767 { 768 int ret_val = -1; 769 770 switch (which_to_count) 771 { 772 case OPEN_CONGLOMERATE: 773 ret_val = conglomerateControllers.size(); 774 break; 775 case OPEN_SCAN: 776 ret_val = scanControllers.size(); 777 break; 778 case OPEN_CREATED_SORTS: 779 ret_val = countCreatedSorts(); 780 break; 781 case OPEN_SORT: 782 ret_val = 783 ((sortControllers != null) ? sortControllers.size() : 0); 784 break; 785 case OPEN_TOTAL: 786 ret_val = 787 conglomerateControllers.size() + scanControllers.size() + 788 ((sortControllers != null) ? sortControllers.size() : 0) + 789 countCreatedSorts(); 790 break; 791 } 792 793 return(ret_val); 794 } 795 796 803 public long createConglomerate( 804 String implementation, 805 DataValueDescriptor[] template, 806 ColumnOrdering[] columnOrder, 807 Properties properties, 808 int temporaryFlag) 809 throws StandardException 810 { 811 MethodFactory mfactory; 813 mfactory = accessmanager.findMethodFactoryByImpl(implementation); 814 if (mfactory == null || !(mfactory instanceof ConglomerateFactory)) 815 { 816 throw StandardException.newException( 817 SQLState.AM_NO_SUCH_CONGLOMERATE_TYPE, implementation); 818 } 819 ConglomerateFactory cfactory = (ConglomerateFactory) mfactory; 820 821 int segment; 825 long conglomid; 826 if ((temporaryFlag & TransactionController.IS_TEMPORARY) 827 == TransactionController.IS_TEMPORARY) 828 { 829 segment = ContainerHandle.TEMPORARY_SEGMENT; 830 conglomid = ContainerHandle.DEFAULT_ASSIGN_ID; 831 } 832 else 833 { 834 segment = 0; conglomid = 836 accessmanager.getNextConglomId( 837 cfactory.getConglomerateFactoryId()); 838 } 839 840 Conglomerate conglom = 842 cfactory.createConglomerate( 843 this, segment, conglomid, template, 844 columnOrder, properties, temporaryFlag); 845 846 long conglomId; 847 if ((temporaryFlag & TransactionController.IS_TEMPORARY) 848 == TransactionController.IS_TEMPORARY) 849 { 850 conglomId = nextTempConglomId--; 851 if (tempCongloms == null) 852 tempCongloms = new Hashtable (); 853 tempCongloms.put(new Long (conglomId), conglom); 854 } 855 else 856 { 857 conglomId = conglom.getContainerid(); 858 859 accessmanager.conglomCacheAddEntry(conglomId, conglom); 860 } 861 862 return conglomId; 863 } 864 865 871 public long createAndLoadConglomerate( 872 String implementation, 873 DataValueDescriptor[] template, 874 ColumnOrdering[] columnOrder, 875 Properties properties, 876 int temporaryFlag, 877 RowLocationRetRowSource rowSource, 878 long[] rowCount) 879 throws StandardException 880 { 881 return( 882 recreateAndLoadConglomerate( 883 implementation, 884 true, 885 template, 886 columnOrder, 887 properties, 888 temporaryFlag, 889 0 , 890 rowSource, 891 rowCount)); 892 } 893 894 900 public long recreateAndLoadConglomerate( 901 String implementation, 902 boolean recreate_ifempty, 903 DataValueDescriptor[] template, 904 ColumnOrdering[] columnOrder, 905 Properties properties, 906 int temporaryFlag, 907 long orig_conglomId, 908 RowLocationRetRowSource rowSource, 909 long[] rowCount) 910 throws StandardException 911 912 { 913 long conglomId = 916 createConglomerate( 917 implementation, template, columnOrder, properties, temporaryFlag); 918 919 long rows_loaded = 920 loadConglomerate( 921 conglomId, 922 true, rowSource); 924 925 if (rowCount != null) 926 rowCount[0] = rows_loaded; 927 928 if (!recreate_ifempty && (rows_loaded == 0)) 929 { 930 dropConglomerate(conglomId); 931 932 conglomId = orig_conglomId; 933 } 934 935 return conglomId; 936 } 937 938 951 public String debugOpened() throws StandardException 952 { 953 String str = null; 954 955 if (SanityManager.DEBUG) 956 { 957 Enumeration e; 958 959 str = new String (); 960 961 e = scanControllers.elements(); 962 while (e.hasMoreElements()) 963 { 964 ScanController sc = (ScanController) e.nextElement(); 965 str += "open scan controller: " + sc + "\n"; 966 } 967 968 e = conglomerateControllers.elements(); 969 while (e.hasMoreElements()) 970 { 971 ConglomerateController cc = 972 (ConglomerateController) e.nextElement(); 973 str += "open conglomerate controller: " + cc + "\n"; 974 } 975 976 if (sortControllers != null) 977 { 978 e = sortControllers.elements(); 979 while (e.hasMoreElements()) 980 { 981 SortController sc = (SortController) e.nextElement(); 982 str += "open sort controller: " + sc + "\n"; 983 } 984 } 985 986 if (sorts != null) 987 { 988 for (int i = 0; i < sorts.size(); i++) 989 { 990 Sort sort = (Sort) sorts.elementAt(i); 991 992 if (sort != null) 993 { 994 str += 995 "sorts created by createSort() in current xact:" + 996 sort + "\n"; 997 } 998 } 999 } 1000 1001 if (tempCongloms != null) 1002 { 1003 e = tempCongloms.keys(); 1004 while (e.hasMoreElements()) 1005 { 1006 Long conglomId = (Long ) e.nextElement(); 1007 Conglomerate c = (Conglomerate) tempCongloms.get(conglomId); 1008 str += "temp conglomerate id = " + conglomId + ": " + c; 1009 } 1010 } 1011 1012 } 1013 1014 return(str); 1015 } 1016 1017 public boolean conglomerateExists(long conglomId) 1018 throws StandardException 1019 { 1020 Conglomerate conglom = findConglomerate(conglomId); 1021 if (conglom == null) 1022 return false; 1023 return true; 1024 } 1025 1026 public void dropConglomerate(long conglomId) 1027 throws StandardException 1028 { 1029 Conglomerate conglom = findExistingConglomerate(conglomId); 1030 1031 conglom.drop(this); 1032 1033 if (conglomId < 0) 1034 { 1035 if (tempCongloms != null) 1036 tempCongloms.remove(new Long (conglomId)); 1037 } 1038 else 1039 { 1040 accessmanager.conglomCacheRemoveEntry(conglomId); 1041 } 1042 } 1043 1044 1082 public boolean fetchMaxOnBtree( 1083 long conglomId, 1084 int open_mode, 1085 int lock_level, 1086 int isolation_level, 1087 FormatableBitSet scanColumnList, 1088 DataValueDescriptor[] fetchRow) 1089 throws StandardException 1090 { 1091 Conglomerate conglom = findExistingConglomerate(conglomId); 1093 1094 return( 1096 conglom.fetchMaxOnBTree( 1097 this, 1098 rawtran, 1099 conglomId, 1100 open_mode, 1101 lock_level, 1102 determine_locking_policy(lock_level, isolation_level), 1103 isolation_level, 1104 scanColumnList, 1105 fetchRow)); 1106 } 1107 1108 1109 1136 public Properties getUserCreateConglomPropList() 1137 { 1138 Properties ret_properties = 1139 ConglomerateUtil.createUserRawStorePropertySet((Properties ) null); 1140 1141 return(ret_properties); 1142 } 1143 1144 1150 public boolean isIdle() 1151 { 1152 return rawtran.isIdle(); 1153 } 1154 1155 1167 public boolean isGlobal() 1168 { 1169 return(rawtran.getGlobalId() != null); 1170 } 1171 1172 1179 public boolean isPristine() 1180 { 1181 return rawtran.isPristine(); 1182 } 1183 1184 1211 public Object 1212 createXATransactionFromLocalTransaction( 1213 int format_id, 1214 byte[] global_id, 1215 byte[] branch_id) 1216 throws StandardException 1217 { 1218 1219 getRawStoreXact().createXATransactionFromLocalTransaction( 1220 format_id, global_id, branch_id); 1221 1222 return this; 1223 } 1224 1225 1242 public long loadConglomerate( 1243 long conglomId, 1244 boolean createConglom, 1245 RowLocationRetRowSource rowSource) 1246 throws StandardException 1247 { 1248 Conglomerate conglom = findExistingConglomerate(conglomId); 1250 1251 return(conglom.load(this, createConglom, rowSource)); 1255 } 1256 1257 1265 public void loadConglomerate( 1266 long conglomId, 1267 RowLocationRetRowSource rowSource) 1268 throws StandardException 1269 { 1270 loadConglomerate( 1271 conglomId, 1272 false, rowSource); 1274 } 1275 1276 1286 public void logAndDo(Loggable operation) 1287 throws StandardException 1288 { 1289 rawtran.logAndDo(operation); 1290 } 1291 1292 public ConglomerateController openCompiledConglomerate( 1293 boolean hold, 1294 int open_mode, 1295 int lock_level, 1296 int isolation_level, 1297 StaticCompiledOpenConglomInfo static_info, 1298 DynamicCompiledOpenConglomInfo dynamic_info) 1299 throws StandardException 1300 { 1301 if (SanityManager.DEBUG) 1302 { 1303 SanityManager.ASSERT(static_info != null); 1304 SanityManager.ASSERT(dynamic_info != null); 1305 } 1306 1307 1310 return( 1311 openConglomerate( 1312 (Conglomerate) static_info.getConglom(), 1313 hold, open_mode, lock_level, isolation_level, 1314 static_info, dynamic_info)); 1315 } 1316 1317 public ConglomerateController openConglomerate( 1318 long conglomId, 1319 boolean hold, 1320 int open_mode, 1321 int lock_level, 1322 int isolation_level) 1323 throws StandardException 1324 { 1325 return( 1326 openConglomerate( 1327 findExistingConglomerate(conglomId), 1328 hold, open_mode, lock_level, isolation_level, 1329 (StaticCompiledOpenConglomInfo) null, 1330 (DynamicCompiledOpenConglomInfo) null)); 1331 } 1332 1333 public long findConglomid(long container_id) 1334 throws StandardException 1335 { 1336 return(container_id); 1337 } 1338 1339 public long findContainerid(long conglom_id) 1340 throws StandardException 1341 { 1342 return(conglom_id); 1343 } 1344 1345 1349 public BackingStoreHashtable createBackingStoreHashtableFromScan( 1350 long conglomId, 1351 int open_mode, 1352 int lock_level, 1353 int isolation_level, 1354 FormatableBitSet scanColumnList, 1355 DataValueDescriptor[] startKeyValue, 1356 int startSearchOperator, 1357 Qualifier qualifier[][], 1358 DataValueDescriptor[] stopKeyValue, 1359 int stopSearchOperator, 1360 long max_rowcnt, 1361 int[] key_column_numbers, 1362 boolean remove_duplicates, 1363 long estimated_rowcnt, 1364 long max_inmemory_rowcnt, 1365 int initialCapacity, 1366 float loadFactor, 1367 boolean collect_runtimestats, 1368 boolean skipNullKeyColumns) 1369 throws StandardException 1370 { 1371 return ( 1372 new BackingStoreHashTableFromScan( 1373 this, 1374 conglomId, 1375 open_mode, 1376 lock_level, 1377 isolation_level, 1378 scanColumnList, 1379 startKeyValue, 1380 startSearchOperator, 1381 qualifier, 1382 stopKeyValue, 1383 stopSearchOperator, 1384 max_rowcnt, 1385 key_column_numbers, 1386 remove_duplicates, 1387 estimated_rowcnt, 1388 max_inmemory_rowcnt, 1389 initialCapacity, 1390 loadFactor, 1391 collect_runtimestats, 1392 skipNullKeyColumns)); 1393 } 1394 1395 1396 public GroupFetchScanController openGroupFetchScan( 1397 long conglomId, 1398 boolean hold, 1399 int open_mode, 1400 int lock_level, 1401 int isolation_level, 1402 FormatableBitSet scanColumnList, 1403 DataValueDescriptor[] startKeyValue, 1404 int startSearchOperator, 1405 Qualifier qualifier[][], 1406 DataValueDescriptor[] stopKeyValue, 1407 int stopSearchOperator) 1408 throws StandardException 1409 { 1410 if (SanityManager.DEBUG) 1411 { 1412 if ((open_mode & 1413 ~(TransactionController.OPENMODE_FORUPDATE | 1414 TransactionController.OPENMODE_FOR_LOCK_ONLY | 1415 TransactionController.OPENMODE_SECONDARY_LOCKED)) != 0) 1416 SanityManager.THROWASSERT( 1417 "Bad open mode to openScan:" + 1418 Integer.toHexString(open_mode)); 1419 1420 if (!(lock_level == MODE_RECORD | 1421 lock_level == MODE_TABLE)) 1422 SanityManager.THROWASSERT( 1423 "Bad lock level to openScan:" + lock_level); 1424 } 1425 1426 Conglomerate conglom = findExistingConglomerate(conglomId); 1428 1429 ScanManager sm = 1431 conglom.openScan( 1432 this, rawtran, hold, open_mode, 1433 determine_lock_level(lock_level), 1434 determine_locking_policy(lock_level, isolation_level), 1435 isolation_level, 1436 scanColumnList, 1437 startKeyValue, startSearchOperator, 1438 qualifier, 1439 stopKeyValue, stopSearchOperator, 1440 (StaticCompiledOpenConglomInfo) null, 1441 (DynamicCompiledOpenConglomInfo) null); 1442 1443 scanControllers.addElement(sm); 1445 1446 return(sm); 1447 } 1448 1449 1450 1451 1462 public void purgeConglomerate( 1463 long conglomId) 1464 throws StandardException 1465 { 1466 findExistingConglomerate(conglomId).purgeConglomerate( 1467 this, 1468 rawtran); 1469 1470 return; 1471 } 1472 1473 1485 public void compressConglomerate( 1486 long conglomId) 1487 throws StandardException 1488 { 1489 findExistingConglomerate(conglomId).compressConglomerate( 1490 this, 1491 rawtran); 1492 1493 return; 1494 } 1495 1496 1532 public GroupFetchScanController defragmentConglomerate( 1533 long conglomId, 1534 boolean online, 1535 boolean hold, 1536 int open_mode, 1537 int lock_level, 1538 int isolation_level) 1539 throws StandardException 1540 { 1541 if (SanityManager.DEBUG) 1542 { 1543 if ((open_mode & 1544 ~(TransactionController.OPENMODE_FORUPDATE | 1545 TransactionController.OPENMODE_FOR_LOCK_ONLY | 1546 TransactionController.OPENMODE_SECONDARY_LOCKED)) != 0) 1547 SanityManager.THROWASSERT( 1548 "Bad open mode to openScan:" + 1549 Integer.toHexString(open_mode)); 1550 1551 if (!(lock_level == MODE_RECORD | 1552 lock_level == MODE_TABLE)) 1553 SanityManager.THROWASSERT( 1554 "Bad lock level to openScan:" + lock_level); 1555 } 1556 1557 Conglomerate conglom = findExistingConglomerate(conglomId); 1559 1560 ScanManager sm = 1562 conglom.defragmentConglomerate( 1563 this, 1564 rawtran, 1565 hold, 1566 open_mode, 1567 determine_lock_level(lock_level), 1568 determine_locking_policy(lock_level, isolation_level), 1569 isolation_level); 1570 1571 scanControllers.addElement(sm); 1573 1574 return(sm); 1575 } 1576 1577 1578 public ScanController openScan( 1579 long conglomId, 1580 boolean hold, 1581 int open_mode, 1582 int lock_level, 1583 int isolation_level, 1584 FormatableBitSet scanColumnList, 1585 DataValueDescriptor[] startKeyValue, 1586 int startSearchOperator, 1587 Qualifier qualifier[][], 1588 DataValueDescriptor[] stopKeyValue, 1589 int stopSearchOperator) 1590 throws StandardException 1591 { 1592 return( 1593 openScan( 1594 findExistingConglomerate(conglomId), 1595 hold, 1596 open_mode, 1597 lock_level, 1598 isolation_level, 1599 scanColumnList, 1600 startKeyValue, 1601 startSearchOperator, 1602 qualifier, 1603 stopKeyValue, 1604 stopSearchOperator, 1605 (StaticCompiledOpenConglomInfo) null, 1606 (DynamicCompiledOpenConglomInfo) null)); 1607 } 1608 1609 public ScanController openCompiledScan( 1610 boolean hold, 1611 int open_mode, 1612 int lock_level, 1613 int isolation_level, 1614 FormatableBitSet scanColumnList, 1615 DataValueDescriptor[] startKeyValue, 1616 int startSearchOperator, 1617 Qualifier qualifier[][], 1618 DataValueDescriptor[] stopKeyValue, 1619 int stopSearchOperator, 1620 StaticCompiledOpenConglomInfo static_info, 1621 DynamicCompiledOpenConglomInfo dynamic_info) 1622 throws StandardException 1623 { 1624 1627 if (SanityManager.DEBUG) 1628 { 1629 SanityManager.ASSERT(static_info != null); 1630 SanityManager.ASSERT(dynamic_info != null); 1631 SanityManager.ASSERT( 1632 static_info instanceof StaticCompiledOpenConglomInfo); 1633 SanityManager.ASSERT( 1634 dynamic_info instanceof DynamicCompiledOpenConglomInfo); 1635 } 1636 1637 return( 1638 openScan( 1639 ((Conglomerate) static_info.getConglom()), 1640 hold, 1641 open_mode, 1642 lock_level, 1643 isolation_level, 1644 scanColumnList, 1645 startKeyValue, 1646 startSearchOperator, 1647 qualifier, 1648 stopKeyValue, 1649 stopSearchOperator, 1650 static_info, 1651 dynamic_info)); 1652 } 1653 1654 1655 1671 public StoreCostController openStoreCost( 1672 long conglomId) 1673 throws StandardException 1674 { 1675 Conglomerate conglom = findExistingConglomerate(conglomId); 1677 1678 StoreCostController scc = conglom.openStoreCost(this, rawtran); 1680 1681 return(scc); 1682 } 1683 1684 1688 public long createSort( 1689 Properties implParameters, 1690 DataValueDescriptor[] template, 1691 ColumnOrdering columnOrdering[], 1692 SortObserver sortObserver, 1693 boolean alreadyInOrder, 1694 long estimatedRows, 1695 int estimatedRowSize) 1696 throws StandardException 1697 { 1698 String implementation = null; 1701 if (implParameters != null) 1702 implementation = 1703 implParameters.getProperty(AccessFactoryGlobals.IMPL_TYPE); 1704 1705 if (implementation == null) 1706 implementation = AccessFactoryGlobals.SORT_EXTERNAL; 1707 1708 MethodFactory mfactory; 1710 mfactory = accessmanager.findMethodFactoryByImpl(implementation); 1711 if (mfactory == null || !(mfactory instanceof SortFactory)) 1712 { 1713 throw( 1714 StandardException.newException( 1715 SQLState.AM_NO_FACTORY_FOR_IMPLEMENTATION, implementation)); 1716 } 1717 SortFactory sfactory = (SortFactory) mfactory; 1718 1719 int segment = 0; 1722 Sort sort = sfactory.createSort(this, segment, 1724 implParameters, template, columnOrdering, 1725 sortObserver, alreadyInOrder, estimatedRows, 1726 estimatedRowSize); 1727 1728 if (sorts == null) { 1730 sorts = new Vector (); 1731 freeSortIds = new ArrayList (); 1732 } 1733 1734 int sortid; 1735 if (freeSortIds.isEmpty()) { 1736 sortid = sorts.size(); 1738 sorts.addElement(sort); 1739 } else { 1740 sortid = ((Integer ) freeSortIds.remove(freeSortIds.size() - 1)) 1742 .intValue(); 1743 sorts.setElementAt(sort, sortid); 1744 } 1745 1746 return sortid; 1747 } 1748 1749 1762 public void dropSort(long sortid) 1763 throws StandardException 1764 { 1765 Sort sort = (Sort) sorts.elementAt((int) sortid); 1767 1768 if (sort != null) 1769 { 1770 sort.drop(this); 1771 sorts.setElementAt(null, (int) sortid); 1772 freeSortIds.add(ReuseFactory.getInteger((int) sortid)); 1773 } 1774 } 1775 1776 1780 public Serializable getProperty( 1781 String key) 1782 throws StandardException 1783 { 1784 return 1785 (accessmanager.getTransactionalProperties().getProperty(this, key)); 1786 } 1787 1788 1792 public Serializable getPropertyDefault( 1793 String key) 1794 throws StandardException 1795 { 1796 return 1797 (accessmanager.getTransactionalProperties().getPropertyDefault(this, key)); 1798 } 1799 1800 1804 public void setProperty( 1805 String key, 1806 Serializable value, 1807 boolean dbOnlyProperty) 1808 throws StandardException 1809 { 1810 accessmanager.getTransactionalProperties().setProperty( 1811 this, key, value, dbOnlyProperty); 1812 } 1813 1814 1818 public void setPropertyDefault( 1819 String key, 1820 Serializable value) 1821 throws StandardException 1822 { 1823 accessmanager.getTransactionalProperties().setPropertyDefault( 1824 this, key, value); 1825 } 1826 1827 1831 public boolean propertyDefaultIsVisible(String key) throws StandardException 1832 { 1833 return accessmanager.getTransactionalProperties().propertyDefaultIsVisible(this,key); 1834 } 1835 1836 1840 public Properties getProperties() 1841 throws StandardException 1842 { 1843 return accessmanager.getTransactionalProperties().getProperties(this); 1844 } 1845 1846 1850 public SortController openSort(long id) 1851 throws StandardException 1852 { 1853 Sort sort; 1854 1855 if (sorts == null || id >= sorts.size() 1858 || (sort = ((Sort) sorts.elementAt((int) id))) == null) 1859 { 1860 throw StandardException.newException( 1861 SQLState.AM_NO_SUCH_SORT, new Long (id)); 1862 } 1863 1864 SortController sc = sort.open(this); 1866 1867 if (sortControllers == null) 1869 sortControllers = new Vector (); 1870 sortControllers.addElement(sc); 1871 1872 return sc; 1873 } 1874 1875 1888 public SortCostController openSortCostController( 1889 Properties implParameters) 1890 throws StandardException 1891 { 1892 String implementation = null; 1895 1896 if (implementation == null) 1897 implementation = AccessFactoryGlobals.SORT_EXTERNAL; 1898 1899 MethodFactory mfactory; 1901 mfactory = accessmanager.findMethodFactoryByImpl(implementation); 1902 if (mfactory == null || !(mfactory instanceof SortFactory)) 1903 { 1904 throw( 1905 StandardException.newException( 1906 SQLState.AM_NO_FACTORY_FOR_IMPLEMENTATION, implementation)); 1907 } 1908 SortFactory sfactory = (SortFactory) mfactory; 1909 1910 return(sfactory.openSortCostController()); 1912 } 1913 1914 1918 public ScanController openSortScan( 1919 long id, 1920 boolean hold) 1921 throws StandardException 1922 { 1923 Sort sort; 1924 1925 if (sorts == null || id >= sorts.size() 1928 || (sort = ((Sort) sorts.elementAt((int) id))) == null) 1929 { 1930 throw StandardException.newException( 1931 SQLState.AM_NO_SUCH_SORT, new Long (id)); 1932 } 1933 1934 ScanController sc = sort.openSortScan(this, hold); 1936 1937 scanControllers.addElement(sc); 1939 1940 return sc; 1941 } 1942 1943 1947 public RowLocationRetRowSource openSortRowSource(long id) 1948 throws StandardException 1949 { 1950 Sort sort; 1951 1952 if (sorts == null || id >= sorts.size() 1955 || (sort = ((Sort) sorts.elementAt((int) id))) == null) 1956 { 1957 throw StandardException.newException( 1958 SQLState.AM_NO_SUCH_SORT, new Long (id)); 1959 } 1960 1961 ScanControllerRowSource sc = sort.openSortRowSource(this); 1963 1964 scanControllers.addElement(sc); 1966 1967 return sc; 1968 } 1969 1970 1971 public void commit() 1972 throws StandardException 1973 { 1974 this.closeControllers(false ); 1975 1976 rawtran.commit(); 1977 1978 alterTableCallMade = false; 1979 1980 return; 1981 } 1982 1983 public DatabaseInstant commitNoSync(int commitflag) 1984 throws StandardException 1985 { 1986 this.closeControllers(false ); 1987 return rawtran.commitNoSync(commitflag); 1988 } 1989 1990 public void abort() 1991 throws StandardException 1992 { 1993 1994 if (alterTableCallMade) 1995 { 1996 accessmanager.conglomCacheInvalidate(); 1997 alterTableCallMade = false; 1998 } 1999 this.closeControllers(true ); 2000 rawtran.abort(); 2001 2002 if (parent_tran != null) 2003 parent_tran.abort(); 2004 } 2005 2006 2012 public ContextManager getContextManager() 2013 { 2014 return(context.getContextManager()); 2015 } 2016 2017 public int setSavePoint(String name, Object kindOfSavepoint) 2018 throws StandardException 2019 { 2020 return rawtran.setSavePoint(name, kindOfSavepoint); 2021 } 2022 2023 public int releaseSavePoint(String name, Object kindOfSavepoint) 2024 throws StandardException 2025 { 2026 return rawtran.releaseSavePoint(name, kindOfSavepoint); 2027 } 2028 2029 public int rollbackToSavePoint(String name, boolean close_controllers, Object kindOfSavepoint) 2030 throws StandardException 2031 { 2032 if (close_controllers) 2033 this.closeControllers(true ); 2034 return rawtran.rollbackToSavePoint(name, kindOfSavepoint); 2035 } 2036 2037 public void destroy() 2038 { 2039 try 2040 { 2041 this.closeControllers(true ); 2042 2043 if (rawtran != null) { 2045 rawtran.destroy(); 2046 rawtran = null; 2047 } 2048 2049 2050 if (context != null) 2052 context.popMe(); 2053 context = null; 2054 2055 accessmanager = null; 2056 tempCongloms = null; 2057 } 2058 catch (StandardException e) 2059 { 2060 rawtran = null; 2063 context = null; 2064 accessmanager = null; 2065 tempCongloms = null; 2066 } 2067 } 2068 2069 public boolean anyoneBlocked() 2070 { 2071 return rawtran.anyoneBlocked(); 2072 } 2073 2074 2078 2079 2091 public void xa_commit( 2092 boolean onePhase) 2093 throws StandardException 2094 { 2095 rawtran.xa_commit(onePhase); 2096 } 2097 2098 2112 public int xa_prepare() 2113 throws StandardException 2114 { 2115 return(rawtran.xa_prepare()); 2116 } 2117 2118 2127 public void xa_rollback() 2128 throws StandardException 2129 { 2130 rawtran.xa_rollback(); 2131 } 2132 2133 2137 2138 2151 public void addPostCommitWork(Serviceable work) 2152 { 2153 rawtran.addPostCommitWork(work); 2154 2155 return; 2156 } 2157 2158 2168 public void closeMe(ConglomerateController conglom_control) 2169 { 2170 conglomerateControllers.removeElement(conglom_control); 2171 } 2172 2173 2181 public void closeMe(SortController sort_control) 2182 { 2183 sortControllers.removeElement(sort_control); 2184 } 2185 2186 2194 public void closeMe(ScanManager scan) 2195 { 2196 scanControllers.removeElement(scan); 2197 } 2198 2199 2206 public AccessFactory getAccessManager() 2207 { 2208 return(accessmanager); 2209 } 2210 2211 2234 public TransactionManager getInternalTransaction() 2235 throws StandardException 2236 { 2237 ContextManager cm = getContextManager(); 2239 2240 2242 2247 Transaction rawtran = 2248 accessmanager.getRawStore().startInternalTransaction(cm); 2249 RAMTransaction rt = new RAMTransaction(accessmanager, rawtran, null); 2250 RAMTransactionContext rtc = 2251 new RAMTransactionContext( 2252 cm, AccessFactoryGlobals.RAMXACT_INTERNAL_CONTEXT_ID, 2253 rt, true ); 2254 2255 rawtran.setDefaultLockingPolicy( 2256 accessmanager.getDefaultLockingPolicy()); 2257 2258 return(rt); 2259 } 2260 2261 2299 public TransactionController startNestedUserTransaction(boolean readOnly) 2300 throws StandardException 2301 { 2302 ContextManager cm = getContextManager(); 2304 2305 2307 2316 2317 Transaction child_rawtran = 2318 ((readOnly) ? 2319 accessmanager.getRawStore().startNestedReadOnlyUserTransaction( 2320 this.getLockObject(), cm, 2321 AccessFactoryGlobals.NESTED_READONLY_USER_TRANS) : 2322 accessmanager.getRawStore().startNestedUpdateUserTransaction( 2323 cm, AccessFactoryGlobals.NESTED_UPDATE_USER_TRANS)); 2324 2325 RAMTransaction rt = 2326 new RAMTransaction(accessmanager, child_rawtran, this); 2327 2328 RAMTransactionContext rtc = 2329 new RAMTransactionContext( 2330 cm, 2331 AccessFactoryGlobals.RAMXACT_CHILD_CONTEXT_ID, 2332 rt, true ); 2333 2334 child_rawtran.setDefaultLockingPolicy( 2335 accessmanager.getDefaultLockingPolicy()); 2336 2337 2341 2342 return(rt); 2343 } 2344 2345 2354 public Transaction getRawStoreXact() 2355 { 2356 return(rawtran); 2357 } 2358 2359 2360 2375 public void saveScanPositions(Conglomerate conglom, Page page) 2376 throws StandardException 2377 { 2378 Enumeration e = scanControllers.elements(); 2379 while (e.hasMoreElements()) 2380 { 2381 Object o = e.nextElement(); 2382 2383 if (SanityManager.DEBUG) 2384 { 2385 2389 if (!(o instanceof ScanManager)) 2390 { 2391 HeaderPrintWriter istream = Monitor.getStream(); 2392 2393 if (o == null) 2394 istream.println("next element was null\n"); 2395 else 2396 istream.println("non ScanManager on list: " + o); 2397 2398 istream.println( 2399 "Current list of open scans: " + debugOpened()); 2400 } 2401 } 2402 ScanManager sm = (ScanManager) o; 2403 sm.savePosition(conglom, page); 2404 } 2405 } 2406 2407 public FileResource getFileHandler() { 2408 return rawtran.getFileHandler(); 2409 } 2410 2411 2416 public Object getLockObject() 2417 { 2418 return rawtran.getCompatibilitySpace(); 2419 } 2420 2421 2437 public String getTransactionIdString() 2438 { 2439 return(rawtran.toString()); 2440 } 2441 2442 2443 2447 public String getActiveStateTxIdString() 2448 { 2449 return(rawtran.getActiveStateTxIdString()); 2450 } 2451 2452 2453 public String toString() 2454 { 2455 String str = null; 2456 2457 if (SanityManager.DEBUG) 2458 { 2459 str = "rawtran = " + rawtran; 2460 } 2461 return(str); 2462 } 2463} 2464 | Popular Tags |