1 21 22 package org.apache.derby.impl.sql.depend; 23 24 import org.apache.derby.catalog.Dependable; 25 import org.apache.derby.catalog.DependableFinder; 26 27 import org.apache.derby.iapi.services.context.ContextManager; 28 import org.apache.derby.iapi.services.context.ContextService; 29 30 import org.apache.derby.iapi.services.monitor.Monitor; 31 32 import org.apache.derby.iapi.services.sanity.SanityManager; 33 34 import org.apache.derby.iapi.sql.compile.CompilerContext; 35 import org.apache.derby.iapi.sql.compile.Parser; 36 import org.apache.derby.impl.sql.compile.CreateViewNode; 37 38 import org.apache.derby.iapi.sql.conn.LanguageConnectionContext; 39 import org.apache.derby.iapi.sql.conn.LanguageConnectionFactory; 40 import org.apache.derby.iapi.sql.conn.StatementContext; 41 42 import org.apache.derby.iapi.sql.depend.DependencyManager; 43 import org.apache.derby.iapi.sql.depend.Dependency; 44 import org.apache.derby.iapi.sql.depend.Dependent; 45 import org.apache.derby.iapi.sql.depend.Provider; 46 import org.apache.derby.iapi.sql.depend.ProviderInfo; 47 import org.apache.derby.iapi.sql.depend.ProviderList; 48 49 import org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator; 50 import org.apache.derby.iapi.sql.dictionary.DataDictionary; 51 import org.apache.derby.iapi.sql.dictionary.DataDictionaryContext; 52 import org.apache.derby.iapi.sql.dictionary.DependencyDescriptor; 53 import org.apache.derby.iapi.sql.dictionary.TableDescriptor; 54 import org.apache.derby.iapi.sql.dictionary.ViewDescriptor; 55 import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor; 56 57 import org.apache.derby.impl.sql.catalog.DDColumnDependableFinder; 58 import org.apache.derby.iapi.store.access.TransactionController; 59 60 import org.apache.derby.catalog.UUID; 61 import org.apache.derby.iapi.reference.SQLState; 62 import org.apache.derby.iapi.services.io.FormatableBitSet; 63 64 import org.apache.derby.iapi.reference.MessageId; 65 66 import org.apache.derby.iapi.error.StandardException; 67 68 import java.util.Hashtable ; 69 import java.util.Enumeration ; 70 import java.util.ListIterator ; 71 import java.util.List ; 72 73 76 77 public class BasicDependencyManager implements DependencyManager { 78 79 83 97 public void addDependency(Dependent d, Provider p, ContextManager cm) 98 throws StandardException { 99 addDependency(d, p, cm, null); 100 } 101 102 private void addDependency(Dependent d, Provider p, ContextManager cm, 103 TransactionController tc) throws StandardException { 104 105 synchronized(this) 106 { 107 Dependency dy = new BasicDependency(d, p); 108 109 110 if (! d.isPersistent() || ! p.isPersistent()) 111 { 112 117 boolean addedToDeps = false; 118 boolean addedToProvs = false; 119 120 addedToDeps = addDependencyToTable(dependents, d.getObjectID(), dy); 121 if (addedToDeps) 122 { 123 addedToProvs = addDependencyToTable(providers, p.getObjectID(), dy); 124 } 125 else if (SanityManager.DEBUG) 126 { 127 addedToProvs = addDependencyToTable(providers, p.getObjectID(), dy); 128 } 129 130 131 if (SanityManager.DEBUG) 132 { 133 if (addedToDeps != addedToProvs) 134 { 135 SanityManager.THROWASSERT( 136 "addedToDeps (" + addedToDeps + 137 ") and addedToProvs (" + 138 addedToProvs + ") are expected to agree"); 139 } 140 } 141 142 145 StatementContext sc = (StatementContext) cm.getContext(org.apache.derby.iapi.reference.ContextId.LANG_STATEMENT); 146 sc.addDependency(dy); 147 } 148 else 149 { 150 151 LanguageConnectionContext lcc = getLanguageConnectionContext(cm); 152 DataDictionary dd = getDataDictionary(); 153 DependencyDescriptor dependencyDescriptor; 154 boolean wait = (tc == null); 155 156 dependencyDescriptor = new DependencyDescriptor(d, p); 157 158 159 dd.addDescriptor(dependencyDescriptor, null, 160 DataDictionary.SYSDEPENDS_CATALOG_NUM, true, 161 ((wait)?lcc.getTransactionExecute():tc), wait); 162 } 163 } 164 } 165 166 174 private void dropDependency(LanguageConnectionContext lcc, Dependent d, Provider p) throws StandardException 175 { 176 if (SanityManager.DEBUG) { 177 if (! d.isPersistent() || ! p.isPersistent()) 179 { 180 SanityManager.NOTREACHED(); 181 } 182 } 183 184 DataDictionary dd = getDataDictionary(); 185 186 DependencyDescriptor dependencyDescriptor = new DependencyDescriptor(d, p); 187 188 dd.dropStoredDependency( dependencyDescriptor, 189 lcc.getTransactionExecute() ); 190 } 191 192 193 215 public void invalidateFor(Provider p, int action, 216 LanguageConnectionContext lcc) 217 throws StandardException 218 { 219 231 if (p.isPersistent()) 232 coreInvalidateFor(p, action, lcc); 233 else { 234 synchronized (this) { 235 coreInvalidateFor(p, action, lcc); 236 } 237 } 238 } 239 240 252 private void coreInvalidateFor(Provider p, int action, LanguageConnectionContext lcc) 253 throws StandardException 254 { 255 List list = getDependents(p); 256 if (list == null) 257 { 258 return; 259 } 260 261 262 274 FormatableBitSet affectedCols = null, subsetCols = null; 275 if (p instanceof TableDescriptor) 276 { 277 affectedCols = ((TableDescriptor) p).getReferencedColumnMap(); 278 if (affectedCols != null) 279 subsetCols = new FormatableBitSet(affectedCols.getLength()); 280 } 281 282 { 283 StandardException noInvalidate = null; 284 for (int ei = list.size() - 1; ei >= 0; ei--) 287 { 288 if (ei >= list.size()) 289 continue; 290 Dependency dependency = (Dependency) list.get(ei); 291 292 Dependent dep = dependency.getDependent(); 293 294 if (affectedCols != null) 295 { 296 TableDescriptor td = (TableDescriptor) dependency.getProvider(); 297 FormatableBitSet providingCols = td.getReferencedColumnMap(); 298 if (providingCols == null) 299 { 300 if (dep instanceof ViewDescriptor) 301 { 302 ViewDescriptor vd = (ViewDescriptor) dep; 303 DataDictionary dd = getDataDictionary(); 304 SchemaDescriptor compSchema; 305 compSchema = dd.getSchemaDescriptor(vd.getCompSchemaId(), null); 306 CompilerContext newCC = lcc.pushCompilerContext(compSchema); 307 Parser pa = newCC.getParser(); 308 LanguageConnectionFactory lcf = lcc.getLanguageConnectionFactory(); 309 310 CreateViewNode cvn = (CreateViewNode)pa.parseStatement( 313 vd.getViewText()); 314 315 newCC.setCurrentDependent(dep); 317 cvn = (CreateViewNode) cvn.bind(); 318 ProviderInfo[] providerInfos = cvn.getProviderInfo(); 319 lcc.popCompilerContext(newCC); 320 321 boolean interferent = false; 322 for (int i = 0; i < providerInfos.length; i++) 323 { 324 Provider provider = null; 325 try 326 { 327 provider = (Provider) providerInfos[i]. 328 getDependableFinder(). 329 getDependable( 330 providerInfos[i].getObjectId()); 331 } 332 catch(java.sql.SQLException te) 333 { 334 if (SanityManager.DEBUG) 335 { 336 SanityManager.THROWASSERT("unexpected java.sql.SQLException - " + te); 337 } 338 } 339 if (provider instanceof TableDescriptor) 340 { 341 TableDescriptor tab = (TableDescriptor)provider; 342 FormatableBitSet colMap = tab.getReferencedColumnMap(); 343 if (colMap == null) 344 continue; 345 tab.setReferencedColumnMap(null); 349 dropDependency(lcc, vd, tab); 350 tab.setReferencedColumnMap(colMap); 351 addDependency(vd, tab, lcc.getContextManager()); 352 353 if (tab.getObjectID().equals(td.getObjectID())) 354 { 355 System.arraycopy(affectedCols.getByteArray(), 0, 356 subsetCols.getByteArray(), 0, 357 affectedCols.getLengthInBytes()); 358 subsetCols.and(colMap); 359 if (subsetCols.anySetBit() != -1) 360 { 361 interferent = true; 362 ((TableDescriptor) p).setReferencedColumnMap(subsetCols); 363 } 364 } 365 } } if (! interferent) 368 continue; 369 } else 371 ((TableDescriptor) p).setReferencedColumnMap(null); 372 } else 374 { 375 System.arraycopy(affectedCols.getByteArray(), 0, subsetCols.getByteArray(), 0, affectedCols.getLengthInBytes()); 376 subsetCols.and(providingCols); 377 if (subsetCols.anySetBit() == -1) 378 continue; 379 ((TableDescriptor) p).setReferencedColumnMap(subsetCols); 380 } 381 } 382 383 try { 385 dep.prepareToInvalidate(p, action, lcc); 386 } catch (StandardException sqle) { 387 388 if (noInvalidate != null) 389 sqle.setNestedException(noInvalidate); 390 391 noInvalidate = sqle; 392 } 393 if (noInvalidate == null) { 394 395 if (affectedCols != null) 396 ((TableDescriptor) p).setReferencedColumnMap(affectedCols); 397 398 dep.makeInvalid(action, lcc); 401 } 402 } 403 404 if (noInvalidate != null) 405 throw noInvalidate; 406 } 407 } 408 409 431 public void clearDependencies(LanguageConnectionContext lcc, Dependent d) throws StandardException { 432 clearDependencies(lcc, d, null); 433 } 434 435 438 public void clearDependencies(LanguageConnectionContext lcc, 439 Dependent d, TransactionController tc) throws StandardException { 440 List deps = (List) dependents.get(d.getObjectID()); 441 442 synchronized(this) 443 { 444 445 if (d.isPersistent()) 446 { 447 DataDictionary dd = getDataDictionary(); 448 boolean wait = (tc == null); 449 450 dd.dropDependentsStoredDependencies(d.getObjectID(), 451 ((wait)?lcc.getTransactionExecute():tc), 452 wait); 453 } 454 455 456 457 if (deps == null) return; 459 for (ListIterator depsIterator = deps.listIterator(); 462 depsIterator.hasNext(); ) { 463 464 Dependency dy = (Dependency)depsIterator.next(); 465 clearProviderDependency(dy.getProviderKey(), dy); 466 } 467 468 dependents.remove(d.getObjectID()); 469 } 470 } 471 472 478 public void clearInMemoryDependency(Dependency dy) 479 { 480 synchronized(this) 481 { 482 List deps = 483 (List) dependents.get(dy.getDependent().getObjectID()); 484 485 if (!SanityManager.DEBUG) { 488 if (deps == null) 490 return; 491 } 492 493 List provs = 494 (List) providers.get(dy.getProvider().getObjectID()); 495 496 if (SanityManager.DEBUG) 497 { 498 if ((deps != null) || (provs != null)) { 500 501 507 int depCount = 0; 509 if (deps != null) { 510 for (int ci = 0; ci < deps.size(); ci++) { 511 if (dy.equals(deps.get(ci))) 512 depCount++; 513 } 514 } 515 516 int provCount = 0; 517 if (provs != null) { 518 for (int ci = 0; ci < provs.size(); ci++) { 519 if (dy.equals(provs.get(ci))) 520 provCount++; 521 } 522 } 523 524 if (depCount != provCount) { 525 SanityManager.THROWASSERT("Dependency count mismatch count in deps: " + depCount + 526 ", count in provs " + provCount + 527 ", dy.getDependent().getObjectID() = " + dy.getDependent().getObjectID() + 528 ", dy.getProvider().getObjectID() = " + dy.getProvider().getObjectID()); 529 } 530 } 531 532 if (deps == null) 535 return; 536 } 537 538 if (provs == null) 540 return; 541 542 543 deps.remove(dy); 544 if (deps.size() == 0) 545 dependents.remove(dy.getDependent().getObjectID()); 546 provs.remove(dy); 547 if (provs.size() == 0) 548 providers.remove(dy.getProvider().getObjectID()); 549 } 550 } 551 552 553 558 568 573 604 605 610 public synchronized ProviderInfo[] getPersistentProviderInfos(Dependent dependent) 611 throws StandardException 612 { 613 List list = getProviders(dependent); 614 if (list == null) 615 { 616 return EMPTY_PROVIDER_INFO; 617 } 618 619 java.util.ArrayList pih = new java.util.ArrayList (); 620 621 for (ListIterator depsIterator = list.listIterator(); 622 depsIterator.hasNext(); ) 623 { 624 Dependency dep = (Dependency) depsIterator.next(); 625 626 if (dep.getProvider().isPersistent()) 627 { 628 pih.add(new BasicProviderInfo( 629 dep.getProvider().getObjectID(), 630 dep.getProvider().getDependableFinder(), 631 dep.getProvider().getObjectName() 632 )); 633 } 634 } 635 636 637 return (ProviderInfo[]) pih.toArray(EMPTY_PROVIDER_INFO); 638 } 639 640 private static final ProviderInfo[] EMPTY_PROVIDER_INFO = new ProviderInfo[0]; 641 642 647 public ProviderInfo[] getPersistentProviderInfos(ProviderList pl) 648 throws StandardException 649 { 650 Enumeration e = pl.elements(); 651 int numProviders = 0; 652 ProviderInfo[] retval; 653 654 658 while (e != null && e.hasMoreElements()) 659 { 660 Provider prov = (Provider) e.nextElement(); 661 662 if (prov.isPersistent()) 663 { 664 numProviders++; 665 } 666 } 667 668 e = pl.elements(); 669 retval = new ProviderInfo[numProviders]; 670 int piCtr = 0; 671 while (e != null && e.hasMoreElements()) 672 { 673 Provider prov = (Provider) e.nextElement(); 674 675 if (prov.isPersistent()) 676 { 677 retval[piCtr++] = new BasicProviderInfo( 678 prov.getObjectID(), 679 prov.getDependableFinder(), 680 prov.getObjectName() 681 ); 682 } 683 } 684 685 return retval; 686 } 687 688 695 public void clearColumnInfoInProviders(ProviderList pl) 696 throws StandardException 697 { 698 Enumeration e = pl.elements(); 699 while (e.hasMoreElements()) 700 { 701 Provider pro = (Provider) e.nextElement(); 702 if (pro instanceof TableDescriptor) 703 ((TableDescriptor) pro).setReferencedColumnMap(null); 704 } 705 } 706 707 717 public void copyDependencies(Dependent copy_From, 718 Dependent copyTo, 719 boolean persistentOnly, 720 ContextManager cm) throws StandardException 721 { 722 copyDependencies(copy_From, copyTo, persistentOnly, cm, null); 723 } 724 725 728 public synchronized void copyDependencies( 729 Dependent copy_From, 730 Dependent copyTo, 731 boolean persistentOnly, 732 ContextManager cm, 733 TransactionController tc) 734 throws StandardException 735 { 736 737 List list = getProviders(copy_From); 738 if (list == null) 739 return; 740 741 for (ListIterator depsIterator = list.listIterator(); depsIterator.hasNext(); ) 742 { 743 Provider provider = ((Dependency) depsIterator.next()).getProvider(); 744 745 if (!persistentOnly || provider.isPersistent()) 746 { 747 this.addDependency(copyTo, provider, cm, tc); 748 } 749 } 750 } 751 752 753 762 public String getActionString(int action) 763 { 764 switch (action) 765 { 766 case ALTER_TABLE: 767 return "ALTER TABLE"; 768 769 case RENAME: return "RENAME"; 771 772 case RENAME_INDEX: 773 return "RENAME INDEX"; 774 775 case COMPILE_FAILED: 776 return "COMPILE FAILED"; 777 778 case DROP_TABLE: 779 return "DROP TABLE"; 780 781 case DROP_INDEX: 782 return "DROP INDEX"; 783 784 case DROP_VIEW: 785 return "DROP VIEW"; 786 787 case CREATE_INDEX: 788 return "CREATE INDEX"; 789 790 case ROLLBACK: 791 return "ROLLBACK"; 792 793 case CHANGED_CURSOR: 794 return "CHANGED CURSOR"; 795 796 case CREATE_CONSTRAINT: 797 return "CREATE CONSTRAINT"; 798 799 case DROP_CONSTRAINT: 800 return "DROP CONSTRAINT"; 801 802 case DROP_METHOD_ALIAS: 803 return "DROP ROUTINE"; 804 805 case PREPARED_STATEMENT_RELEASE: 806 return "PREPARED STATEMENT RELEASE"; 807 808 case DROP_SPS: 809 return "DROP STORED PREPARED STATEMENT"; 810 811 case USER_RECOMPILE_REQUEST: 812 return "USER REQUESTED INVALIDATION"; 813 814 case BULK_INSERT: 815 return "BULK INSERT"; 816 817 case CREATE_VIEW: 818 return "CREATE_VIEW"; 819 820 case DROP_JAR: 821 return "DROP_JAR"; 822 823 case REPLACE_JAR: 824 return "REPLACE_JAR"; 825 826 case SET_CONSTRAINTS_ENABLE: 827 return "SET_CONSTRAINTS_ENABLE"; 828 829 case SET_CONSTRAINTS_DISABLE: 830 return "SET_CONSTRAINTS_DISABLE"; 831 832 case INTERNAL_RECOMPILE_REQUEST: 833 return "INTERNAL RECOMPILE REQUEST"; 834 835 case CREATE_TRIGGER: 836 return "CREATE TRIGGER"; 837 838 case DROP_TRIGGER: 839 return "DROP TRIGGER"; 840 841 case SET_TRIGGERS_ENABLE: 842 return "SET TRIGGERS ENABLED"; 843 844 case SET_TRIGGERS_DISABLE: 845 return "SET TRIGGERS DISABLED"; 846 847 case MODIFY_COLUMN_DEFAULT: 848 return "MODIFY COLUMN DEFAULT"; 849 850 case COMPRESS_TABLE: 851 return "COMPRESS TABLE"; 852 853 case DROP_COLUMN: 854 return "DROP COLUMN"; 855 856 case DROP_STATISTICS: 857 return "DROP STATISTICS"; 858 859 case UPDATE_STATISTICS: 860 return "UPDATE STATISTICS"; 861 862 case TRUNCATE_TABLE: 863 return "TRUNCATE TABLE"; 864 865 case DROP_SYNONYM: 866 return "DROP SYNONYM"; 867 868 case REVOKE_PRIVILEGE: 869 return "REVOKE PRIVILEGE"; 870 871 case REVOKE_PRIVILEGE_RESTRICT: 872 return "REVOKE PRIVILEGE RESTRICT"; 873 874 default: 875 if (SanityManager.DEBUG) 876 { 877 SanityManager.THROWASSERT("getActionString() passed an invalid value (" + action + ")"); 878 } 879 return "UNKNOWN"; 882 } 883 } 884 885 893 public int countDependencies() 894 throws StandardException 895 { 896 synchronized(this) 897 { 898 int numDependencies = 0; 899 Enumeration deps = dependents.elements(); 900 Enumeration provs = providers.elements(); 901 List storedDeps = getDataDictionary(). 902 getAllDependencyDescriptorsList(); 903 904 905 while (deps.hasMoreElements()) 906 { 907 numDependencies += ((List) deps.nextElement()).size(); 908 } 909 910 while (provs.hasMoreElements()) 911 { 912 numDependencies += ((List) provs.nextElement()).size(); 913 } 914 915 916 numDependencies += storedDeps.size(); 917 918 return numDependencies; 919 } 920 } 921 922 932 public String dumpDependencies() throws StandardException, java.sql.SQLException 933 { 934 synchronized(this) 935 { 936 boolean foundInMemory = false; 937 boolean foundStored = false; 938 StringBuffer debugBuf = new StringBuffer (); 939 940 if (SanityManager.DEBUG) 941 { 942 Enumeration deps = dependents.keys(); 943 UUID[] depKeys = new UUID[dependents.size()]; 944 945 946 for (int i = 0; deps.hasMoreElements(); i++) 947 { 948 955 depKeys[i] = (UUID) deps.nextElement(); 956 } 957 958 959 bubbleSort(depKeys); 960 961 962 for (int i = 0; i < depKeys.length; i++) 963 { 964 List depsSList = (List) dependents.get(depKeys[i]); 965 966 for (ListIterator depsIterator = depsSList.listIterator(); 967 depsIterator.hasNext(); ) 968 { 969 Dependency dy = (Dependency)depsIterator.next(); 970 971 if (! foundInMemory) 972 { 973 debugBuf.append("In Memory Dependencies:\n"); 974 foundInMemory = true; 975 } 976 977 debugBuf.append(dy.getDependent().toString() + 978 ", type " + 979 dy.getDependent().getClassType() + 980 ", " + 981 " is dependent on " + 982 dy.getProvider().getObjectName() + 983 ", type " + 984 dy.getProvider().getClassType() + 985 "\n"); 986 } 987 } 988 989 990 Enumeration provs = providers.keys(); 991 UUID[] provKeys = new UUID[providers.size()]; 992 for (int i = 0; provs.hasMoreElements(); i++) 993 { 994 1001 provKeys[i] = (UUID) provs.nextElement(); 1002 } 1003 1004 1005 bubbleSort(provKeys); 1006 1007 1008 for (int i = 0; i < provKeys.length; i++) 1009 { 1010 List depsSList = (List) providers.get(provKeys[i]); 1011 1012 for (ListIterator depsIterator = depsSList.listIterator(); 1013 depsIterator.hasNext(); ) 1014 { 1015 1016 Dependency dy = (Dependency)depsIterator.next(); 1017 1018 if (! foundInMemory) 1019 { 1020 debugBuf.append("In Memory Dependencies:\n"); 1021 foundInMemory = true; 1022 } 1023 1024 debugBuf.append( 1025 dy.getProvider().toString() + 1026 ", type " + 1027 dy.getProvider().getClassType() + 1028 ", provides for " + 1029 dy.getDependent().getObjectName() + 1030 ", type " + 1031 dy.getDependent().getClassType() + 1032 "\n"); 1033 } 1034 } 1035 1039 List storedDeps = 1040 getDataDictionary().getAllDependencyDescriptorsList(); 1041 1042 String [] dependStr = new String [storedDeps.size()]; 1043 1044 int i = 0; 1045 for (ListIterator depsIterator = storedDeps.listIterator(); 1046 depsIterator.hasNext(); ) 1047 { 1048 DependencyDescriptor dd = (DependencyDescriptor)depsIterator.next(); 1049 1050 if (! foundStored) 1051 { 1052 debugBuf.append("Stored Dependencies:\n"); 1053 foundStored = true; 1054 } 1055 1056 dependStr[i++] = new String ( 1057 dd.getProviderFinder().getSQLObjectName( 1058 dd.getProviderID().toString()) + 1059 ", type " + 1060 dd.getProviderFinder().getSQLObjectType() + 1061 ", provides for " + 1062 dd.getDependentFinder().getSQLObjectName( 1063 dd.getUUID().toString()) + 1064 ", type " + 1065 dd.getDependentFinder().getSQLObjectType() + 1066 "\n"); 1067 } 1068 1069 for (i = 0; i < dependStr.length; i++) 1071 { 1072 for (int j = i + 1; j < dependStr.length; j++) 1073 { 1074 if (dependStr[i].compareTo(dependStr[j]) > 0) 1075 { 1076 String save = dependStr[i]; 1077 dependStr[i] = dependStr[j]; 1078 dependStr[j] = save; 1079 } 1080 } 1081 } 1082 1083 for(i=0; i < dependStr.length; i++) 1084 debugBuf.append(dependStr[i]); 1085 1086 1087 } 1088 1089 return debugBuf.toString(); 1090 } 1091 } 1092 1093 public BasicDependencyManager() { 1097 } 1098 1099 1103 1109 private boolean addDependencyToTable(Hashtable table, 1110 Object key, Dependency dy) { 1111 1112 List deps = (List) table.get(key); 1113 if (deps == null) { 1114 deps = newSList(); 1115 deps.add(dy); 1116 table.put(key, deps); 1117 } 1118 else { 1119 1120 UUID provKey = dy.getProvider().getObjectID(); 1121 UUID depKey = dy.getDependent().getObjectID(); 1122 1123 for (ListIterator depsIT = deps.listIterator(); depsIT.hasNext(); ) 1124 { 1125 Dependency curDY = (Dependency)depsIT.next(); 1126 if (curDY.getProvider().getObjectID().equals(provKey) && 1127 curDY.getDependent().getObjectID().equals(depKey)) 1128 { 1129 return false; 1130 } 1131 } 1132 1133 deps.add(dy); 1134 } 1135 1136 if (SanityManager.DEBUG) { 1137 1138 if (SanityManager.DEBUG_ON("memoryLeakTrace")) { 1139 1140 if (table.size() > 100) 1141 System.out.println("memoryLeakTrace:BasicDependencyManager:table " + table.size()); 1142 if (deps.size() > 50) 1143 System.out.println("memoryLeakTrace:BasicDependencyManager:deps " + deps.size()); 1144 } 1145 } 1146 1147 return true; 1148 } 1149 1150 1155 protected void clearProviderDependency(UUID p, Dependency d) { 1156 List deps = (List) providers.get(p); 1157 1158 if (deps == null) 1159 return; 1160 1161 deps.remove(d); 1162 1163 if (deps.size() == 0) 1164 providers.remove(p); 1165 } 1166 1167 1179 private List getDependencyDescriptorList(List storedList, 1180 Provider providerForList) 1181 throws StandardException 1182 { 1183 if (storedList.size() != 0) 1184 { 1185 1192 for (ListIterator depsIterator = storedList.listIterator(); 1193 depsIterator.hasNext(); ) 1194 { 1195 Dependent tempD; 1196 Provider tempP; 1197 DependableFinder finder = null; 1198 1199 DependencyDescriptor depDesc = (DependencyDescriptor) depsIterator.next(); 1200 1201 try { 1202 finder = depDesc.getDependentFinder(); 1203 tempD = (Dependent) finder.getDependable( depDesc.getUUID() ); 1204 1205 if (providerForList != null) 1206 { 1207 tempP = providerForList; 1209 1210 if (SanityManager.DEBUG) { 1212 if (!tempP.getObjectID().equals(depDesc.getProviderID())) 1213 { 1214 SanityManager.THROWASSERT("mismatch providers"); 1215 } 1216 } 1217 } 1218 else 1219 { 1220 finder = depDesc.getProviderFinder(); 1221 tempP = (Provider) finder.getDependable( depDesc.getProviderID() ); 1222 1223 } 1224 1225 } catch (java.sql.SQLException te) { 1226 throw StandardException.newException(SQLState.DEP_UNABLE_TO_RESTORE, finder.getClass().getName(), te.getMessage()); 1227 1228 } 1229 1230 depsIterator.set(new BasicDependency(tempD, tempP)); 1231 } 1232 } 1233 1234 return storedList; 1235 } 1236 1237 1242 private DataDictionary getDataDictionary() 1243 { 1244 if (dataDictionary == null) 1245 { 1246 DataDictionaryContext ddc; 1247 1248 ddc = (DataDictionaryContext) 1249 (ContextService.getContext(DataDictionaryContext.CONTEXT_ID)); 1250 1251 1252 dataDictionary = ddc.getDataDictionary(); 1253 } 1254 1255 return dataDictionary; 1256 } 1257 1258 1263 private LanguageConnectionContext getLanguageConnectionContext() 1264 { 1265 return (LanguageConnectionContext) 1267 ContextService.getContext(LanguageConnectionContext.CONTEXT_ID); 1268 } 1269 1270 1277 private LanguageConnectionContext getLanguageConnectionContext(ContextManager cm) 1278 { 1279 return (LanguageConnectionContext) cm.getContext(LanguageConnectionContext.CONTEXT_ID); 1281 } 1282 1283 1293 private void bubbleSort(UUID[] uuids) 1294 { 1295 if (SanityManager.DEBUG) 1296 { 1297 for (int i = 0; i < uuids.length; i++) 1298 { 1299 for (int j = i + 1; j < uuids.length; j++) 1300 { 1301 if (uuids[i].toString().compareTo(uuids[j].toString()) > 0) 1302 { 1303 UUID save = uuids[i]; 1304 uuids[i] = uuids[j]; 1305 uuids[j] = save; 1306 } 1307 } 1308 } 1309 } 1310 } 1311 1312 1321 private List getProviders (Dependent d) throws StandardException { 1322 1323 List deps = (List) dependents.get(d.getObjectID()); 1324 1325 1329 if (! d.isPersistent()) 1330 { 1331 return (deps == null? null : deps); 1332 } 1333 else 1334 { 1335 if (deps == null) 1336 { 1337 deps = newSList(); 1338 } 1339 else 1340 { 1341 deps = newSList(deps); 1342 } 1343 1344 1347 List storedList = getDependencyDescriptorList( 1348 getDataDictionary(). 1349 getDependentsDescriptorList( 1350 d.getObjectID().toString() 1351 ), 1352 (Provider) null 1353 ); 1354 1355 if (storedList.size() > 0) 1356 { 1357 deps.addAll(0, storedList); 1358 } 1359 1360 return deps; 1361 } 1362 } 1363 1364 1373 private List getDependents (Provider p) 1374 throws StandardException { 1375 1376 List deps = (List) providers.get(p.getObjectID()); 1377 1378 1382 if (! p.isPersistent()) 1383 { 1384 return deps; 1385 } 1386 else 1387 { 1388 if (deps == null) 1389 { 1390 deps = newSList(); 1391 } 1392 else 1393 { 1394 deps = newSList(deps); 1395 } 1396 1397 1400 List storedList = getDependencyDescriptorList( 1401 getDataDictionary(). 1402 getProvidersDescriptorList( 1403 p.getObjectID().toString() 1404 ), 1405 p 1406 ); 1407 if (storedList.size() > 0) 1408 { 1409 deps.addAll(0, storedList); 1410 } 1411 1412 return deps; 1413 } 1414 } 1415 1416 private static List newSList() { 1417 return java.util.Collections.synchronizedList(new java.util.LinkedList ()); 1418 } 1419 private static List newSList(List list) { 1420 return java.util.Collections.synchronizedList(new java.util.LinkedList (list)); 1421 } 1422 1423 private DataDictionary dataDictionary = null; 1424 protected Hashtable dependents = new Hashtable (); 1425 protected Hashtable providers = new Hashtable (); 1426} 1427 | Popular Tags |