X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.db.impl%2Fsrc%2Forg%2Fsimantics%2Fdb%2Fimpl%2Fquery%2FQueryCache.java;h=48d5646c27eaa3aaeee3ac636f78e165d968e7c9;hp=7b591abb7fd80e062308ce3df88c86e872cfe27e;hb=1dfc44ff89362fb4500ee9427432541b92d1953f;hpb=9f0fd59be54719b1fe9322d8fd37e4950857308c 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 7b591abb7..48d5646c2 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 @@ -19,11 +19,14 @@ import org.simantics.db.request.Read; public class QueryCache extends QueryCacheBase { + // Using QueryChaching breaks Diagram Editor (and probably something else). + private static final boolean SINGLE = false; + public QueryCache(QuerySupport querySupport, int threads) { super(querySupport, threads); } - Objects getOrCreateObjects(QueryProcessor processor, int r1, int r2) throws DatabaseException { + Objects getOrCreateObjects(ReadGraphImpl graph, int r1, int r2) throws DatabaseException { Objects existing = null; synchronized(objectsMap) { existing = (Objects)objectsMap.get(r1,r2); @@ -40,7 +43,7 @@ public class QueryCache extends QueryCacheBase { return existing; } } - if(existing.isPending()) waitPending(processor, existing); + if(existing.isPending()) waitPending(graph, existing); return existing; } @@ -53,21 +56,34 @@ public class QueryCache extends QueryCacheBase { public static void runnerObjects(ReadGraphImpl graph, int r1, int r2, CacheEntry parent, ListenerBase listener, final IntProcedure procedure) throws DatabaseException { QueryCache cache = graph.processor.cache; if(parent == null && listener == null && !cache.shouldCache(graph.processor, r1,r2)) { + if (SINGLE) { + Objects e = cache.peekObjects(r1,r2); + if (e != null && e.isReady()) { + e.performFromCache(graph, procedure); + return; + } + } Objects.computeForEach(graph, r1,r2, null, procedure); return; } - Objects entry = (Objects)cache.getOrCreateObjects(graph.processor, r1,r2); + Objects entry = (Objects)cache.getOrCreateObjects(graph, 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_); else { assert(entry.isPending()); - Objects.computeForEach(graph, r1,r2, entry, procedure_); - if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult()); + Objects.computeForEach(graph, r1,r2, entry, procedure_); + if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult()); } } - Statements getOrCreateStatements(QueryProcessor processor, int r1, int r2) throws DatabaseException { + private Objects peekObjects(int r1, int r2) { + synchronized(objectsMap) { + return (Objects) objectsMap.get(r1,r2); + } + } + + Statements getOrCreateStatements(ReadGraphImpl graph, int r1, int r2) throws DatabaseException { Statements existing = null; synchronized(statementsMap) { existing = (Statements)statementsMap.get(r1,r2); @@ -84,7 +100,7 @@ public class QueryCache extends QueryCacheBase { return existing; } } - if(existing.isPending()) waitPending(processor, existing); + if(existing.isPending()) waitPending(graph, existing); return existing; } @@ -97,21 +113,34 @@ public class QueryCache extends QueryCacheBase { public static void runnerStatements(ReadGraphImpl graph, int r1, int r2, CacheEntry parent, ListenerBase listener, final TripleIntProcedure procedure) throws DatabaseException { QueryCache cache = graph.processor.cache; if(parent == null && listener == null && !cache.shouldCache(graph.processor, r1,r2)) { + if (SINGLE) { + Statements e = cache.peekStatements(r1,r2); + if (e != null && e.isReady()) { + e.performFromCache(graph, procedure); + return; + } + } Statements.computeForEach(graph, r1,r2, null, procedure); return; } - Statements entry = (Statements)cache.getOrCreateStatements(graph.processor, r1,r2); + Statements entry = (Statements)cache.getOrCreateStatements(graph, 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_); else { assert(entry.isPending()); - Statements.computeForEach(graph, r1,r2, entry, procedure_); - if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult()); + Statements.computeForEach(graph, r1,r2, entry, procedure_); + if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult()); } } - DirectObjects getOrCreateDirectObjects(QueryProcessor processor, int r1, int r2) throws DatabaseException { + private Statements peekStatements(int r1, int r2) { + synchronized(statementsMap) { + return (Statements) statementsMap.get(r1,r2); + } + } + + DirectObjects getOrCreateDirectObjects(ReadGraphImpl graph, int r1, int r2) throws DatabaseException { DirectObjects existing = null; synchronized(directObjectsMap) { existing = (DirectObjects)directObjectsMap.get(r1,r2); @@ -128,7 +157,7 @@ public class QueryCache extends QueryCacheBase { return existing; } } - if(existing.isPending()) waitPending(processor, existing); + if(existing.isPending()) waitPending(graph, existing); return existing; } @@ -141,21 +170,34 @@ public class QueryCache extends QueryCacheBase { public static void runnerDirectObjects(ReadGraphImpl graph, int r1, int r2, CacheEntry parent, ListenerBase listener, final IntProcedure procedure) throws DatabaseException { QueryCache cache = graph.processor.cache; if(parent == null && listener == null && !cache.shouldCache(graph.processor, r1,r2)) { + if (SINGLE) { + DirectObjects e = cache.peekDirectObjects(r1,r2); + if (e != null && e.isReady()) { + e.performFromCache(graph, procedure); + return; + } + } DirectObjects.computeForEach(graph, r1,r2, null, procedure); return; } - DirectObjects entry = (DirectObjects)cache.getOrCreateDirectObjects(graph.processor, r1,r2); + DirectObjects entry = (DirectObjects)cache.getOrCreateDirectObjects(graph, 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_); else { assert(entry.isPending()); - DirectObjects.computeForEach(graph, r1,r2, entry, procedure_); - if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult()); + DirectObjects.computeForEach(graph, r1,r2, entry, procedure_); + if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult()); } } - RelationInfoQuery getOrCreateRelationInfoQuery(QueryProcessor processor, int r) throws DatabaseException { + private DirectObjects peekDirectObjects(int r1, int r2) { + synchronized(directObjectsMap) { + return (DirectObjects) directObjectsMap.get(r1,r2); + } + } + + RelationInfoQuery getOrCreateRelationInfoQuery(ReadGraphImpl graph, int r) throws DatabaseException { RelationInfoQuery existing = null; synchronized(relationInfoQueryMap) { existing = (RelationInfoQuery)relationInfoQueryMap.get(r); @@ -172,7 +214,7 @@ public class QueryCache extends QueryCacheBase { return existing; } } - if(existing.isPending()) waitPending(processor, existing); + if(existing.isPending()) waitPending(graph, existing); return existing; } @@ -185,21 +227,34 @@ public class QueryCache extends QueryCacheBase { public static void runnerRelationInfoQuery(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, final InternalProcedure procedure) throws DatabaseException { QueryCache cache = graph.processor.cache; if(parent == null && listener == null && !cache.shouldCache(graph.processor, r)) { + if (SINGLE) { + RelationInfoQuery e = cache.peekRelationInfoQuery(r); + if (e != null && e.isReady()) { + e.performFromCache(graph, procedure); + return; + } + } RelationInfoQuery.computeForEach(graph, r, null, procedure); return; } - RelationInfoQuery entry = (RelationInfoQuery)cache.getOrCreateRelationInfoQuery(graph.processor, r); + RelationInfoQuery entry = (RelationInfoQuery)cache.getOrCreateRelationInfoQuery(graph, r); InternalProcedure procedure_ = procedure != null ? procedure : emptyProcedureRelationInfoQuery; ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false); if(entry.isReady()) entry.performFromCache(graph, procedure_); else { assert(entry.isPending()); - RelationInfoQuery.computeForEach(graph, r, entry, procedure_); - if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult()); + RelationInfoQuery.computeForEach(graph, r, entry, procedure_); + if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult()); } } - URIToResource getOrCreateURIToResource(QueryProcessor processor, String id) throws DatabaseException { + private RelationInfoQuery peekRelationInfoQuery(int r) { + synchronized(relationInfoQueryMap) { + return (RelationInfoQuery) relationInfoQueryMap.get(r); + } + } + + URIToResource getOrCreateURIToResource(ReadGraphImpl graph, String id) throws DatabaseException { URIToResource existing = null; synchronized(uRIToResourceMap) { existing = (URIToResource)uRIToResourceMap.get(id); @@ -216,7 +271,7 @@ public class QueryCache extends QueryCacheBase { return existing; } } - if(existing.isPending()) waitPending(processor, existing); + if(existing.isPending()) waitPending(graph, existing); return existing; } @@ -229,21 +284,34 @@ public class QueryCache extends QueryCacheBase { public static void runnerURIToResource(ReadGraphImpl graph, String id, CacheEntry parent, ListenerBase listener, final InternalProcedure procedure) throws DatabaseException { QueryCache cache = graph.processor.cache; if(parent == null && listener == null && !cache.shouldCache(graph.processor, id)) { + if (SINGLE) { + URIToResource e = cache.peekURIToResource(id); + if (e != null && e.isReady()) { + e.performFromCache(graph, procedure); + return; + } + } URIToResource.computeForEach(graph, id, null, procedure); return; } - URIToResource entry = (URIToResource)cache.getOrCreateURIToResource(graph.processor, id); + URIToResource entry = (URIToResource)cache.getOrCreateURIToResource(graph, id); InternalProcedure procedure_ = procedure != null ? procedure : emptyProcedureURIToResource; ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false); if(entry.isReady()) entry.performFromCache(graph, procedure_); else { assert(entry.isPending()); - URIToResource.computeForEach(graph, id, entry, procedure_); - if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult()); + URIToResource.computeForEach(graph, id, entry, procedure_); + if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult()); } } - ValueQuery getOrCreateValueQuery(QueryProcessor processor, int r) throws DatabaseException { + private URIToResource peekURIToResource(String id) { + synchronized(uRIToResourceMap) { + return (URIToResource) uRIToResourceMap.get(id); + } + } + + ValueQuery getOrCreateValueQuery(ReadGraphImpl graph, int r) throws DatabaseException { ValueQuery existing = null; synchronized(valueQueryMap) { existing = (ValueQuery)valueQueryMap.get(r); @@ -260,7 +328,7 @@ public class QueryCache extends QueryCacheBase { return existing; } } - if(existing.isPending()) waitPending(processor, existing); + if(existing.isPending()) waitPending(graph, existing); return existing; } @@ -273,21 +341,34 @@ public class QueryCache extends QueryCacheBase { public static void runnerValueQuery(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, final InternalProcedure procedure) throws DatabaseException { QueryCache cache = graph.processor.cache; if(parent == null && listener == null && !cache.shouldCache(graph.processor, r)) { + if (SINGLE) { + ValueQuery e = cache.peekValueQuery(r); + if (e != null && e.isReady()) { + e.performFromCache(graph, procedure); + return; + } + } ValueQuery.computeForEach(graph, r, null, procedure); return; } - ValueQuery entry = (ValueQuery)cache.getOrCreateValueQuery(graph.processor, r); + ValueQuery entry = (ValueQuery)cache.getOrCreateValueQuery(graph, r); InternalProcedure procedure_ = procedure != null ? procedure : emptyProcedureValueQuery; ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false); if(entry.isReady()) entry.performFromCache(graph, procedure_); else { assert(entry.isPending()); - ValueQuery.computeForEach(graph, r, entry, procedure_); - if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult()); + ValueQuery.computeForEach(graph, r, entry, procedure_); + if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult()); } } - OrderedSet getOrCreateOrderedSet(QueryProcessor processor, int r) throws DatabaseException { + private ValueQuery peekValueQuery(int r) { + synchronized(valueQueryMap) { + return (ValueQuery) valueQueryMap.get(r); + } + } + + OrderedSet getOrCreateOrderedSet(ReadGraphImpl graph, int r) throws DatabaseException { OrderedSet existing = null; synchronized(orderedSetMap) { existing = (OrderedSet)orderedSetMap.get(r); @@ -304,7 +385,7 @@ public class QueryCache extends QueryCacheBase { return existing; } } - if(existing.isPending()) waitPending(processor, existing); + if(existing.isPending()) waitPending(graph, existing); return existing; } @@ -317,21 +398,34 @@ public class QueryCache extends QueryCacheBase { public static void runnerOrderedSet(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, final IntProcedure procedure) throws DatabaseException { QueryCache cache = graph.processor.cache; if(parent == null && listener == null && !cache.shouldCache(graph.processor, r)) { + if (SINGLE) { + OrderedSet e = cache.peekOrderedSet(r); + if (e != null && e.isReady()) { + e.performFromCache(graph, procedure); + return; + } + } OrderedSet.computeForEach(graph, r, null, procedure); return; } - OrderedSet entry = (OrderedSet)cache.getOrCreateOrderedSet(graph.processor, r); + OrderedSet entry = (OrderedSet)cache.getOrCreateOrderedSet(graph, r); IntProcedure procedure_ = procedure != null ? procedure : emptyProcedureOrderedSet; ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false); if(entry.isReady()) entry.performFromCache(graph, procedure_); else { assert(entry.isPending()); - OrderedSet.computeForEach(graph, r, entry, procedure_); - if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult()); + OrderedSet.computeForEach(graph, r, entry, procedure_); + if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult()); } } - PrincipalTypes getOrCreatePrincipalTypes(QueryProcessor processor, int r) throws DatabaseException { + private OrderedSet peekOrderedSet(int r) { + synchronized(orderedSetMap) { + return (OrderedSet) orderedSetMap.get(r); + } + } + + PrincipalTypes getOrCreatePrincipalTypes(ReadGraphImpl graph, int r) throws DatabaseException { PrincipalTypes existing = null; synchronized(principalTypesMap) { existing = (PrincipalTypes)principalTypesMap.get(r); @@ -348,7 +442,7 @@ public class QueryCache extends QueryCacheBase { return existing; } } - if(existing.isPending()) waitPending(processor, existing); + if(existing.isPending()) waitPending(graph, existing); return existing; } @@ -361,21 +455,34 @@ public class QueryCache extends QueryCacheBase { public static void runnerPrincipalTypes(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, final IntProcedure procedure) throws DatabaseException { QueryCache cache = graph.processor.cache; if(parent == null && listener == null && !cache.shouldCache(graph.processor, r)) { + if (SINGLE) { + PrincipalTypes e = cache.peekPrincipalTypes(r); + if (e != null && e.isReady()) { + e.performFromCache(graph, procedure); + return; + } + } PrincipalTypes.computeForEach(graph, r, null, procedure); return; } - PrincipalTypes entry = (PrincipalTypes)cache.getOrCreatePrincipalTypes(graph.processor, r); + PrincipalTypes entry = (PrincipalTypes)cache.getOrCreatePrincipalTypes(graph, r); IntProcedure procedure_ = procedure != null ? procedure : emptyProcedurePrincipalTypes; ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false); if(entry.isReady()) entry.performFromCache(graph, procedure_); else { assert(entry.isPending()); - PrincipalTypes.computeForEach(graph, r, entry, procedure_); - if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult()); + PrincipalTypes.computeForEach(graph, r, entry, procedure_); + if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult()); + } + } + + private PrincipalTypes peekPrincipalTypes(int r) { + synchronized(principalTypesMap) { + return (PrincipalTypes) principalTypesMap.get(r); } } - DirectPredicates getOrCreateDirectPredicates(QueryProcessor processor, int r) throws DatabaseException { + DirectPredicates getOrCreateDirectPredicates(ReadGraphImpl graph, int r) throws DatabaseException { DirectPredicates existing = null; synchronized(directPredicatesMap) { existing = (DirectPredicates)directPredicatesMap.get(r); @@ -392,7 +499,7 @@ public class QueryCache extends QueryCacheBase { return existing; } } - if(existing.isPending()) waitPending(processor, existing); + if(existing.isPending()) waitPending(graph, existing); return existing; } @@ -405,21 +512,34 @@ public class QueryCache extends QueryCacheBase { public static void runnerDirectPredicates(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, final InternalProcedure procedure) throws DatabaseException { QueryCache cache = graph.processor.cache; if(parent == null && listener == null && !cache.shouldCache(graph.processor, r)) { + if (SINGLE) { + DirectPredicates e = cache.peekDirectPredicates(r); + if (e != null && e.isReady()) { + e.performFromCache(graph, procedure); + return; + } + } DirectPredicates.computeForEach(graph, r, null, procedure); return; } - DirectPredicates entry = (DirectPredicates)cache.getOrCreateDirectPredicates(graph.processor, r); + DirectPredicates entry = (DirectPredicates)cache.getOrCreateDirectPredicates(graph, r); InternalProcedure procedure_ = procedure != null ? procedure : emptyProcedureDirectPredicates; ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false); if(entry.isReady()) entry.performFromCache(graph, procedure_); else { assert(entry.isPending()); - DirectPredicates.computeForEach(graph, r, entry, procedure_); - if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult()); + DirectPredicates.computeForEach(graph, r, entry, procedure_); + if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult()); + } + } + + private DirectPredicates peekDirectPredicates(int r) { + synchronized(directPredicatesMap) { + return (DirectPredicates) directPredicatesMap.get(r); } } - Predicates getOrCreatePredicates(QueryProcessor processor, int r) throws DatabaseException { + Predicates getOrCreatePredicates(ReadGraphImpl graph, int r) throws DatabaseException { Predicates existing = null; synchronized(predicatesMap) { existing = (Predicates)predicatesMap.get(r); @@ -436,7 +556,7 @@ public class QueryCache extends QueryCacheBase { return existing; } } - if(existing.isPending()) waitPending(processor, existing); + if(existing.isPending()) waitPending(graph, existing); return existing; } @@ -449,21 +569,34 @@ public class QueryCache extends QueryCacheBase { public static void runnerPredicates(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, final InternalProcedure procedure) throws DatabaseException { QueryCache cache = graph.processor.cache; if(parent == null && listener == null && !cache.shouldCache(graph.processor, r)) { + if (SINGLE) { + Predicates e = cache.peekPredicates(r); + if (e != null && e.isReady()) { + e.performFromCache(graph, procedure); + return; + } + } Predicates.computeForEach(graph, r, null, procedure); return; } - Predicates entry = (Predicates)cache.getOrCreatePredicates(graph.processor, r); + Predicates entry = (Predicates)cache.getOrCreatePredicates(graph, r); InternalProcedure procedure_ = procedure != null ? procedure : emptyProcedurePredicates; ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false); if(entry.isReady()) entry.performFromCache(graph, procedure_); else { assert(entry.isPending()); - Predicates.computeForEach(graph, r, entry, procedure_); - if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult()); + Predicates.computeForEach(graph, r, entry, procedure_); + if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult()); + } + } + + private Predicates peekPredicates(int r) { + synchronized(predicatesMap) { + return (Predicates) predicatesMap.get(r); } } - ReadEntry getOrCreateReadEntry(QueryProcessor processor, Read r, boolean isSync) throws DatabaseException { + ReadEntry getOrCreateReadEntry(ReadGraphImpl graph, Read r, boolean needsToBlock) throws DatabaseException { ReadEntry existing = null; synchronized(readEntryMap) { existing = (ReadEntry)readEntryMap.get(r); @@ -481,11 +614,12 @@ public class QueryCache extends QueryCacheBase { } } if(existing.isPending()) { - if(isSync) waitPending(processor, existing); - else return null; + if(needsToBlock) waitPending(graph, existing); + else return null; } return existing; } + void remove(ReadEntry entry) { synchronized(readEntryMap) { @@ -493,38 +627,50 @@ public class QueryCache extends QueryCacheBase { } } - public static void runnerReadEntry(ReadGraphImpl graph, Read r, CacheEntry parent, ListenerBase listener, final AsyncProcedure procedure, boolean isSync) throws DatabaseException { + public static Object runnerReadEntry(ReadGraphImpl graph, Read r, CacheEntry parent, ListenerBase listener, final AsyncProcedure procedure, final boolean needsToBlock) 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 (SINGLE) { + ReadEntry e = cache.peekReadEntry(r); + if (e != null && e.isReady()) { + return e.performFromCache(graph, procedure); + } + } + return ReadEntry.computeForEach(graph, r, null, procedure); } - ReadEntry entry = (ReadEntry)cache.getOrCreateReadEntry(graph.processor, r, isSync); + ReadEntry entry = (ReadEntry)cache.getOrCreateReadEntry(graph, r, needsToBlock); if(entry == null) { - graph.processor.schedule(new SessionTask(false) { + graph.processor.schedule(new SessionTask(graph) { @Override - public void run(int thread) { + public void run0(int thread) { try { - assert(!isSync); - runnerReadEntry(graph, r, parent, listener, procedure, isSync); + runnerReadEntry(graph, r, parent, listener, procedure, needsToBlock); } catch (DatabaseException e) { Logger.defaultLogError(e); } } }); - return; + return null; } AsyncProcedure procedure_ = procedure != null ? procedure : emptyProcedureReadEntry; ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false); - if(entry.isReady()) entry.performFromCache(graph, procedure_); + if(entry.isReady()) return entry.performFromCache(graph, procedure_); else { assert(entry.isPending()); - ReadEntry.computeForEach(graph, r, entry, procedure_); - if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult()); + Object result = ReadEntry.computeForEach(graph, r, entry, procedure_); + if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult()); + return result; + } + } + + + private ReadEntry peekReadEntry(Read r) { + synchronized(readEntryMap) { + return (ReadEntry) readEntryMap.get(r); } } - AsyncReadEntry getOrCreateAsyncReadEntry(QueryProcessor processor, AsyncRead r, boolean isSync) throws DatabaseException { + AsyncReadEntry getOrCreateAsyncReadEntry(ReadGraphImpl graph, AsyncRead r, boolean needsToBlock) throws DatabaseException { AsyncReadEntry existing = null; synchronized(asyncReadEntryMap) { existing = (AsyncReadEntry)asyncReadEntryMap.get(r); @@ -542,11 +688,12 @@ public class QueryCache extends QueryCacheBase { } } if(existing.isPending()) { - if(isSync) waitPending(processor, existing); - else return null; + if(needsToBlock) waitPending(graph, existing); + else return null; } return existing; } + void remove(AsyncReadEntry entry) { synchronized(asyncReadEntryMap) { @@ -554,38 +701,50 @@ public class QueryCache extends QueryCacheBase { } } - public static void runnerAsyncReadEntry(ReadGraphImpl graph, AsyncRead r, CacheEntry parent, ListenerBase listener, final AsyncProcedure procedure, boolean isSync) throws DatabaseException { + public static Object runnerAsyncReadEntry(ReadGraphImpl graph, AsyncRead r, CacheEntry parent, ListenerBase listener, final AsyncProcedure procedure, final boolean needsToBlock) 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 (SINGLE) { + AsyncReadEntry e = cache.peekAsyncReadEntry(r); + if (e != null && e.isReady()) { + return e.performFromCache(graph, procedure); + } + } + return AsyncReadEntry.computeForEach(graph, r, null, procedure, needsToBlock); } - AsyncReadEntry entry = (AsyncReadEntry)cache.getOrCreateAsyncReadEntry(graph.processor, r, isSync); + AsyncReadEntry entry = (AsyncReadEntry)cache.getOrCreateAsyncReadEntry(graph, r, needsToBlock); if(entry == null) { - graph.processor.schedule(new SessionTask(false) { + graph.processor.schedule(new SessionTask(graph) { @Override - public void run(int thread) { + public void run0(int thread) { try { - assert(!isSync); - runnerAsyncReadEntry(graph, r, parent, listener, procedure, isSync); + runnerAsyncReadEntry(graph, r, parent, listener, procedure, needsToBlock); } catch (DatabaseException e) { Logger.defaultLogError(e); } } }); - return; + return null; } AsyncProcedure procedure_ = procedure != null ? procedure : emptyProcedureAsyncReadEntry; ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false); - if(entry.isReady()) entry.performFromCache(graph, procedure_); + if(entry.isReady()) return entry.performFromCache(graph, procedure_); else { assert(entry.isPending()); - AsyncReadEntry.computeForEach(graph, r, entry, procedure_); - if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult()); + Object result = AsyncReadEntry.computeForEach(graph, r, entry, procedure_, needsToBlock); + if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult()); + return result; + } + } + + + private AsyncReadEntry peekAsyncReadEntry(AsyncRead r) { + synchronized(asyncReadEntryMap) { + return (AsyncReadEntry) asyncReadEntryMap.get(r); } } - Types getOrCreateTypes(QueryProcessor processor, int r) throws DatabaseException { + Types getOrCreateTypes(ReadGraphImpl graph, int r) throws DatabaseException { Types existing = null; synchronized(typesMap) { existing = (Types)typesMap.get(r); @@ -602,7 +761,7 @@ public class QueryCache extends QueryCacheBase { return existing; } } - if(existing.isPending()) waitPending(processor, existing); + if(existing.isPending()) waitPending(graph, existing); return existing; } @@ -615,21 +774,34 @@ public class QueryCache extends QueryCacheBase { public static void runnerTypes(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, final InternalProcedure procedure) throws DatabaseException { QueryCache cache = graph.processor.cache; if(parent == null && listener == null && !cache.shouldCache(graph.processor, r)) { + if (SINGLE) { + Types e = cache.peekTypes(r); + if (e != null && e.isReady()) { + e.performFromCache(graph, procedure); + return; + } + } Types.computeForEach(graph, r, null, procedure); return; } - Types entry = (Types)cache.getOrCreateTypes(graph.processor, r); + Types entry = (Types)cache.getOrCreateTypes(graph, r); InternalProcedure procedure_ = procedure != null ? procedure : emptyProcedureTypes; ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false); if(entry.isReady()) entry.performFromCache(graph, procedure_); else { assert(entry.isPending()); - Types.computeForEach(graph, r, entry, procedure_); - if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult()); + Types.computeForEach(graph, r, entry, procedure_); + if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult()); } } - ChildMap getOrCreateChildMap(QueryProcessor processor, int r) throws DatabaseException { + private Types peekTypes(int r) { + synchronized(typesMap) { + return (Types) typesMap.get(r); + } + } + + ChildMap getOrCreateChildMap(ReadGraphImpl graph, int r) throws DatabaseException { ChildMap existing = null; synchronized(childMapMap) { existing = (ChildMap)childMapMap.get(r); @@ -646,7 +818,7 @@ public class QueryCache extends QueryCacheBase { return existing; } } - if(existing.isPending()) waitPending(processor, existing); + if(existing.isPending()) waitPending(graph, existing); return existing; } @@ -659,21 +831,34 @@ public class QueryCache extends QueryCacheBase { public static void runnerChildMap(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, final InternalProcedure> procedure) throws DatabaseException { QueryCache cache = graph.processor.cache; if(parent == null && listener == null && !cache.shouldCache(graph.processor, r)) { + if (SINGLE) { + ChildMap e = cache.peekChildMap(r); + if (e != null && e.isReady()) { + e.performFromCache(graph, procedure); + return; + } + } ChildMap.computeForEach(graph, r, null, procedure); return; } - ChildMap entry = (ChildMap)cache.getOrCreateChildMap(graph.processor, r); + ChildMap entry = (ChildMap)cache.getOrCreateChildMap(graph, r); InternalProcedure> procedure_ = procedure != null ? procedure : emptyProcedureChildMap; ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false); if(entry.isReady()) entry.performFromCache(graph, procedure_); else { assert(entry.isPending()); - ChildMap.computeForEach(graph, r, entry, procedure_); - if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult()); + ChildMap.computeForEach(graph, r, entry, procedure_); + if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult()); } } - TypeHierarchy getOrCreateTypeHierarchy(QueryProcessor processor, int r) throws DatabaseException { + private ChildMap peekChildMap(int r) { + synchronized(childMapMap) { + return (ChildMap) childMapMap.get(r); + } + } + + TypeHierarchy getOrCreateTypeHierarchy(ReadGraphImpl graph, int r) throws DatabaseException { TypeHierarchy existing = null; synchronized(typeHierarchyMap) { existing = (TypeHierarchy)typeHierarchyMap.get(r); @@ -690,7 +875,7 @@ public class QueryCache extends QueryCacheBase { return existing; } } - if(existing.isPending()) waitPending(processor, existing); + if(existing.isPending()) waitPending(graph, existing); return existing; } @@ -703,21 +888,34 @@ public class QueryCache extends QueryCacheBase { public static void runnerTypeHierarchy(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, final InternalProcedure procedure) throws DatabaseException { QueryCache cache = graph.processor.cache; if(parent == null && listener == null && !cache.shouldCache(graph.processor, r)) { + if (SINGLE) { + TypeHierarchy e = cache.peekTypeHierarchy(r); + if (e != null && e.isReady()) { + e.performFromCache(graph, procedure); + return; + } + } TypeHierarchy.computeForEach(graph, r, null, procedure); return; } - TypeHierarchy entry = (TypeHierarchy)cache.getOrCreateTypeHierarchy(graph.processor, r); + TypeHierarchy entry = (TypeHierarchy)cache.getOrCreateTypeHierarchy(graph, 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()); - TypeHierarchy.computeForEach(graph, r, entry, procedure_); - if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult()); + TypeHierarchy.computeForEach(graph, r, entry, procedure_); + if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult()); + } + } + + private TypeHierarchy peekTypeHierarchy(int r) { + synchronized(typeHierarchyMap) { + return (TypeHierarchy) typeHierarchyMap.get(r); } } - SuperTypes getOrCreateSuperTypes(QueryProcessor processor, int r) throws DatabaseException { + SuperTypes getOrCreateSuperTypes(ReadGraphImpl graph, int r) throws DatabaseException { SuperTypes existing = null; synchronized(superTypesMap) { existing = (SuperTypes)superTypesMap.get(r); @@ -734,7 +932,7 @@ public class QueryCache extends QueryCacheBase { return existing; } } - if(existing.isPending()) waitPending(processor, existing); + if(existing.isPending()) waitPending(graph, existing); return existing; } @@ -747,21 +945,34 @@ public class QueryCache extends QueryCacheBase { public static void runnerSuperTypes(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, final InternalProcedure procedure) throws DatabaseException { QueryCache cache = graph.processor.cache; if(parent == null && listener == null && !cache.shouldCache(graph.processor, r)) { + if (SINGLE) { + SuperTypes e = cache.peekSuperTypes(r); + if (e != null && e.isReady()) { + e.performFromCache(graph, procedure); + return; + } + } SuperTypes.computeForEach(graph, r, null, procedure); return; } - SuperTypes entry = (SuperTypes)cache.getOrCreateSuperTypes(graph.processor, r); + SuperTypes entry = (SuperTypes)cache.getOrCreateSuperTypes(graph, 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()); - SuperTypes.computeForEach(graph, r, entry, procedure_); - if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult()); + SuperTypes.computeForEach(graph, r, entry, procedure_); + if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult()); } } - SuperRelations getOrCreateSuperRelations(QueryProcessor processor, int r) throws DatabaseException { + private SuperTypes peekSuperTypes(int r) { + synchronized(superTypesMap) { + return (SuperTypes) superTypesMap.get(r); + } + } + + SuperRelations getOrCreateSuperRelations(ReadGraphImpl graph, int r) throws DatabaseException { SuperRelations existing = null; synchronized(superRelationsMap) { existing = (SuperRelations)superRelationsMap.get(r); @@ -778,7 +989,7 @@ public class QueryCache extends QueryCacheBase { return existing; } } - if(existing.isPending()) waitPending(processor, existing); + if(existing.isPending()) waitPending(graph, existing); return existing; } @@ -791,21 +1002,34 @@ public class QueryCache extends QueryCacheBase { public static void runnerSuperRelations(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, final InternalProcedure procedure) throws DatabaseException { QueryCache cache = graph.processor.cache; if(parent == null && listener == null && !cache.shouldCache(graph.processor, r)) { + if (SINGLE) { + SuperRelations e = cache.peekSuperRelations(r); + if (e != null && e.isReady()) { + e.performFromCache(graph, procedure); + return; + } + } SuperRelations.computeForEach(graph, r, null, procedure); return; } - SuperRelations entry = (SuperRelations)cache.getOrCreateSuperRelations(graph.processor, r); + SuperRelations entry = (SuperRelations)cache.getOrCreateSuperRelations(graph, 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()); - SuperRelations.computeForEach(graph, r, entry, procedure_); - if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult()); + SuperRelations.computeForEach(graph, r, entry, procedure_); + if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult()); + } + } + + private SuperRelations peekSuperRelations(int r) { + synchronized(superRelationsMap) { + return (SuperRelations) superRelationsMap.get(r); } } - AssertedPredicates getOrCreateAssertedPredicates(QueryProcessor processor, int r) throws DatabaseException { + AssertedPredicates getOrCreateAssertedPredicates(ReadGraphImpl graph, int r) throws DatabaseException { AssertedPredicates existing = null; synchronized(assertedPredicatesMap) { existing = (AssertedPredicates)assertedPredicatesMap.get(r); @@ -822,7 +1046,7 @@ public class QueryCache extends QueryCacheBase { return existing; } } - if(existing.isPending()) waitPending(processor, existing); + if(existing.isPending()) waitPending(graph, existing); return existing; } @@ -834,18 +1058,24 @@ public class QueryCache extends QueryCacheBase { public static void runnerAssertedPredicates(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, final IntProcedure procedure) throws DatabaseException { QueryCache cache = graph.processor.cache; - AssertedPredicates entry = (AssertedPredicates)cache.getOrCreateAssertedPredicates(graph.processor, r); + AssertedPredicates entry = (AssertedPredicates)cache.getOrCreateAssertedPredicates(graph, 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 { assert(entry.isPending()); - entry.compute(graph, procedure_); - if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult()); + entry.compute(graph, procedure_); + if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult()); } } - AssertedStatements getOrCreateAssertedStatements(QueryProcessor processor, int r1, int r2) throws DatabaseException { + private AssertedPredicates peekAssertedPredicates(int r) { + synchronized(assertedPredicatesMap) { + return (AssertedPredicates) assertedPredicatesMap.get(r); + } + } + + AssertedStatements getOrCreateAssertedStatements(ReadGraphImpl graph, int r1, int r2) throws DatabaseException { AssertedStatements existing = null; synchronized(assertedStatementsMap) { existing = (AssertedStatements)assertedStatementsMap.get(r1,r2); @@ -862,7 +1092,7 @@ public class QueryCache extends QueryCacheBase { return existing; } } - if(existing.isPending()) waitPending(processor, existing); + if(existing.isPending()) waitPending(graph, existing); return existing; } @@ -874,18 +1104,24 @@ public class QueryCache extends QueryCacheBase { public static void runnerAssertedStatements(ReadGraphImpl graph, int r1, int r2, CacheEntry parent, ListenerBase listener, final TripleIntProcedure procedure) throws DatabaseException { QueryCache cache = graph.processor.cache; - AssertedStatements entry = (AssertedStatements)cache.getOrCreateAssertedStatements(graph.processor, r1,r2); + AssertedStatements entry = (AssertedStatements)cache.getOrCreateAssertedStatements(graph, 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 { assert(entry.isPending()); - entry.compute(graph, procedure_); - if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult()); + entry.compute(graph, procedure_); + if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult()); + } + } + + private AssertedStatements peekAssertedStatements(int r1, int r2) { + synchronized(assertedStatementsMap) { + return (AssertedStatements) assertedStatementsMap.get(r1,r2); } } - DirectSuperRelations getOrCreateDirectSuperRelations(QueryProcessor processor, int r) throws DatabaseException { + DirectSuperRelations getOrCreateDirectSuperRelations(ReadGraphImpl graph, int r) throws DatabaseException { DirectSuperRelations existing = null; synchronized(directSuperRelationsMap) { existing = (DirectSuperRelations)directSuperRelationsMap.get(r); @@ -902,7 +1138,7 @@ public class QueryCache extends QueryCacheBase { return existing; } } - if(existing.isPending()) waitPending(processor, existing); + if(existing.isPending()) waitPending(graph, existing); return existing; } @@ -914,18 +1150,24 @@ public class QueryCache extends QueryCacheBase { public static void runnerDirectSuperRelations(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, final IntProcedure procedure) throws DatabaseException { QueryCache cache = graph.processor.cache; - DirectSuperRelations entry = (DirectSuperRelations)cache.getOrCreateDirectSuperRelations(graph.processor, r); + DirectSuperRelations entry = (DirectSuperRelations)cache.getOrCreateDirectSuperRelations(graph, 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 { assert(entry.isPending()); - entry.compute(graph, procedure_); - if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult()); + entry.compute(graph, procedure_); + if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult()); } } - MultiReadEntry getOrCreateMultiReadEntry(QueryProcessor processor, MultiRead r) throws DatabaseException { + private DirectSuperRelations peekDirectSuperRelations(int r) { + synchronized(directSuperRelationsMap) { + return (DirectSuperRelations) directSuperRelationsMap.get(r); + } + } + + MultiReadEntry getOrCreateMultiReadEntry(ReadGraphImpl graph, MultiRead r) throws DatabaseException { MultiReadEntry existing = null; synchronized(multiReadEntryMap) { existing = (MultiReadEntry)multiReadEntryMap.get(r); @@ -942,7 +1184,7 @@ public class QueryCache extends QueryCacheBase { return existing; } } - if(existing.isPending()) waitPending(processor, existing); + if(existing.isPending()) waitPending(graph, existing); return existing; } @@ -954,18 +1196,24 @@ public class QueryCache extends QueryCacheBase { 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(graph.processor, r); + MultiReadEntry entry = (MultiReadEntry)cache.getOrCreateMultiReadEntry(graph, 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 { assert(entry.isPending()); - entry.compute(graph, procedure_); - if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult()); + entry.compute(graph, procedure_); + if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult()); } } - AsyncMultiReadEntry getOrCreateAsyncMultiReadEntry(QueryProcessor processor, AsyncMultiRead r) throws DatabaseException { + private MultiReadEntry peekMultiReadEntry(MultiRead r) { + synchronized(multiReadEntryMap) { + return (MultiReadEntry) multiReadEntryMap.get(r); + } + } + + AsyncMultiReadEntry getOrCreateAsyncMultiReadEntry(ReadGraphImpl graph, AsyncMultiRead r) throws DatabaseException { AsyncMultiReadEntry existing = null; synchronized(asyncMultiReadEntryMap) { existing = (AsyncMultiReadEntry)asyncMultiReadEntryMap.get(r); @@ -982,7 +1230,7 @@ public class QueryCache extends QueryCacheBase { return existing; } } - if(existing.isPending()) waitPending(processor, existing); + if(existing.isPending()) waitPending(graph, existing); return existing; } @@ -994,23 +1242,29 @@ 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(graph.processor, r); + AsyncMultiReadEntry entry = (AsyncMultiReadEntry)cache.getOrCreateAsyncMultiReadEntry(graph, r); AsyncMultiProcedure procedure_ = procedure != null ? procedure : emptyProcedureAsyncMultiReadEntry; 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_); - if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult()); + entry.compute(graph, procedure_); + if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult()); } } - ExternalReadEntry getOrCreateExternalReadEntry(QueryProcessor processor, ExternalRead r) throws DatabaseException { + private AsyncMultiReadEntry peekAsyncMultiReadEntry(AsyncMultiRead r) { + synchronized(asyncMultiReadEntryMap) { + return (AsyncMultiReadEntry) asyncMultiReadEntryMap.get(r); + } + } + + ExternalReadEntry getOrCreateExternalReadEntry(ReadGraphImpl graph, ExternalRead r) throws DatabaseException { ExternalReadEntry existing = null; synchronized(externalReadEntryMap) { existing = (ExternalReadEntry)externalReadEntryMap.get(r); if(existing == null) { - existing = new ExternalReadEntry(r); + existing = new ExternalReadEntry(r, graph); existing.clearResult(querySupport); existing.setPending(); externalReadEntryMap.put(id(r), existing); @@ -1022,9 +1276,10 @@ public class QueryCache extends QueryCacheBase { return existing; } } - if(existing.isPending()) waitPending(processor, existing); + if(existing.isPending()) waitPending(graph, existing); return existing; } + void remove(ExternalReadEntry entry) { synchronized(externalReadEntryMap) { @@ -1034,14 +1289,20 @@ 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(graph.processor, r); + ExternalReadEntry entry = (ExternalReadEntry)cache.getOrCreateExternalReadEntry(graph, r); AsyncProcedure procedure_ = procedure != null ? procedure : emptyProcedureExternalReadEntry; 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_); - if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult()); + entry.compute(graph, procedure_); + if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult()); + } + } + + private ExternalReadEntry peekExternalReadEntry(ExternalRead r) { + synchronized(externalReadEntryMap) { + return (ExternalReadEntry) externalReadEntryMap.get(r); } }