📄 basicdependencymanager.java
字号:
** be printed in the same order (we have tests that canonize ** the order of printing the dependencies, and since the key ** is a UUID, the order they are returned from ** hasMoreElements() changes from run to run). */ depKeys[i] = (UUID) deps.nextElement(); } /* Do a bubble sort - there aren't likely to be many elements */ bubbleSort(depKeys); /* Iterate through the sorted keys */ for (int i = 0; i < depKeys.length; i++) { List depsSList = (List) dependents.get(depKeys[i]); for (ListIterator depsIterator = depsSList.listIterator(); depsIterator.hasNext(); ) { Dependency dy = (Dependency)depsIterator.next(); if (! foundInMemory) { debugBuf.append("In Memory Dependencies:\n"); foundInMemory = true; } debugBuf.append(dy.getDependent().toString() + ", type " + dy.getDependent().getClassType() + ", " + " is dependent on " + dy.getProvider().getObjectName() + ", type " + dy.getProvider().getClassType() + "\n"); } } /* Record the in memory dependencies */ Enumeration provs = providers.keys(); UUID[] provKeys = new UUID[providers.size()]; for (int i = 0; provs.hasMoreElements(); i++) { /* ** Get all the keys and sort them, so that they will always ** be printed in the same order (we have tests that canonize ** the order of printing the dependencies, and since the key ** is a UUID, the order they are returned from ** hasMoreElements() changes from run to run). */ provKeys[i] = (UUID) provs.nextElement(); } /* Do a bubble sort - there aren't likely to be many elements */ bubbleSort(provKeys); /* Iterate through the sorted keys */ for (int i = 0; i < provKeys.length; i++) { List depsSList = (List) providers.get(provKeys[i]); for (ListIterator depsIterator = depsSList.listIterator(); depsIterator.hasNext(); ) { Dependency dy = (Dependency)depsIterator.next(); if (! foundInMemory) { debugBuf.append("In Memory Dependencies:\n"); foundInMemory = true; } debugBuf.append( dy.getProvider().toString() + ", type " + dy.getProvider().getClassType() + ", provides for " + dy.getDependent().getObjectName() + ", type " + dy.getDependent().getClassType() + "\n"); } } /* Record the stored dependencies in sorted order to avoid ordering problems in canons. Also the dependencyDescriptor.getUUID() in this list is not unique, hence the sort on the output string values instead */ List storedDeps = getDataDictionary().getAllDependencyDescriptorsList(); String[] dependStr = new String[storedDeps.size()]; int i = 0; for (ListIterator depsIterator = storedDeps.listIterator(); depsIterator.hasNext(); ) { DependencyDescriptor dd = (DependencyDescriptor)depsIterator.next(); if (! foundStored) { debugBuf.append("Stored Dependencies:\n"); foundStored = true; } dependStr[i++] = new String( dd.getProviderFinder().getSQLObjectName( dd.getProviderID().toString()) + ", type " + dd.getProviderFinder().getSQLObjectType() + ", provides for " + dd.getDependentFinder().getSQLObjectName( dd.getUUID().toString()) + ", type " + dd.getDependentFinder().getSQLObjectType() + "\n"); } // sort stored dependencies; dependStr for (i = 0; i < dependStr.length; i++) { for (int j = i + 1; j < dependStr.length; j++) { if (dependStr[i].compareTo(dependStr[j]) > 0) { String save = dependStr[i]; dependStr[i] = dependStr[j]; dependStr[j] = save; } } } for(i=0; i < dependStr.length; i++) debugBuf.append(dependStr[i]); } return debugBuf.toString(); } } // // class interface // public BasicDependencyManager() { } // // class implementation // /** * Add a new dependency to the specified table if it does not * already exist in that table. * * @return boolean Whether or not the dependency get added. */ private boolean addDependencyToTable(Hashtable table, Object key, Dependency dy) { List deps = (List) table.get(key); if (deps == null) { deps = newSList(); deps.add(dy); table.put(key, deps); } else { /* Make sure that we're not adding a duplicate dependency */ UUID provKey = dy.getProvider().getObjectID(); UUID depKey = dy.getDependent().getObjectID(); for (ListIterator depsIT = deps.listIterator(); depsIT.hasNext(); ) { Dependency curDY = (Dependency)depsIT.next(); if (curDY.getProvider().getObjectID().equals(provKey) && curDY.getDependent().getObjectID().equals(depKey)) { return false; } } deps.add(dy); } if (SanityManager.DEBUG) { if (SanityManager.DEBUG_ON("memoryLeakTrace")) { if (table.size() > 100) System.out.println("memoryLeakTrace:BasicDependencyManager:table " + table.size()); if (deps.size() > 50) System.out.println("memoryLeakTrace:BasicDependencyManager:deps " + deps.size()); } } return true; } /** * removes a dependency for a given provider. assumes * that the dependent removal is being dealt with elsewhere. * Won't assume that the dependent only appears once in the list. */ protected void clearProviderDependency(UUID p, Dependency d) { List deps = (List) providers.get(p); if (deps == null) return; deps.remove(d); if (deps.size() == 0) providers.remove(p); } /** * Replace the DependencyDescriptors in an List with Dependencys. * * @param storedList The List of DependencyDescriptors representing * stored dependencies. * * @return List The converted List * * @exception StandardException thrown if something goes wrong */ private List getDependencyDescriptorList(List storedList) throws StandardException { DataDictionary dd = getDataDictionary(); if (storedList.size() != 0) { /* For each DependencyDescriptor, we need to instantiate * object descriptors of the appropriate type for both * the dependent and provider, create a Dependency with * that Dependent and Provider and substitute the Dependency * back into the same place in the List * so that the call gets an enumerations of Dependencys. */ for (ListIterator depsIterator = storedList.listIterator(); depsIterator.hasNext(); ) { Dependent tempD; Provider tempP; DependableFinder finder = null; DependencyDescriptor depDesc = (DependencyDescriptor) depsIterator.next(); try { finder = depDesc.getDependentFinder(); tempD = (Dependent) finder.getDependable( depDesc.getUUID() ); finder = depDesc.getProviderFinder(); tempP = (Provider) finder.getDependable( depDesc.getProviderID() );/* if (finder instanceof DDColumnDependableFinder) ((TableDescriptor)tempP).setReferencedColumnMap( new FormatableBitSet(((DDColumnDependableFinder) finder). getColumnBitMap()));*/ } catch (java.sql.SQLException te) { throw StandardException.newException(SQLState.DEP_UNABLE_TO_RESTORE, finder.getClass().getName(), te.getMessage()); } depsIterator.set(new BasicDependency(tempD, tempP)); } } return storedList; } /** * Returns the DataDictionary to use. * * @return DataDictionary The DataDictionary to use. */ private DataDictionary getDataDictionary() { if (dataDictionary == null) { DataDictionaryContext ddc; ddc = (DataDictionaryContext) (ContextService.getContext(DataDictionaryContext.CONTEXT_ID)); dataDictionary = ddc.getDataDictionary(); } return dataDictionary; } /** * Returns the LanguageConnectionContext to use. * * @return LanguageConnectionContext The LanguageConnectionContext to use. */ private LanguageConnectionContext getLanguageConnectionContext() { // find the language context. return (LanguageConnectionContext) ContextService.getContext(LanguageConnectionContext.CONTEXT_ID); } /** * Returns the LanguageConnectionContext to use. * * @param cm Current ContextManager * * @return LanguageConnectionContext The LanguageConnectionContext to use. */ private LanguageConnectionContext getLanguageConnectionContext(ContextManager cm) { // find the language context. return (LanguageConnectionContext) cm.getContext(LanguageConnectionContext.CONTEXT_ID); } /** * Do a bubble sort on the given array of UUIDs. This sorts by the * String values of the UUIDs. It's slow, but it doesn't matter * because this is only for testing and debugging. Sorting by * UUID.toString() always gives the same order because, within a * single boot of the system, UUIDs are distinguished only by a * sequence number. * * @param uuids The array of UUIDs to sort. */ private void bubbleSort(UUID[] uuids) { if (SanityManager.DEBUG) { for (int i = 0; i < uuids.length; i++) { for (int j = i + 1; j < uuids.length; j++) { if (uuids[i].toString().compareTo(uuids[j].toString()) > 0) { UUID save = uuids[i]; uuids[i] = uuids[j]; uuids[j] = save; } } } } } /** Returns an enumeration of all dependencies that this dependent has with any provider (even invalid ones). Includes all dependency types. @param d the dependent @exception StandardException thrown if something goes wrong */ protected List getProviders (Dependent d) throws StandardException { List deps = (List) dependents.get(d.getObjectID()); /* If the Dependent is not persistent, then we only have to * worry about in-memory dependencies. Otherwise, we have to * integrate the 2. */ if (! d.isPersistent()) { return (deps == null? null : deps); } else { if (deps == null) { deps = newSList(); } else { deps = newSList(deps); } /* Now we need to add any persistent dependencies to the * list before returning */ List storedList = getDependencyDescriptorList( getDataDictionary(). getDependentsDescriptorList( d.getObjectID().toString() ) ); if (storedList.size() > 0) { deps.addAll(0, storedList); } return deps; } } /** Returns an enumeration of all dependencies that this provider is supporting for any dependent at all (even invalid ones). Includes all dependency types. @param p the provider @exception StandardException thrown if something goes wrong */ protected List getDependents (Provider p) throws StandardException { List deps = (List) providers.get(p.getObjectID()); /* If the Provider is not persistent, then we only have to * worry about in-memory dependencies. Otherwise, we have to * integrate the 2. */ if (! p.isPersistent()) { return (deps == null? null : deps); } else { if (deps == null) { deps = newSList(); } else { deps = newSList(deps); } /* Now we need to add any persistent dependencies to the * list before returning */ List storedList = getDependencyDescriptorList( getDataDictionary(). getProvidersDescriptorList( p.getObjectID().toString() ) ); if (storedList.size() > 0) { deps.addAll(0, storedList); } return deps; } } private static List newSList() { return java.util.Collections.synchronizedList(new java.util.LinkedList()); } private static List newSList(List list) { return java.util.Collections.synchronizedList(new java.util.LinkedList(list)); } private DataDictionary dataDictionary = null; protected Hashtable dependents = new Hashtable(); protected Hashtable providers = new Hashtable();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -