X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.db.impl%2Fsrc%2Forg%2Fsimantics%2Fdb%2Fimpl%2Fquery%2FQueryCache.java;h=7b591abb7fd80e062308ce3df88c86e872cfe27e;hb=8b6de499c9c1bad0e72631719fd165ce39d6ad56;hp=3e7a25190df94fe225f803bea23215c770727417;hpb=5bc1c2b950d374ecfcc206981724c3b9286dcbd6;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryCache.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryCache.java index 3e7a25190..7b591abb7 100644 --- a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryCache.java +++ b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryCache.java @@ -10,21 +10,20 @@ import org.simantics.db.impl.query.QueryProcessor.SessionTask; import org.simantics.db.procedure.AsyncMultiProcedure; import org.simantics.db.procedure.AsyncProcedure; import org.simantics.db.procedure.ListenerBase; +import org.simantics.db.procedure.SyncMultiProcedure; 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 getOrCreateObjects(QueryProcessor processor, int r1, int r2) throws DatabaseException { Objects existing = null; synchronized(objectsMap) { existing = (Objects)objectsMap.get(r1,r2); @@ -41,7 +40,7 @@ public class QueryCache extends QueryCacheBase { return existing; } } - if(existing.isPending()) waitPending(existing); + if(existing.isPending()) waitPending(processor, existing); return existing; } @@ -57,7 +56,7 @@ public class QueryCache extends QueryCacheBase { Objects.computeForEach(graph, r1,r2, null, procedure); return; } - Objects entry = (Objects)cache.getOrCreateObjects(r1,r2); + Objects entry = (Objects)cache.getOrCreateObjects(graph.processor, r1,r2); IntProcedure procedure_ = procedure != null ? procedure : emptyProcedureObjects; ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false); if(entry.isReady()) entry.performFromCache(graph, procedure_); @@ -68,7 +67,7 @@ public class QueryCache extends QueryCacheBase { } } - Statements getOrCreateStatements(int r1, int r2) throws DatabaseException { + Statements getOrCreateStatements(QueryProcessor processor, int r1, int r2) throws DatabaseException { Statements existing = null; synchronized(statementsMap) { existing = (Statements)statementsMap.get(r1,r2); @@ -85,7 +84,7 @@ public class QueryCache extends QueryCacheBase { return existing; } } - if(existing.isPending()) waitPending(existing); + if(existing.isPending()) waitPending(processor, existing); return existing; } @@ -101,7 +100,7 @@ public class QueryCache extends QueryCacheBase { Statements.computeForEach(graph, r1,r2, null, procedure); return; } - Statements entry = (Statements)cache.getOrCreateStatements(r1,r2); + Statements entry = (Statements)cache.getOrCreateStatements(graph.processor, r1,r2); TripleIntProcedure procedure_ = procedure != null ? procedure : emptyProcedureStatements; ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false); if(entry.isReady()) entry.performFromCache(graph, procedure_); @@ -112,7 +111,7 @@ public class QueryCache extends QueryCacheBase { } } - DirectObjects getOrCreateDirectObjects(int r1, int r2) throws DatabaseException { + DirectObjects getOrCreateDirectObjects(QueryProcessor processor, int r1, int r2) throws DatabaseException { DirectObjects existing = null; synchronized(directObjectsMap) { existing = (DirectObjects)directObjectsMap.get(r1,r2); @@ -129,7 +128,7 @@ public class QueryCache extends QueryCacheBase { return existing; } } - if(existing.isPending()) waitPending(existing); + if(existing.isPending()) waitPending(processor, existing); return existing; } @@ -145,7 +144,7 @@ public class QueryCache extends QueryCacheBase { DirectObjects.computeForEach(graph, r1,r2, null, procedure); return; } - DirectObjects entry = (DirectObjects)cache.getOrCreateDirectObjects(r1,r2); + DirectObjects entry = (DirectObjects)cache.getOrCreateDirectObjects(graph.processor, r1,r2); IntProcedure procedure_ = procedure != null ? procedure : emptyProcedureDirectObjects; ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false); if(entry.isReady()) entry.performFromCache(graph, procedure_); @@ -156,7 +155,7 @@ public class QueryCache extends QueryCacheBase { } } - RelationInfoQuery getOrCreateRelationInfoQuery(int r) throws DatabaseException { + RelationInfoQuery getOrCreateRelationInfoQuery(QueryProcessor processor, int r) throws DatabaseException { RelationInfoQuery existing = null; synchronized(relationInfoQueryMap) { existing = (RelationInfoQuery)relationInfoQueryMap.get(r); @@ -173,7 +172,7 @@ public class QueryCache extends QueryCacheBase { return existing; } } - if(existing.isPending()) waitPending(existing); + if(existing.isPending()) waitPending(processor, existing); return existing; } @@ -189,7 +188,7 @@ public class QueryCache extends QueryCacheBase { RelationInfoQuery.computeForEach(graph, r, null, procedure); return; } - RelationInfoQuery entry = (RelationInfoQuery)cache.getOrCreateRelationInfoQuery(r); + RelationInfoQuery entry = (RelationInfoQuery)cache.getOrCreateRelationInfoQuery(graph.processor, r); InternalProcedure procedure_ = procedure != null ? procedure : emptyProcedureRelationInfoQuery; ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false); if(entry.isReady()) entry.performFromCache(graph, procedure_); @@ -200,7 +199,7 @@ public class QueryCache extends QueryCacheBase { } } - URIToResource getOrCreateURIToResource(String id) throws DatabaseException { + URIToResource getOrCreateURIToResource(QueryProcessor processor, String id) throws DatabaseException { URIToResource existing = null; synchronized(uRIToResourceMap) { existing = (URIToResource)uRIToResourceMap.get(id); @@ -217,7 +216,7 @@ public class QueryCache extends QueryCacheBase { return existing; } } - if(existing.isPending()) waitPending(existing); + if(existing.isPending()) waitPending(processor, existing); return existing; } @@ -233,7 +232,7 @@ public class QueryCache extends QueryCacheBase { URIToResource.computeForEach(graph, id, null, procedure); return; } - URIToResource entry = (URIToResource)cache.getOrCreateURIToResource(id); + URIToResource entry = (URIToResource)cache.getOrCreateURIToResource(graph.processor, id); InternalProcedure procedure_ = procedure != null ? procedure : emptyProcedureURIToResource; ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false); if(entry.isReady()) entry.performFromCache(graph, procedure_); @@ -244,7 +243,7 @@ public class QueryCache extends QueryCacheBase { } } - ValueQuery getOrCreateValueQuery(int r) throws DatabaseException { + ValueQuery getOrCreateValueQuery(QueryProcessor processor, int r) throws DatabaseException { ValueQuery existing = null; synchronized(valueQueryMap) { existing = (ValueQuery)valueQueryMap.get(r); @@ -261,7 +260,7 @@ public class QueryCache extends QueryCacheBase { return existing; } } - if(existing.isPending()) waitPending(existing); + if(existing.isPending()) waitPending(processor, existing); return existing; } @@ -277,7 +276,7 @@ public class QueryCache extends QueryCacheBase { ValueQuery.computeForEach(graph, r, null, procedure); return; } - ValueQuery entry = (ValueQuery)cache.getOrCreateValueQuery(r); + ValueQuery entry = (ValueQuery)cache.getOrCreateValueQuery(graph.processor, r); InternalProcedure procedure_ = procedure != null ? procedure : emptyProcedureValueQuery; ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false); if(entry.isReady()) entry.performFromCache(graph, procedure_); @@ -288,7 +287,7 @@ public class QueryCache extends QueryCacheBase { } } - OrderedSet getOrCreateOrderedSet(int r) throws DatabaseException { + OrderedSet getOrCreateOrderedSet(QueryProcessor processor, int r) throws DatabaseException { OrderedSet existing = null; synchronized(orderedSetMap) { existing = (OrderedSet)orderedSetMap.get(r); @@ -305,7 +304,7 @@ public class QueryCache extends QueryCacheBase { return existing; } } - if(existing.isPending()) waitPending(existing); + if(existing.isPending()) waitPending(processor, existing); return existing; } @@ -321,7 +320,7 @@ public class QueryCache extends QueryCacheBase { OrderedSet.computeForEach(graph, r, null, procedure); return; } - OrderedSet entry = (OrderedSet)cache.getOrCreateOrderedSet(r); + OrderedSet entry = (OrderedSet)cache.getOrCreateOrderedSet(graph.processor, r); IntProcedure procedure_ = procedure != null ? procedure : emptyProcedureOrderedSet; ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false); if(entry.isReady()) entry.performFromCache(graph, procedure_); @@ -332,7 +331,7 @@ public class QueryCache extends QueryCacheBase { } } - PrincipalTypes getOrCreatePrincipalTypes(int r) throws DatabaseException { + PrincipalTypes getOrCreatePrincipalTypes(QueryProcessor processor, int r) throws DatabaseException { PrincipalTypes existing = null; synchronized(principalTypesMap) { existing = (PrincipalTypes)principalTypesMap.get(r); @@ -349,7 +348,7 @@ public class QueryCache extends QueryCacheBase { return existing; } } - if(existing.isPending()) waitPending(existing); + if(existing.isPending()) waitPending(processor, existing); return existing; } @@ -365,7 +364,7 @@ public class QueryCache extends QueryCacheBase { PrincipalTypes.computeForEach(graph, r, null, procedure); return; } - PrincipalTypes entry = (PrincipalTypes)cache.getOrCreatePrincipalTypes(r); + PrincipalTypes entry = (PrincipalTypes)cache.getOrCreatePrincipalTypes(graph.processor, r); IntProcedure procedure_ = procedure != null ? procedure : emptyProcedurePrincipalTypes; ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false); if(entry.isReady()) entry.performFromCache(graph, procedure_); @@ -376,7 +375,7 @@ public class QueryCache extends QueryCacheBase { } } - DirectPredicates getOrCreateDirectPredicates(int r) throws DatabaseException { + DirectPredicates getOrCreateDirectPredicates(QueryProcessor processor, int r) throws DatabaseException { DirectPredicates existing = null; synchronized(directPredicatesMap) { existing = (DirectPredicates)directPredicatesMap.get(r); @@ -393,7 +392,7 @@ public class QueryCache extends QueryCacheBase { return existing; } } - if(existing.isPending()) waitPending(existing); + if(existing.isPending()) waitPending(processor, existing); return existing; } @@ -409,7 +408,7 @@ public class QueryCache extends QueryCacheBase { DirectPredicates.computeForEach(graph, r, null, procedure); return; } - DirectPredicates entry = (DirectPredicates)cache.getOrCreateDirectPredicates(r); + DirectPredicates entry = (DirectPredicates)cache.getOrCreateDirectPredicates(graph.processor, r); InternalProcedure procedure_ = procedure != null ? procedure : emptyProcedureDirectPredicates; ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false); if(entry.isReady()) entry.performFromCache(graph, procedure_); @@ -420,7 +419,7 @@ public class QueryCache extends QueryCacheBase { } } - Predicates getOrCreatePredicates(int r) throws DatabaseException { + Predicates getOrCreatePredicates(QueryProcessor processor, int r) throws DatabaseException { Predicates existing = null; synchronized(predicatesMap) { existing = (Predicates)predicatesMap.get(r); @@ -437,7 +436,7 @@ public class QueryCache extends QueryCacheBase { return existing; } } - if(existing.isPending()) waitPending(existing); + if(existing.isPending()) waitPending(processor, existing); return existing; } @@ -453,7 +452,7 @@ public class QueryCache extends QueryCacheBase { Predicates.computeForEach(graph, r, null, procedure); return; } - Predicates entry = (Predicates)cache.getOrCreatePredicates(r); + Predicates entry = (Predicates)cache.getOrCreatePredicates(graph.processor, r); InternalProcedure procedure_ = procedure != null ? procedure : emptyProcedurePredicates; ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false); if(entry.isReady()) entry.performFromCache(graph, procedure_); @@ -464,7 +463,7 @@ public class QueryCache extends QueryCacheBase { } } - ReadEntry getOrCreateReadEntry(Read r, boolean isSync) throws DatabaseException { + ReadEntry getOrCreateReadEntry(QueryProcessor processor, Read r, boolean isSync) throws DatabaseException { ReadEntry existing = null; synchronized(readEntryMap) { existing = (ReadEntry)readEntryMap.get(r); @@ -482,7 +481,7 @@ public class QueryCache extends QueryCacheBase { } } if(existing.isPending()) { - if(isSync) waitPending(existing); + if(isSync) waitPending(processor, existing); else return null; } return existing; @@ -500,9 +499,9 @@ public class QueryCache extends QueryCacheBase { ReadEntry.computeForEach(graph, r, null, procedure); return; } - ReadEntry entry = (ReadEntry)cache.getOrCreateReadEntry(r, isSync); + ReadEntry entry = (ReadEntry)cache.getOrCreateReadEntry(graph.processor, r, isSync); if(entry == null) { - graph.processor.schedule(Integer.MIN_VALUE, new SessionTask(r, graph.processor.THREAD_MASK+1, -1) { + graph.processor.schedule(new SessionTask(false) { @Override public void run(int thread) { try { @@ -525,7 +524,7 @@ public class QueryCache extends QueryCacheBase { } } - AsyncReadEntry getOrCreateAsyncReadEntry(AsyncRead r, boolean isSync) throws DatabaseException { + AsyncReadEntry getOrCreateAsyncReadEntry(QueryProcessor processor, AsyncRead r, boolean isSync) throws DatabaseException { AsyncReadEntry existing = null; synchronized(asyncReadEntryMap) { existing = (AsyncReadEntry)asyncReadEntryMap.get(r); @@ -543,7 +542,7 @@ public class QueryCache extends QueryCacheBase { } } if(existing.isPending()) { - if(isSync) waitPending(existing); + if(isSync) waitPending(processor, existing); else return null; } return existing; @@ -561,9 +560,9 @@ public class QueryCache extends QueryCacheBase { AsyncReadEntry.computeForEach(graph, r, null, procedure); return; } - AsyncReadEntry entry = (AsyncReadEntry)cache.getOrCreateAsyncReadEntry(r, isSync); + AsyncReadEntry entry = (AsyncReadEntry)cache.getOrCreateAsyncReadEntry(graph.processor, r, isSync); if(entry == null) { - graph.processor.schedule(Integer.MIN_VALUE, new SessionTask(r, graph.processor.THREAD_MASK+1, -1) { + graph.processor.schedule(new SessionTask(false) { @Override public void run(int thread) { try { @@ -586,7 +585,7 @@ public class QueryCache extends QueryCacheBase { } } - Types getOrCreateTypes(int r) throws DatabaseException { + Types getOrCreateTypes(QueryProcessor processor, int r) throws DatabaseException { Types existing = null; synchronized(typesMap) { existing = (Types)typesMap.get(r); @@ -603,7 +602,7 @@ public class QueryCache extends QueryCacheBase { return existing; } } - if(existing.isPending()) waitPending(existing); + if(existing.isPending()) waitPending(processor, existing); return existing; } @@ -619,7 +618,7 @@ public class QueryCache extends QueryCacheBase { Types.computeForEach(graph, r, null, procedure); return; } - Types entry = (Types)cache.getOrCreateTypes(r); + Types entry = (Types)cache.getOrCreateTypes(graph.processor, r); InternalProcedure procedure_ = procedure != null ? procedure : emptyProcedureTypes; ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false); if(entry.isReady()) entry.performFromCache(graph, procedure_); @@ -630,7 +629,7 @@ public class QueryCache extends QueryCacheBase { } } - ChildMap getOrCreateChildMap(int r) throws DatabaseException { + ChildMap getOrCreateChildMap(QueryProcessor processor, int r) throws DatabaseException { ChildMap existing = null; synchronized(childMapMap) { existing = (ChildMap)childMapMap.get(r); @@ -647,7 +646,7 @@ public class QueryCache extends QueryCacheBase { return existing; } } - if(existing.isPending()) waitPending(existing); + if(existing.isPending()) waitPending(processor, existing); return existing; } @@ -663,7 +662,7 @@ public class QueryCache extends QueryCacheBase { ChildMap.computeForEach(graph, r, null, procedure); return; } - ChildMap entry = (ChildMap)cache.getOrCreateChildMap(r); + ChildMap entry = (ChildMap)cache.getOrCreateChildMap(graph.processor, r); InternalProcedure> procedure_ = procedure != null ? procedure : emptyProcedureChildMap; ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false); if(entry.isReady()) entry.performFromCache(graph, procedure_); @@ -674,15 +673,15 @@ public class QueryCache extends QueryCacheBase { } } - AssertedStatements getOrCreateAssertedStatements(int r1, int r2) throws DatabaseException { - AssertedStatements existing = null; - synchronized(assertedStatementsMap) { - existing = (AssertedStatements)assertedStatementsMap.get(r1,r2); + TypeHierarchy getOrCreateTypeHierarchy(QueryProcessor processor, int r) throws DatabaseException { + TypeHierarchy existing = null; + synchronized(typeHierarchyMap) { + existing = (TypeHierarchy)typeHierarchyMap.get(r); if(existing == null) { - existing = new AssertedStatements(r1,r2); + existing = new TypeHierarchy(r); existing.clearResult(querySupport); existing.setPending(); - assertedStatementsMap.put(keyR2(r1,r2), existing); + typeHierarchyMap.put(keyR(r), existing); size++; return existing; } @@ -691,38 +690,42 @@ public class QueryCache extends QueryCacheBase { return existing; } } - if(existing.isPending()) waitPending(existing); + if(existing.isPending()) waitPending(processor, existing); return existing; } - void remove(AssertedStatements entry) { - synchronized(assertedStatementsMap) { - assertedStatementsMap.remove(entry.id); + void remove(TypeHierarchy entry) { + synchronized(typeHierarchyMap) { + typeHierarchyMap.remove(entry.id); } } - public static void runnerAssertedStatements(ReadGraphImpl graph, int r1, int r2, CacheEntry parent, ListenerBase listener, final TripleIntProcedure procedure) throws DatabaseException { + public static void runnerTypeHierarchy(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, final InternalProcedure procedure) throws DatabaseException { QueryCache cache = graph.processor.cache; - AssertedStatements entry = (AssertedStatements)cache.getOrCreateAssertedStatements(r1,r2); - TripleIntProcedure procedure_ = procedure != null ? procedure : emptyProcedureAssertedStatements; + if(parent == null && listener == null && !cache.shouldCache(graph.processor, r)) { + TypeHierarchy.computeForEach(graph, r, null, procedure); + return; + } + TypeHierarchy entry = (TypeHierarchy)cache.getOrCreateTypeHierarchy(graph.processor, r); + InternalProcedure procedure_ = procedure != null ? procedure : emptyProcedureTypeHierarchy; ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false); if(entry.isReady()) entry.performFromCache(graph, procedure_); else { assert(entry.isPending()); - entry.compute(graph, procedure_); + TypeHierarchy.computeForEach(graph, r, entry, 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); + SuperTypes getOrCreateSuperTypes(QueryProcessor processor, int r) throws DatabaseException { + SuperTypes existing = null; + synchronized(superTypesMap) { + existing = (SuperTypes)superTypesMap.get(r); if(existing == null) { - existing = new AssertedPredicates(r); + existing = new SuperTypes(r); existing.clearResult(querySupport); existing.setPending(); - assertedPredicatesMap.put(keyR(r), existing); + superTypesMap.put(keyR(r), existing); size++; return existing; } @@ -731,38 +734,42 @@ public class QueryCache extends QueryCacheBase { return existing; } } - if(existing.isPending()) waitPending(existing); + if(existing.isPending()) waitPending(processor, existing); return existing; } - void remove(AssertedPredicates entry) { - synchronized(assertedPredicatesMap) { - assertedPredicatesMap.remove(entry.id); + void remove(SuperTypes entry) { + synchronized(superTypesMap) { + superTypesMap.remove(entry.id); } } - public static void runnerAssertedPredicates(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, final IntProcedure procedure) throws DatabaseException { + public static void runnerSuperTypes(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, final InternalProcedure procedure) throws DatabaseException { QueryCache cache = graph.processor.cache; - AssertedPredicates entry = (AssertedPredicates)cache.getOrCreateAssertedPredicates(r); - IntProcedure procedure_ = procedure != null ? procedure : emptyProcedureAssertedPredicates; + if(parent == null && listener == null && !cache.shouldCache(graph.processor, r)) { + SuperTypes.computeForEach(graph, r, null, procedure); + return; + } + SuperTypes entry = (SuperTypes)cache.getOrCreateSuperTypes(graph.processor, r); + InternalProcedure procedure_ = procedure != null ? procedure : emptyProcedureSuperTypes; ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false); if(entry.isReady()) entry.performFromCache(graph, procedure_); else { assert(entry.isPending()); - entry.compute(graph, procedure_); + SuperTypes.computeForEach(graph, r, entry, 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); + SuperRelations getOrCreateSuperRelations(QueryProcessor processor, int r) throws DatabaseException { + SuperRelations existing = null; + synchronized(superRelationsMap) { + existing = (SuperRelations)superRelationsMap.get(r); if(existing == null) { - existing = new DirectSuperRelations(r); + existing = new SuperRelations(r); existing.clearResult(querySupport); existing.setPending(); - directSuperRelationsMap.put(keyR(r), existing); + superRelationsMap.put(keyR(r), existing); size++; return existing; } @@ -771,38 +778,42 @@ public class QueryCache extends QueryCacheBase { return existing; } } - if(existing.isPending()) waitPending(existing); + if(existing.isPending()) waitPending(processor, existing); return existing; } - void remove(DirectSuperRelations entry) { - synchronized(directSuperRelationsMap) { - directSuperRelationsMap.remove(entry.id); + void remove(SuperRelations entry) { + synchronized(superRelationsMap) { + superRelationsMap.remove(entry.id); } } - public static void runnerDirectSuperRelations(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, final IntProcedure procedure) throws DatabaseException { + public static void runnerSuperRelations(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, final InternalProcedure procedure) throws DatabaseException { QueryCache cache = graph.processor.cache; - DirectSuperRelations entry = (DirectSuperRelations)cache.getOrCreateDirectSuperRelations(r); - IntProcedure procedure_ = procedure != null ? procedure : emptyProcedureDirectSuperRelations; + if(parent == null && listener == null && !cache.shouldCache(graph.processor, r)) { + SuperRelations.computeForEach(graph, r, null, procedure); + return; + } + SuperRelations entry = (SuperRelations)cache.getOrCreateSuperRelations(graph.processor, r); + InternalProcedure procedure_ = procedure != null ? procedure : emptyProcedureSuperRelations; ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false); if(entry.isReady()) entry.performFromCache(graph, procedure_); else { assert(entry.isPending()); - entry.compute(graph, procedure_); + SuperRelations.computeForEach(graph, r, entry, 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); + AssertedPredicates getOrCreateAssertedPredicates(QueryProcessor processor, int r) throws DatabaseException { + AssertedPredicates existing = null; + synchronized(assertedPredicatesMap) { + existing = (AssertedPredicates)assertedPredicatesMap.get(r); if(existing == null) { - existing = new SuperTypes(r); + existing = new AssertedPredicates(r); existing.clearResult(querySupport); existing.setPending(); - superTypesMap.put(keyR(r), existing); + assertedPredicatesMap.put(keyR(r), existing); size++; return existing; } @@ -811,20 +822,20 @@ public class QueryCache extends QueryCacheBase { return existing; } } - if(existing.isPending()) waitPending(existing); + if(existing.isPending()) waitPending(processor, existing); return existing; } - void remove(SuperTypes entry) { - synchronized(superTypesMap) { - superTypesMap.remove(entry.id); + void remove(AssertedPredicates entry) { + synchronized(assertedPredicatesMap) { + assertedPredicatesMap.remove(entry.id); } } - public static void runnerSuperTypes(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, final InternalProcedure procedure) throws DatabaseException { + public static void runnerAssertedPredicates(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, final IntProcedure procedure) throws DatabaseException { QueryCache cache = graph.processor.cache; - SuperTypes entry = (SuperTypes)cache.getOrCreateSuperTypes(r); - InternalProcedure procedure_ = procedure != null ? procedure : emptyProcedureSuperTypes; + AssertedPredicates entry = (AssertedPredicates)cache.getOrCreateAssertedPredicates(graph.processor, r); + IntProcedure procedure_ = procedure != null ? procedure : emptyProcedureAssertedPredicates; ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false); if(entry.isReady()) entry.performFromCache(graph, procedure_); else { @@ -834,15 +845,15 @@ public class QueryCache extends QueryCacheBase { } } - TypeHierarchy getOrCreateTypeHierarchy(int r) throws DatabaseException { - TypeHierarchy existing = null; - synchronized(typeHierarchyMap) { - existing = (TypeHierarchy)typeHierarchyMap.get(r); + AssertedStatements getOrCreateAssertedStatements(QueryProcessor processor, int r1, int r2) throws DatabaseException { + AssertedStatements existing = null; + synchronized(assertedStatementsMap) { + existing = (AssertedStatements)assertedStatementsMap.get(r1,r2); if(existing == null) { - existing = new TypeHierarchy(r); + existing = new AssertedStatements(r1,r2); existing.clearResult(querySupport); existing.setPending(); - typeHierarchyMap.put(keyR(r), existing); + assertedStatementsMap.put(keyR2(r1,r2), existing); size++; return existing; } @@ -851,20 +862,20 @@ public class QueryCache extends QueryCacheBase { return existing; } } - if(existing.isPending()) waitPending(existing); + if(existing.isPending()) waitPending(processor, existing); return existing; } - void remove(TypeHierarchy entry) { - synchronized(typeHierarchyMap) { - typeHierarchyMap.remove(entry.id); + void remove(AssertedStatements entry) { + synchronized(assertedStatementsMap) { + assertedStatementsMap.remove(entry.id); } } - public static void runnerTypeHierarchy(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, final InternalProcedure procedure) throws DatabaseException { + public static void runnerAssertedStatements(ReadGraphImpl graph, int r1, int r2, CacheEntry parent, ListenerBase listener, final TripleIntProcedure procedure) throws DatabaseException { QueryCache cache = graph.processor.cache; - TypeHierarchy entry = (TypeHierarchy)cache.getOrCreateTypeHierarchy(r); - InternalProcedure procedure_ = procedure != null ? procedure : emptyProcedureTypeHierarchy; + AssertedStatements entry = (AssertedStatements)cache.getOrCreateAssertedStatements(graph.processor, r1,r2); + TripleIntProcedure procedure_ = procedure != null ? procedure : emptyProcedureAssertedStatements; ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false); if(entry.isReady()) entry.performFromCache(graph, procedure_); else { @@ -874,15 +885,15 @@ public class QueryCache extends QueryCacheBase { } } - SuperRelations getOrCreateSuperRelations(int r) throws DatabaseException { - SuperRelations existing = null; - synchronized(superRelationsMap) { - existing = (SuperRelations)superRelationsMap.get(r); + DirectSuperRelations getOrCreateDirectSuperRelations(QueryProcessor processor, int r) throws DatabaseException { + DirectSuperRelations existing = null; + synchronized(directSuperRelationsMap) { + existing = (DirectSuperRelations)directSuperRelationsMap.get(r); if(existing == null) { - existing = new SuperRelations(r); + existing = new DirectSuperRelations(r); existing.clearResult(querySupport); existing.setPending(); - superRelationsMap.put(keyR(r), existing); + directSuperRelationsMap.put(keyR(r), existing); size++; return existing; } @@ -891,20 +902,20 @@ public class QueryCache extends QueryCacheBase { return existing; } } - if(existing.isPending()) waitPending(existing); + if(existing.isPending()) waitPending(processor, existing); return existing; } - void remove(SuperRelations entry) { - synchronized(superRelationsMap) { - superRelationsMap.remove(entry.id); + void remove(DirectSuperRelations entry) { + synchronized(directSuperRelationsMap) { + directSuperRelationsMap.remove(entry.id); } } - public static void runnerSuperRelations(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, final InternalProcedure procedure) throws DatabaseException { + public static void runnerDirectSuperRelations(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, final IntProcedure procedure) throws DatabaseException { QueryCache cache = graph.processor.cache; - SuperRelations entry = (SuperRelations)cache.getOrCreateSuperRelations(r); - InternalProcedure procedure_ = procedure != null ? procedure : emptyProcedureSuperRelations; + DirectSuperRelations entry = (DirectSuperRelations)cache.getOrCreateDirectSuperRelations(graph.processor, r); + IntProcedure procedure_ = procedure != null ? procedure : emptyProcedureDirectSuperRelations; ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false); if(entry.isReady()) entry.performFromCache(graph, procedure_); else { @@ -914,7 +925,7 @@ public class QueryCache extends QueryCacheBase { } } - MultiReadEntry getOrCreateMultiReadEntry(MultiRead r) throws DatabaseException { + MultiReadEntry getOrCreateMultiReadEntry(QueryProcessor processor, MultiRead r) throws DatabaseException { MultiReadEntry existing = null; synchronized(multiReadEntryMap) { existing = (MultiReadEntry)multiReadEntryMap.get(r); @@ -931,7 +942,7 @@ public class QueryCache extends QueryCacheBase { return existing; } } - if(existing.isPending()) waitPending(existing); + if(existing.isPending()) waitPending(processor, existing); return existing; } @@ -941,10 +952,10 @@ public class QueryCache extends QueryCacheBase { } } - public static void runnerMultiReadEntry(ReadGraphImpl graph, MultiRead r, CacheEntry parent, ListenerBase listener, final AsyncMultiProcedure procedure) throws DatabaseException { + public static void runnerMultiReadEntry(ReadGraphImpl graph, MultiRead r, CacheEntry parent, ListenerBase listener, final SyncMultiProcedure procedure) throws DatabaseException { QueryCache cache = graph.processor.cache; - MultiReadEntry entry = (MultiReadEntry)cache.getOrCreateMultiReadEntry(r); - AsyncMultiProcedure procedure_ = procedure != null ? procedure : emptyProcedureMultiReadEntry; + MultiReadEntry entry = (MultiReadEntry)cache.getOrCreateMultiReadEntry(graph.processor, r); + SyncMultiProcedure procedure_ = procedure != null ? procedure : emptyProcedureMultiReadEntry; ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false); if(entry.isReady()) entry.performFromCache(graph, procedure_); else { @@ -954,7 +965,7 @@ public class QueryCache extends QueryCacheBase { } } - AsyncMultiReadEntry getOrCreateAsyncMultiReadEntry(AsyncMultiRead r) throws DatabaseException { + AsyncMultiReadEntry getOrCreateAsyncMultiReadEntry(QueryProcessor processor, AsyncMultiRead r) throws DatabaseException { AsyncMultiReadEntry existing = null; synchronized(asyncMultiReadEntryMap) { existing = (AsyncMultiReadEntry)asyncMultiReadEntryMap.get(r); @@ -971,7 +982,7 @@ public class QueryCache extends QueryCacheBase { return existing; } } - if(existing.isPending()) waitPending(existing); + if(existing.isPending()) waitPending(processor, existing); return existing; } @@ -983,7 +994,7 @@ public class QueryCache extends QueryCacheBase { public static void runnerAsyncMultiReadEntry(ReadGraphImpl graph, AsyncMultiRead r, CacheEntry parent, ListenerBase listener, final AsyncMultiProcedure procedure) throws DatabaseException { QueryCache cache = graph.processor.cache; - AsyncMultiReadEntry entry = (AsyncMultiReadEntry)cache.getOrCreateAsyncMultiReadEntry(r); + AsyncMultiReadEntry entry = (AsyncMultiReadEntry)cache.getOrCreateAsyncMultiReadEntry(graph.processor, r); AsyncMultiProcedure procedure_ = procedure != null ? procedure : emptyProcedureAsyncMultiReadEntry; ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false); if(entry.isReady()) entry.performFromCache(graph, procedure_); @@ -994,7 +1005,7 @@ public class QueryCache extends QueryCacheBase { } } - ExternalReadEntry getOrCreateExternalReadEntry(ExternalRead r) throws DatabaseException { + ExternalReadEntry getOrCreateExternalReadEntry(QueryProcessor processor, ExternalRead r) throws DatabaseException { ExternalReadEntry existing = null; synchronized(externalReadEntryMap) { existing = (ExternalReadEntry)externalReadEntryMap.get(r); @@ -1011,7 +1022,7 @@ public class QueryCache extends QueryCacheBase { return existing; } } - if(existing.isPending()) waitPending(existing); + if(existing.isPending()) waitPending(processor, existing); return existing; } @@ -1023,7 +1034,7 @@ public class QueryCache extends QueryCacheBase { public static void runnerExternalReadEntry(ReadGraphImpl graph, ExternalRead r, CacheEntry parent, ListenerBase listener, final AsyncProcedure procedure) throws DatabaseException { QueryCache cache = graph.processor.cache; - ExternalReadEntry entry = (ExternalReadEntry)cache.getOrCreateExternalReadEntry(r); + ExternalReadEntry entry = (ExternalReadEntry)cache.getOrCreateExternalReadEntry(graph.processor, r); AsyncProcedure procedure_ = procedure != null ? procedure : emptyProcedureExternalReadEntry; ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false); if(entry.isReady()) entry.performFromCache(graph, procedure_);