package org.simantics.db.impl.query; import org.simantics.db.ObjectResourceIdMap; import org.simantics.db.RelationInfo; import org.simantics.db.exception.DatabaseException; import org.simantics.db.impl.graph.ReadGraphImpl; import org.simantics.db.impl.procedure.InternalProcedure; import org.simantics.db.procedure.AsyncMultiProcedure; import org.simantics.db.procedure.AsyncProcedure; import org.simantics.db.procedure.ListenerBase; import org.simantics.db.request.AsyncMultiRead; import org.simantics.db.request.AsyncRead; import org.simantics.db.request.ExternalRead; import org.simantics.db.request.MultiRead; import org.simantics.db.request.Read; import gnu.trove.map.hash.TObjectIntHashMap; public class QueryCache extends QueryCacheBase { public QueryCache(QuerySupport querySupport, int threads) { super(querySupport, threads); } Objects getOrCreateObjects(int r1, int r2) throws DatabaseException { Objects existing = null; synchronized(objectsMap) { existing = (Objects)objectsMap.get(r1,r2); if(existing == null) { existing = new Objects(r1,r2); existing.clearResult(querySupport); existing.setPending(); objectsMap.put(keyR2(r1,r2), existing); size++; return existing; } if(existing.requiresComputation()) { existing.setPending(); return existing; } } if(existing.isPending()) waitPending(existing); return existing; } void remove(Objects entry) { synchronized(objectsMap) { objectsMap.remove(entry.id); } } public static void runnerObjects(ReadGraphImpl graph, int r1, int r2, CacheEntry parent, ListenerBase listener, IntProcedure procedure) throws DatabaseException { QueryCache cache = graph.processor.cache; if(parent == null && listener == null && !cache.shouldCache(graph.processor, r1,r2)) { Objects.computeForEach(graph, r1,r2, null, procedure); return; } if(procedure == null) procedure = emptyProcedureObjects; Objects entry = (Objects)cache.getOrCreateObjects(r1,r2); ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure, false); if(entry.isReady()) entry.performFromCache(graph, procedure); else { Objects.computeForEach(graph, r1,r2, entry, procedure); if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult()); } } Statements getOrCreateStatements(int r1, int r2) throws DatabaseException { Statements existing = null; synchronized(statementsMap) { existing = (Statements)statementsMap.get(r1,r2); if(existing == null) { existing = new Statements(r1,r2); existing.clearResult(querySupport); existing.setPending(); statementsMap.put(keyR2(r1,r2), existing); size++; return existing; } if(existing.requiresComputation()) { existing.setPending(); return existing; } } if(existing.isPending()) waitPending(existing); return existing; } void remove(Statements entry) { synchronized(statementsMap) { statementsMap.remove(entry.id); } } public static void runnerStatements(ReadGraphImpl graph, int r1, int r2, CacheEntry parent, ListenerBase listener, TripleIntProcedure procedure) throws DatabaseException { QueryCache cache = graph.processor.cache; if(parent == null && listener == null && !cache.shouldCache(graph.processor, r1,r2)) { Statements.computeForEach(graph, r1,r2, null, procedure); return; } if(procedure == null) procedure = emptyProcedureStatements; Statements entry = (Statements)cache.getOrCreateStatements(r1,r2); ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure, false); if(entry.isReady()) entry.performFromCache(graph, procedure); else { Statements.computeForEach(graph, r1,r2, entry, procedure); if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult()); } } DirectObjects getOrCreateDirectObjects(int r1, int r2) throws DatabaseException { DirectObjects existing = null; synchronized(directObjectsMap) { existing = (DirectObjects)directObjectsMap.get(r1,r2); if(existing == null) { existing = new DirectObjects(r1,r2); existing.clearResult(querySupport); existing.setPending(); directObjectsMap.put(keyR2(r1,r2), existing); size++; return existing; } if(existing.requiresComputation()) { existing.setPending(); return existing; } } if(existing.isPending()) waitPending(existing); return existing; } void remove(DirectObjects entry) { synchronized(directObjectsMap) { directObjectsMap.remove(entry.id); } } public static void runnerDirectObjects(ReadGraphImpl graph, int r1, int r2, CacheEntry parent, ListenerBase listener, IntProcedure procedure) throws DatabaseException { QueryCache cache = graph.processor.cache; if(parent == null && listener == null && !cache.shouldCache(graph.processor, r1,r2)) { DirectObjects.computeForEach(graph, r1,r2, null, procedure); return; } if(procedure == null) procedure = emptyProcedureDirectObjects; DirectObjects entry = (DirectObjects)cache.getOrCreateDirectObjects(r1,r2); ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure, false); if(entry.isReady()) entry.performFromCache(graph, procedure); else { DirectObjects.computeForEach(graph, r1,r2, entry, procedure); if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult()); } } RelationInfoQuery getOrCreateRelationInfoQuery(int r) throws DatabaseException { RelationInfoQuery existing = null; synchronized(relationInfoQueryMap) { existing = (RelationInfoQuery)relationInfoQueryMap.get(r); if(existing == null) { existing = new RelationInfoQuery(r); existing.clearResult(querySupport); existing.setPending(); relationInfoQueryMap.put(keyR(r), existing); size++; return existing; } if(existing.requiresComputation()) { existing.setPending(); return existing; } } if(existing.isPending()) waitPending(existing); return existing; } void remove(RelationInfoQuery entry) { synchronized(relationInfoQueryMap) { relationInfoQueryMap.remove(entry.id); } } public static void runnerRelationInfoQuery(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, InternalProcedure procedure) throws DatabaseException { QueryCache cache = graph.processor.cache; if(parent == null && listener == null && !cache.shouldCache(graph.processor, r)) { RelationInfoQuery.computeForEach(graph, r, null, procedure); return; } if(procedure == null) procedure = emptyProcedureRelationInfoQuery; RelationInfoQuery entry = (RelationInfoQuery)cache.getOrCreateRelationInfoQuery(r); ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure, false); if(entry.isReady()) entry.performFromCache(graph, procedure); else { RelationInfoQuery.computeForEach(graph, r, entry, procedure); if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult()); } } URIToResource getOrCreateURIToResource(String id) throws DatabaseException { URIToResource existing = null; synchronized(uRIToResourceMap) { existing = (URIToResource)uRIToResourceMap.get(id); if(existing == null) { existing = new URIToResource(id); existing.clearResult(querySupport); existing.setPending(); uRIToResourceMap.put(keyID(id), existing); size++; return existing; } if(existing.requiresComputation()) { existing.setPending(); return existing; } } if(existing.isPending()) waitPending(existing); return existing; } void remove(URIToResource entry) { synchronized(uRIToResourceMap) { uRIToResourceMap.remove(entry.id); } } public static void runnerURIToResource(ReadGraphImpl graph, String id, CacheEntry parent, ListenerBase listener, InternalProcedure procedure) throws DatabaseException { QueryCache cache = graph.processor.cache; if(parent == null && listener == null && !cache.shouldCache(graph.processor, id)) { URIToResource.computeForEach(graph, id, null, procedure); return; } if(procedure == null) procedure = emptyProcedureURIToResource; URIToResource entry = (URIToResource)cache.getOrCreateURIToResource(id); ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure, false); if(entry.isReady()) entry.performFromCache(graph, procedure); else { URIToResource.computeForEach(graph, id, entry, procedure); if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult()); } } ValueQuery getOrCreateValueQuery(int r) throws DatabaseException { ValueQuery existing = null; synchronized(valueQueryMap) { existing = (ValueQuery)valueQueryMap.get(r); if(existing == null) { existing = new ValueQuery(r); existing.clearResult(querySupport); existing.setPending(); valueQueryMap.put(keyR(r), existing); size++; return existing; } if(existing.requiresComputation()) { existing.setPending(); return existing; } } if(existing.isPending()) waitPending(existing); return existing; } void remove(ValueQuery entry) { synchronized(valueQueryMap) { valueQueryMap.remove(entry.id); } } public static void runnerValueQuery(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, InternalProcedure procedure) throws DatabaseException { QueryCache cache = graph.processor.cache; if(parent == null && listener == null && !cache.shouldCache(graph.processor, r)) { ValueQuery.computeForEach(graph, r, null, procedure); return; } if(procedure == null) procedure = emptyProcedureValueQuery; ValueQuery entry = (ValueQuery)cache.getOrCreateValueQuery(r); ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure, false); if(entry.isReady()) entry.performFromCache(graph, procedure); else { ValueQuery.computeForEach(graph, r, entry, procedure); if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult()); } } OrderedSet getOrCreateOrderedSet(int r) throws DatabaseException { OrderedSet existing = null; synchronized(orderedSetMap) { existing = (OrderedSet)orderedSetMap.get(r); if(existing == null) { existing = new OrderedSet(r); existing.clearResult(querySupport); existing.setPending(); orderedSetMap.put(keyR(r), existing); size++; return existing; } if(existing.requiresComputation()) { existing.setPending(); return existing; } } if(existing.isPending()) waitPending(existing); return existing; } void remove(OrderedSet entry) { synchronized(orderedSetMap) { orderedSetMap.remove(entry.id); } } public static void runnerOrderedSet(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, IntProcedure procedure) throws DatabaseException { QueryCache cache = graph.processor.cache; if(parent == null && listener == null && !cache.shouldCache(graph.processor, r)) { OrderedSet.computeForEach(graph, r, null, procedure); return; } if(procedure == null) procedure = emptyProcedureOrderedSet; OrderedSet entry = (OrderedSet)cache.getOrCreateOrderedSet(r); ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure, false); if(entry.isReady()) entry.performFromCache(graph, procedure); else { OrderedSet.computeForEach(graph, r, entry, procedure); if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult()); } } PrincipalTypes getOrCreatePrincipalTypes(int r) throws DatabaseException { PrincipalTypes existing = null; synchronized(principalTypesMap) { existing = (PrincipalTypes)principalTypesMap.get(r); if(existing == null) { existing = new PrincipalTypes(r); existing.clearResult(querySupport); existing.setPending(); principalTypesMap.put(keyR(r), existing); size++; return existing; } if(existing.requiresComputation()) { existing.setPending(); return existing; } } if(existing.isPending()) waitPending(existing); return existing; } void remove(PrincipalTypes entry) { synchronized(principalTypesMap) { principalTypesMap.remove(entry.id); } } public static void runnerPrincipalTypes(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, IntProcedure procedure) throws DatabaseException { QueryCache cache = graph.processor.cache; if(parent == null && listener == null && !cache.shouldCache(graph.processor, r)) { PrincipalTypes.computeForEach(graph, r, null, procedure); return; } if(procedure == null) procedure = emptyProcedurePrincipalTypes; PrincipalTypes entry = (PrincipalTypes)cache.getOrCreatePrincipalTypes(r); ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure, false); if(entry.isReady()) entry.performFromCache(graph, procedure); else { PrincipalTypes.computeForEach(graph, r, entry, procedure); if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult()); } } DirectPredicates getOrCreateDirectPredicates(int r) throws DatabaseException { DirectPredicates existing = null; synchronized(directPredicatesMap) { existing = (DirectPredicates)directPredicatesMap.get(r); if(existing == null) { existing = new DirectPredicates(r); existing.clearResult(querySupport); existing.setPending(); directPredicatesMap.put(keyR(r), existing); size++; return existing; } if(existing.requiresComputation()) { existing.setPending(); return existing; } } if(existing.isPending()) waitPending(existing); return existing; } void remove(DirectPredicates entry) { synchronized(directPredicatesMap) { directPredicatesMap.remove(entry.id); } } public static void runnerDirectPredicates(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, InternalProcedure procedure) throws DatabaseException { QueryCache cache = graph.processor.cache; if(parent == null && listener == null && !cache.shouldCache(graph.processor, r)) { DirectPredicates.computeForEach(graph, r, null, procedure); return; } if(procedure == null) procedure = emptyProcedureDirectPredicates; DirectPredicates entry = (DirectPredicates)cache.getOrCreateDirectPredicates(r); ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure, false); if(entry.isReady()) entry.performFromCache(graph, procedure); else { DirectPredicates.computeForEach(graph, r, entry, procedure); if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult()); } } Predicates getOrCreatePredicates(int r) throws DatabaseException { Predicates existing = null; synchronized(predicatesMap) { existing = (Predicates)predicatesMap.get(r); if(existing == null) { existing = new Predicates(r); existing.clearResult(querySupport); existing.setPending(); predicatesMap.put(keyR(r), existing); size++; return existing; } if(existing.requiresComputation()) { existing.setPending(); return existing; } } if(existing.isPending()) waitPending(existing); return existing; } void remove(Predicates entry) { synchronized(predicatesMap) { predicatesMap.remove(entry.id); } } public static void runnerPredicates(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, InternalProcedure procedure) throws DatabaseException { QueryCache cache = graph.processor.cache; if(parent == null && listener == null && !cache.shouldCache(graph.processor, r)) { Predicates.computeForEach(graph, r, null, procedure); return; } if(procedure == null) procedure = emptyProcedurePredicates; Predicates entry = (Predicates)cache.getOrCreatePredicates(r); ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure, false); if(entry.isReady()) entry.performFromCache(graph, procedure); else { Predicates.computeForEach(graph, r, entry, procedure); if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult()); } } ReadEntry getOrCreateReadEntry(Read r) throws DatabaseException { ReadEntry existing = null; synchronized(readEntryMap) { existing = (ReadEntry)readEntryMap.get(r); if(existing == null) { existing = new ReadEntry(r); existing.clearResult(querySupport); existing.setPending(); readEntryMap.put(id(r), existing); size++; return existing; } if(existing.requiresComputation()) { existing.setPending(); return existing; } } if(existing.isPending()) waitPending(existing); return existing; } void remove(ReadEntry entry) { synchronized(readEntryMap) { readEntryMap.remove(entry.request); } } public static void runnerReadEntry(ReadGraphImpl graph, Read r, CacheEntry parent, ListenerBase listener, AsyncProcedure procedure) throws DatabaseException { QueryCache cache = graph.processor.cache; if(parent == null && listener == null && !cache.shouldCache(graph.processor, r)) { ReadEntry.computeForEach(graph, r, null, procedure); return; } if(procedure == null) procedure = emptyProcedureReadEntry; ReadEntry entry = (ReadEntry)cache.getOrCreateReadEntry(r); ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure, false); if(entry.isReady()) entry.performFromCache(graph, procedure); else { ReadEntry.computeForEach(graph, r, entry, procedure); if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult()); } } AsyncReadEntry getOrCreateAsyncReadEntry(AsyncRead r) throws DatabaseException { AsyncReadEntry existing = null; synchronized(asyncReadEntryMap) { existing = (AsyncReadEntry)asyncReadEntryMap.get(r); if(existing == null) { existing = new AsyncReadEntry(r); existing.clearResult(querySupport); existing.setPending(); asyncReadEntryMap.put(id(r), existing); size++; return existing; } if(existing.requiresComputation()) { existing.setPending(); return existing; } } if(existing.isPending()) waitPending(existing); return existing; } void remove(AsyncReadEntry entry) { synchronized(asyncReadEntryMap) { asyncReadEntryMap.remove(entry.request); } } public static void runnerAsyncReadEntry(ReadGraphImpl graph, AsyncRead r, CacheEntry parent, ListenerBase listener, AsyncProcedure procedure) throws DatabaseException { QueryCache cache = graph.processor.cache; if(parent == null && listener == null && !cache.shouldCache(graph.processor, r)) { AsyncReadEntry.computeForEach(graph, r, null, procedure); return; } if(procedure == null) procedure = emptyProcedureAsyncReadEntry; AsyncReadEntry entry = (AsyncReadEntry)cache.getOrCreateAsyncReadEntry(r); ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure, false); if(entry.isReady()) entry.performFromCache(graph, procedure); else { AsyncReadEntry.computeForEach(graph, r, entry, procedure); if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult()); } } Types getOrCreateTypes(int r) throws DatabaseException { Types existing = null; synchronized(typesMap) { existing = (Types)typesMap.get(r); if(existing == null) { existing = new Types(r); existing.clearResult(querySupport); existing.setPending(); typesMap.put(keyR(r), existing); size++; return existing; } if(existing.requiresComputation()) { existing.setPending(); return existing; } } if(existing.isPending()) waitPending(existing); return existing; } void remove(Types entry) { synchronized(typesMap) { typesMap.remove(entry.id); } } public static void runnerTypes(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, InternalProcedure procedure) throws DatabaseException { QueryCache cache = graph.processor.cache; if(parent == null && listener == null && !cache.shouldCache(graph.processor, r)) { Types.computeForEach(graph, r, null, procedure); return; } if(procedure == null) procedure = emptyProcedureTypes; Types entry = (Types)cache.getOrCreateTypes(r); ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure, false); if(entry.isReady()) entry.performFromCache(graph, procedure); else { Types.computeForEach(graph, r, entry, procedure); if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult()); } } ChildMap getOrCreateChildMap(int r) throws DatabaseException { ChildMap existing = null; synchronized(childMapMap) { existing = (ChildMap)childMapMap.get(r); if(existing == null) { existing = new ChildMap(r); existing.clearResult(querySupport); existing.setPending(); childMapMap.put(keyR(r), existing); size++; return existing; } if(existing.requiresComputation()) { existing.setPending(); return existing; } } if(existing.isPending()) waitPending(existing); return existing; } void remove(ChildMap entry) { synchronized(childMapMap) { childMapMap.remove(entry.id); } } public static void runnerChildMap(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, InternalProcedure> procedure) throws DatabaseException { QueryCache cache = graph.processor.cache; if(parent == null && listener == null && !cache.shouldCache(graph.processor, r)) { ChildMap.computeForEach(graph, r, null, procedure); return; } if(procedure == null) procedure = emptyProcedureChildMap; ChildMap entry = (ChildMap)cache.getOrCreateChildMap(r); ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure, false); if(entry.isReady()) entry.performFromCache(graph, procedure); else { ChildMap.computeForEach(graph, r, entry, procedure); if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult()); } } AssertedStatements getOrCreateAssertedStatements(int r1, int r2) throws DatabaseException { AssertedStatements existing = null; synchronized(assertedStatementsMap) { existing = (AssertedStatements)assertedStatementsMap.get(r1,r2); if(existing == null) { existing = new AssertedStatements(r1,r2); existing.clearResult(querySupport); existing.setPending(); assertedStatementsMap.put(keyR2(r1,r2), existing); size++; return existing; } if(existing.requiresComputation()) { existing.setPending(); return existing; } } if(existing.isPending()) waitPending(existing); return existing; } void remove(AssertedStatements entry) { synchronized(assertedStatementsMap) { assertedStatementsMap.remove(entry.id); } } public static void runnerAssertedStatements(ReadGraphImpl graph, int r1, int r2, CacheEntry parent, ListenerBase listener, TripleIntProcedure procedure) throws DatabaseException { QueryCache cache = graph.processor.cache; if(procedure == null) procedure = emptyProcedureAssertedStatements; AssertedStatements entry = (AssertedStatements)cache.getOrCreateAssertedStatements(r1,r2); ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure, false); if(entry.isReady()) entry.performFromCache(graph, procedure); else { entry.compute(graph, procedure); if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult()); } } AssertedPredicates getOrCreateAssertedPredicates(int r) throws DatabaseException { AssertedPredicates existing = null; synchronized(assertedPredicatesMap) { existing = (AssertedPredicates)assertedPredicatesMap.get(r); if(existing == null) { existing = new AssertedPredicates(r); existing.clearResult(querySupport); existing.setPending(); assertedPredicatesMap.put(keyR(r), existing); size++; return existing; } if(existing.requiresComputation()) { existing.setPending(); return existing; } } if(existing.isPending()) waitPending(existing); return existing; } void remove(AssertedPredicates entry) { synchronized(assertedPredicatesMap) { assertedPredicatesMap.remove(entry.id); } } public static void runnerAssertedPredicates(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, IntProcedure procedure) throws DatabaseException { QueryCache cache = graph.processor.cache; if(procedure == null) procedure = emptyProcedureAssertedPredicates; AssertedPredicates entry = (AssertedPredicates)cache.getOrCreateAssertedPredicates(r); ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure, false); if(entry.isReady()) entry.performFromCache(graph, procedure); else { entry.compute(graph, procedure); if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult()); } } DirectSuperRelations getOrCreateDirectSuperRelations(int r) throws DatabaseException { DirectSuperRelations existing = null; synchronized(directSuperRelationsMap) { existing = (DirectSuperRelations)directSuperRelationsMap.get(r); if(existing == null) { existing = new DirectSuperRelations(r); existing.clearResult(querySupport); existing.setPending(); directSuperRelationsMap.put(keyR(r), existing); size++; return existing; } if(existing.requiresComputation()) { existing.setPending(); return existing; } } if(existing.isPending()) waitPending(existing); return existing; } void remove(DirectSuperRelations entry) { synchronized(directSuperRelationsMap) { directSuperRelationsMap.remove(entry.id); } } public static void runnerDirectSuperRelations(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, IntProcedure procedure) throws DatabaseException { QueryCache cache = graph.processor.cache; if(procedure == null) procedure = emptyProcedureDirectSuperRelations; DirectSuperRelations entry = (DirectSuperRelations)cache.getOrCreateDirectSuperRelations(r); ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure, false); if(entry.isReady()) entry.performFromCache(graph, procedure); else { entry.compute(graph, procedure); if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult()); } } SuperTypes getOrCreateSuperTypes(int r) throws DatabaseException { SuperTypes existing = null; synchronized(superTypesMap) { existing = (SuperTypes)superTypesMap.get(r); if(existing == null) { existing = new SuperTypes(r); existing.clearResult(querySupport); existing.setPending(); superTypesMap.put(keyR(r), existing); size++; return existing; } if(existing.requiresComputation()) { existing.setPending(); return existing; } } if(existing.isPending()) waitPending(existing); return existing; } void remove(SuperTypes entry) { synchronized(superTypesMap) { superTypesMap.remove(entry.id); } } public static void runnerSuperTypes(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, InternalProcedure procedure) throws DatabaseException { QueryCache cache = graph.processor.cache; if(procedure == null) procedure = emptyProcedureSuperTypes; SuperTypes entry = (SuperTypes)cache.getOrCreateSuperTypes(r); ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure, false); if(entry.isReady()) entry.performFromCache(graph, procedure); else { entry.compute(graph, procedure); if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult()); } } TypeHierarchy getOrCreateTypeHierarchy(int r) throws DatabaseException { TypeHierarchy existing = null; synchronized(typeHierarchyMap) { existing = (TypeHierarchy)typeHierarchyMap.get(r); if(existing == null) { existing = new TypeHierarchy(r); existing.clearResult(querySupport); existing.setPending(); typeHierarchyMap.put(keyR(r), existing); size++; return existing; } if(existing.requiresComputation()) { existing.setPending(); return existing; } } if(existing.isPending()) waitPending(existing); return existing; } void remove(TypeHierarchy entry) { synchronized(typeHierarchyMap) { typeHierarchyMap.remove(entry.id); } } public static void runnerTypeHierarchy(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, InternalProcedure procedure) throws DatabaseException { QueryCache cache = graph.processor.cache; if(procedure == null) procedure = emptyProcedureTypeHierarchy; TypeHierarchy entry = (TypeHierarchy)cache.getOrCreateTypeHierarchy(r); ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure, false); if(entry.isReady()) entry.performFromCache(graph, procedure); else { entry.compute(graph, procedure); if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult()); } } SuperRelations getOrCreateSuperRelations(int r) throws DatabaseException { SuperRelations existing = null; synchronized(superRelationsMap) { existing = (SuperRelations)superRelationsMap.get(r); if(existing == null) { existing = new SuperRelations(r); existing.clearResult(querySupport); existing.setPending(); superRelationsMap.put(keyR(r), existing); size++; return existing; } if(existing.requiresComputation()) { existing.setPending(); return existing; } } if(existing.isPending()) waitPending(existing); return existing; } void remove(SuperRelations entry) { synchronized(superRelationsMap) { superRelationsMap.remove(entry.id); } } public static void runnerSuperRelations(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, InternalProcedure procedure) throws DatabaseException { QueryCache cache = graph.processor.cache; if(procedure == null) procedure = emptyProcedureSuperRelations; SuperRelations entry = (SuperRelations)cache.getOrCreateSuperRelations(r); ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure, false); if(entry.isReady()) entry.performFromCache(graph, procedure); else { entry.compute(graph, procedure); if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult()); } } MultiReadEntry getOrCreateMultiReadEntry(MultiRead r) throws DatabaseException { MultiReadEntry existing = null; synchronized(multiReadEntryMap) { existing = (MultiReadEntry)multiReadEntryMap.get(r); if(existing == null) { existing = new MultiReadEntry(r); existing.clearResult(querySupport); existing.setPending(); multiReadEntryMap.put(id(r), existing); size++; return existing; } if(existing.requiresComputation()) { existing.setPending(); return existing; } } if(existing.isPending()) waitPending(existing); return existing; } void remove(MultiReadEntry entry) { synchronized(multiReadEntryMap) { multiReadEntryMap.remove(entry.request); } } public static void runnerMultiReadEntry(ReadGraphImpl graph, MultiRead r, CacheEntry parent, ListenerBase listener, AsyncMultiProcedure procedure) throws DatabaseException { QueryCache cache = graph.processor.cache; if(procedure == null) procedure = emptyProcedureMultiReadEntry; MultiReadEntry entry = (MultiReadEntry)cache.getOrCreateMultiReadEntry(r); ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure, false); if(entry.isReady()) entry.performFromCache(graph, procedure); else { entry.compute(graph, procedure); if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult()); } } AsyncMultiReadEntry getOrCreateAsyncMultiReadEntry(AsyncMultiRead r) throws DatabaseException { AsyncMultiReadEntry existing = null; synchronized(asyncMultiReadEntryMap) { existing = (AsyncMultiReadEntry)asyncMultiReadEntryMap.get(r); if(existing == null) { existing = new AsyncMultiReadEntry(r); existing.clearResult(querySupport); existing.setPending(); asyncMultiReadEntryMap.put(id(r), existing); size++; return existing; } if(existing.requiresComputation()) { existing.setPending(); return existing; } } if(existing.isPending()) waitPending(existing); return existing; } void remove(AsyncMultiReadEntry entry) { synchronized(asyncMultiReadEntryMap) { asyncMultiReadEntryMap.remove(entry.request); } } public static void runnerAsyncMultiReadEntry(ReadGraphImpl graph, AsyncMultiRead r, CacheEntry parent, ListenerBase listener, AsyncMultiProcedure procedure) throws DatabaseException { QueryCache cache = graph.processor.cache; if(procedure == null) procedure = emptyProcedureAsyncMultiReadEntry; AsyncMultiReadEntry entry = (AsyncMultiReadEntry)cache.getOrCreateAsyncMultiReadEntry(r); ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure, false); if(entry.isReady()) entry.performFromCache(graph, procedure); else { entry.compute(graph, procedure); if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult()); } } ExternalReadEntry getOrCreateExternalReadEntry(ExternalRead r) throws DatabaseException { ExternalReadEntry existing = null; synchronized(externalReadEntryMap) { existing = (ExternalReadEntry)externalReadEntryMap.get(r); if(existing == null) { existing = new ExternalReadEntry(r); existing.clearResult(querySupport); existing.setPending(); externalReadEntryMap.put(id(r), existing); size++; return existing; } if(existing.requiresComputation()) { existing.setPending(); return existing; } } if(existing.isPending()) waitPending(existing); return existing; } void remove(ExternalReadEntry entry) { synchronized(externalReadEntryMap) { externalReadEntryMap.remove(entry.request); } } public static void runnerExternalReadEntry(ReadGraphImpl graph, ExternalRead r, CacheEntry parent, ListenerBase listener, AsyncProcedure procedure) throws DatabaseException { QueryCache cache = graph.processor.cache; if(procedure == null) procedure = emptyProcedureExternalReadEntry; ExternalReadEntry entry = (ExternalReadEntry)cache.getOrCreateExternalReadEntry(r); ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure, false); if(entry.isReady()) entry.performFromCache(graph, procedure); else { entry.compute(graph, procedure); if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult()); } } }