1 package org.simantics.db.impl.query;
3 import org.simantics.db.RelationInfo;
4 import org.simantics.db.exception.DatabaseException;
5 import org.simantics.db.impl.graph.ReadGraphImpl;
6 import org.simantics.db.impl.procedure.InternalProcedure;
7 import org.simantics.db.procedure.AsyncMultiProcedure;
8 import org.simantics.db.procedure.AsyncProcedure;
9 import org.simantics.db.procedure.ListenerBase;
10 import org.simantics.db.request.AsyncMultiRead;
11 import org.simantics.db.request.AsyncRead;
12 import org.simantics.db.request.ExternalRead;
13 import org.simantics.db.request.MultiRead;
14 import org.simantics.db.request.Read;
16 import gnu.trove.map.hash.TObjectIntHashMap;
18 public class QueryCache extends QueryCacheBase {
20 public QueryCache(QuerySupport querySupport, int threads) {
21 super(querySupport, threads);
24 Objects getOrCreateObjects(int r1, int r2) throws DatabaseException {
25 Objects existing = null;
26 synchronized(objectsMap) {
27 existing = (Objects)objectsMap.get(r1,r2);
28 if(existing == null) {
29 existing = new Objects(r1,r2);
30 existing.clearResult(querySupport);
31 existing.setPending();
32 objectsMap.put(keyR2(r1,r2), existing);
35 if(existing.requiresComputation()) {
36 existing.setPending();
40 if(existing.isPending()) waitPending(existing);
44 void remove(Objects entry) {
45 synchronized(objectsMap) {
46 objectsMap.remove(entry.id);
50 static void runnerObjects(ReadGraphImpl graph, int r1, int r2, CacheEntry parent, ListenerBase listener, IntProcedure procedure) throws DatabaseException {
51 if(parent == null && listener == null) {
52 Objects.computeForEach(graph, r1,r2, null, procedure);
55 QueryCache cache = graph.processor.cache;
56 if(procedure == null) procedure = emptyProcedureObjects;
57 Objects entry = (Objects)cache.getOrCreateObjects(r1,r2);
58 ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure, false);
59 if(entry.isReady()) entry.performFromCache(graph, procedure);
61 Objects.computeForEach(graph, r1,r2, entry, procedure);
62 if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());
66 Statements getOrCreateStatements(int r1, int r2) throws DatabaseException {
67 Statements existing = null;
68 synchronized(statementsMap) {
69 existing = (Statements)statementsMap.get(r1,r2);
70 if(existing == null) {
71 existing = new Statements(r1,r2);
72 existing.clearResult(querySupport);
73 existing.setPending();
74 statementsMap.put(keyR2(r1,r2), existing);
77 if(existing.requiresComputation()) {
78 existing.setPending();
82 if(existing.isPending()) waitPending(existing);
86 void remove(Statements entry) {
87 synchronized(statementsMap) {
88 statementsMap.remove(entry.id);
92 static void runnerStatements(ReadGraphImpl graph, int r1, int r2, CacheEntry parent, ListenerBase listener, TripleIntProcedure procedure) throws DatabaseException {
93 if(parent == null && listener == null) {
94 Statements.computeForEach(graph, r1,r2, null, procedure);
97 QueryCache cache = graph.processor.cache;
98 if(procedure == null) procedure = emptyProcedureStatements;
99 Statements entry = (Statements)cache.getOrCreateStatements(r1,r2);
100 ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure, false);
101 if(entry.isReady()) entry.performFromCache(graph, procedure);
103 Statements.computeForEach(graph, r1,r2, entry, procedure);
104 if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());
108 DirectObjects getOrCreateDirectObjects(int r1, int r2) throws DatabaseException {
109 DirectObjects existing = null;
110 synchronized(directObjectsMap) {
111 existing = (DirectObjects)directObjectsMap.get(r1,r2);
112 if(existing == null) {
113 existing = new DirectObjects(r1,r2);
114 existing.clearResult(querySupport);
115 existing.setPending();
116 directObjectsMap.put(keyR2(r1,r2), existing);
119 if(existing.requiresComputation()) {
120 existing.setPending();
124 if(existing.isPending()) waitPending(existing);
128 void remove(DirectObjects entry) {
129 synchronized(directObjectsMap) {
130 directObjectsMap.remove(entry.id);
134 static void runnerDirectObjects(ReadGraphImpl graph, int r1, int r2, CacheEntry parent, ListenerBase listener, IntProcedure procedure) throws DatabaseException {
135 if(parent == null && listener == null) {
136 DirectObjects.computeForEach(graph, r1,r2, null, procedure);
139 QueryCache cache = graph.processor.cache;
140 if(procedure == null) procedure = emptyProcedureDirectObjects;
141 DirectObjects entry = (DirectObjects)cache.getOrCreateDirectObjects(r1,r2);
142 ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure, false);
143 if(entry.isReady()) entry.performFromCache(graph, procedure);
145 DirectObjects.computeForEach(graph, r1,r2, entry, procedure);
146 if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());
150 RelationInfoQuery getOrCreateRelationInfoQuery(int r) throws DatabaseException {
151 RelationInfoQuery existing = null;
152 synchronized(relationInfoQueryMap) {
153 existing = (RelationInfoQuery)relationInfoQueryMap.get(r);
154 if(existing == null) {
155 existing = new RelationInfoQuery(r);
156 existing.clearResult(querySupport);
157 existing.setPending();
158 relationInfoQueryMap.put(keyR(r), existing);
161 if(existing.requiresComputation()) {
162 existing.setPending();
166 if(existing.isPending()) waitPending(existing);
170 void remove(RelationInfoQuery entry) {
171 synchronized(relationInfoQueryMap) {
172 relationInfoQueryMap.remove(entry.id);
176 static void runnerRelationInfoQuery(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, InternalProcedure<RelationInfo> procedure) throws DatabaseException {
177 if(parent == null && listener == null) {
178 RelationInfoQuery.computeForEach(graph, r, null, procedure);
181 QueryCache cache = graph.processor.cache;
182 if(procedure == null) procedure = emptyProcedureRelationInfoQuery;
183 RelationInfoQuery entry = (RelationInfoQuery)cache.getOrCreateRelationInfoQuery(r);
184 ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure, false);
185 if(entry.isReady()) entry.performFromCache(graph, procedure);
187 RelationInfoQuery.computeForEach(graph, r, entry, procedure);
188 if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());
192 URIToResource getOrCreateURIToResource(String id) throws DatabaseException {
193 URIToResource existing = null;
194 synchronized(uRIToResourceMap) {
195 existing = (URIToResource)uRIToResourceMap.get(id);
196 if(existing == null) {
197 existing = new URIToResource(id);
198 existing.clearResult(querySupport);
199 existing.setPending();
200 uRIToResourceMap.put(keyID(id), existing);
203 if(existing.requiresComputation()) {
204 existing.setPending();
208 if(existing.isPending()) waitPending(existing);
212 void remove(URIToResource entry) {
213 synchronized(uRIToResourceMap) {
214 uRIToResourceMap.remove(entry.id);
218 static void runnerURIToResource(ReadGraphImpl graph, String id, CacheEntry parent, ListenerBase listener, InternalProcedure<Integer> procedure) throws DatabaseException {
219 if(parent == null && listener == null) {
220 URIToResource.computeForEach(graph, id, null, procedure);
223 QueryCache cache = graph.processor.cache;
224 if(procedure == null) procedure = emptyProcedureURIToResource;
225 URIToResource entry = (URIToResource)cache.getOrCreateURIToResource(id);
226 ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure, false);
227 if(entry.isReady()) entry.performFromCache(graph, procedure);
229 URIToResource.computeForEach(graph, id, entry, procedure);
230 if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());
234 ValueQuery getOrCreateValueQuery(int r) throws DatabaseException {
235 ValueQuery existing = null;
236 synchronized(valueQueryMap) {
237 existing = (ValueQuery)valueQueryMap.get(r);
238 if(existing == null) {
239 existing = new ValueQuery(r);
240 existing.clearResult(querySupport);
241 existing.setPending();
242 valueQueryMap.put(keyR(r), existing);
245 if(existing.requiresComputation()) {
246 existing.setPending();
250 if(existing.isPending()) waitPending(existing);
254 void remove(ValueQuery entry) {
255 synchronized(valueQueryMap) {
256 valueQueryMap.remove(entry.id);
260 static void runnerValueQuery(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, InternalProcedure<byte[]> procedure) throws DatabaseException {
261 if(parent == null && listener == null) {
262 ValueQuery.computeForEach(graph, r, null, procedure);
265 QueryCache cache = graph.processor.cache;
266 if(procedure == null) procedure = emptyProcedureValueQuery;
267 ValueQuery entry = (ValueQuery)cache.getOrCreateValueQuery(r);
268 ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure, false);
269 if(entry.isReady()) entry.performFromCache(graph, procedure);
271 ValueQuery.computeForEach(graph, r, entry, procedure);
272 if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());
276 OrderedSet getOrCreateOrderedSet(int r) throws DatabaseException {
277 OrderedSet existing = null;
278 synchronized(orderedSetMap) {
279 existing = (OrderedSet)orderedSetMap.get(r);
280 if(existing == null) {
281 existing = new OrderedSet(r);
282 existing.clearResult(querySupport);
283 existing.setPending();
284 orderedSetMap.put(keyR(r), existing);
287 if(existing.requiresComputation()) {
288 existing.setPending();
292 if(existing.isPending()) waitPending(existing);
296 void remove(OrderedSet entry) {
297 synchronized(orderedSetMap) {
298 orderedSetMap.remove(entry.id);
302 static void runnerOrderedSet(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, IntProcedure procedure) throws DatabaseException {
303 if(parent == null && listener == null) {
304 OrderedSet.computeForEach(graph, r, null, procedure);
307 QueryCache cache = graph.processor.cache;
308 if(procedure == null) procedure = emptyProcedureOrderedSet;
309 OrderedSet entry = (OrderedSet)cache.getOrCreateOrderedSet(r);
310 ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure, false);
311 if(entry.isReady()) entry.performFromCache(graph, procedure);
313 OrderedSet.computeForEach(graph, r, entry, procedure);
314 if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());
318 PrincipalTypes getOrCreatePrincipalTypes(int r) throws DatabaseException {
319 PrincipalTypes existing = null;
320 synchronized(principalTypesMap) {
321 existing = (PrincipalTypes)principalTypesMap.get(r);
322 if(existing == null) {
323 existing = new PrincipalTypes(r);
324 existing.clearResult(querySupport);
325 existing.setPending();
326 principalTypesMap.put(keyR(r), existing);
329 if(existing.requiresComputation()) {
330 existing.setPending();
334 if(existing.isPending()) waitPending(existing);
338 void remove(PrincipalTypes entry) {
339 synchronized(principalTypesMap) {
340 principalTypesMap.remove(entry.id);
344 static void runnerPrincipalTypes(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, IntProcedure procedure) throws DatabaseException {
345 if(parent == null && listener == null) {
346 PrincipalTypes.computeForEach(graph, r, null, procedure);
349 QueryCache cache = graph.processor.cache;
350 if(procedure == null) procedure = emptyProcedurePrincipalTypes;
351 PrincipalTypes entry = (PrincipalTypes)cache.getOrCreatePrincipalTypes(r);
352 ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure, false);
353 if(entry.isReady()) entry.performFromCache(graph, procedure);
355 PrincipalTypes.computeForEach(graph, r, entry, procedure);
356 if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());
360 DirectPredicates getOrCreateDirectPredicates(int r) throws DatabaseException {
361 DirectPredicates existing = null;
362 synchronized(directPredicatesMap) {
363 existing = (DirectPredicates)directPredicatesMap.get(r);
364 if(existing == null) {
365 existing = new DirectPredicates(r);
366 existing.clearResult(querySupport);
367 existing.setPending();
368 directPredicatesMap.put(keyR(r), existing);
371 if(existing.requiresComputation()) {
372 existing.setPending();
376 if(existing.isPending()) waitPending(existing);
380 void remove(DirectPredicates entry) {
381 synchronized(directPredicatesMap) {
382 directPredicatesMap.remove(entry.id);
386 static void runnerDirectPredicates(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, InternalProcedure<IntSet> procedure) throws DatabaseException {
387 if(parent == null && listener == null) {
388 DirectPredicates.computeForEach(graph, r, null, procedure);
391 QueryCache cache = graph.processor.cache;
392 if(procedure == null) procedure = emptyProcedureDirectPredicates;
393 DirectPredicates entry = (DirectPredicates)cache.getOrCreateDirectPredicates(r);
394 ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure, false);
395 if(entry.isReady()) entry.performFromCache(graph, procedure);
397 DirectPredicates.computeForEach(graph, r, entry, procedure);
398 if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());
402 Predicates getOrCreatePredicates(int r) throws DatabaseException {
403 Predicates existing = null;
404 synchronized(predicatesMap) {
405 existing = (Predicates)predicatesMap.get(r);
406 if(existing == null) {
407 existing = new Predicates(r);
408 existing.clearResult(querySupport);
409 existing.setPending();
410 predicatesMap.put(keyR(r), existing);
413 if(existing.requiresComputation()) {
414 existing.setPending();
418 if(existing.isPending()) waitPending(existing);
422 void remove(Predicates entry) {
423 synchronized(predicatesMap) {
424 predicatesMap.remove(entry.id);
428 static void runnerPredicates(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, InternalProcedure<IntSet> procedure) throws DatabaseException {
429 if(parent == null && listener == null) {
430 Predicates.computeForEach(graph, r, null, procedure);
433 QueryCache cache = graph.processor.cache;
434 if(procedure == null) procedure = emptyProcedurePredicates;
435 Predicates entry = (Predicates)cache.getOrCreatePredicates(r);
436 ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure, false);
437 if(entry.isReady()) entry.performFromCache(graph, procedure);
439 Predicates.computeForEach(graph, r, entry, procedure);
440 if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());
444 ReadEntry getOrCreateReadEntry(Read<?> r) throws DatabaseException {
445 ReadEntry existing = null;
446 synchronized(readEntryMap) {
447 existing = (ReadEntry)readEntryMap.get(r);
448 if(existing == null) {
449 existing = new ReadEntry(r);
450 existing.clearResult(querySupport);
451 existing.setPending();
452 readEntryMap.put(id(r), existing);
455 if(existing.requiresComputation()) {
456 existing.setPending();
460 if(existing.isPending()) waitPending(existing);
464 void remove(ReadEntry entry) {
465 synchronized(readEntryMap) {
466 readEntryMap.remove(entry.request);
470 static void runnerReadEntry(ReadGraphImpl graph, Read<?> r, CacheEntry parent, ListenerBase listener, AsyncProcedure procedure) throws DatabaseException {
471 if(parent == null && listener == null) {
472 ReadEntry.computeForEach(graph, r, null, procedure);
475 QueryCache cache = graph.processor.cache;
476 if(procedure == null) procedure = emptyProcedureReadEntry;
477 ReadEntry entry = (ReadEntry)cache.getOrCreateReadEntry(r);
478 ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure, false);
479 if(entry.isReady()) entry.performFromCache(graph, procedure);
481 ReadEntry.computeForEach(graph, r, entry, procedure);
482 if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());
486 Types getOrCreateTypes(int r) throws DatabaseException {
487 Types existing = null;
488 synchronized(typesMap) {
489 existing = (Types)typesMap.get(r);
490 if(existing == null) {
491 existing = new Types(r);
492 existing.clearResult(querySupport);
493 existing.setPending();
494 typesMap.put(keyR(r), existing);
497 if(existing.requiresComputation()) {
498 existing.setPending();
502 if(existing.isPending()) waitPending(existing);
506 void remove(Types entry) {
507 synchronized(typesMap) {
508 typesMap.remove(entry.id);
512 static void runnerTypes(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, InternalProcedure<IntSet> procedure) throws DatabaseException {
513 if(parent == null && listener == null) {
514 Types.computeForEach(graph, r, null, procedure);
517 QueryCache cache = graph.processor.cache;
518 if(procedure == null) procedure = emptyProcedureTypes;
519 Types entry = (Types)cache.getOrCreateTypes(r);
520 ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure, false);
521 if(entry.isReady()) entry.performFromCache(graph, procedure);
523 Types.computeForEach(graph, r, entry, procedure);
524 if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());
528 AssertedStatements getOrCreateAssertedStatements(int r1, int r2) throws DatabaseException {
529 AssertedStatements existing = null;
530 synchronized(assertedStatementsMap) {
531 existing = (AssertedStatements)assertedStatementsMap.get(r1,r2);
532 if(existing == null) {
533 existing = new AssertedStatements(r1,r2);
534 existing.clearResult(querySupport);
535 existing.setPending();
536 assertedStatementsMap.put(keyR2(r1,r2), existing);
539 if(existing.requiresComputation()) {
540 existing.setPending();
544 if(existing.isPending()) waitPending(existing);
548 void remove(AssertedStatements entry) {
549 synchronized(assertedStatementsMap) {
550 assertedStatementsMap.remove(entry.id);
554 static void runnerAssertedStatements(ReadGraphImpl graph, int r1, int r2, CacheEntry parent, ListenerBase listener, TripleIntProcedure procedure) throws DatabaseException {
555 QueryCache cache = graph.processor.cache;
556 if(procedure == null) procedure = emptyProcedureAssertedStatements;
557 AssertedStatements entry = (AssertedStatements)cache.getOrCreateAssertedStatements(r1,r2);
558 ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure, false);
559 if(entry.isReady()) entry.performFromCache(graph, procedure);
561 entry.compute(graph, procedure);
562 if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());
566 NamespaceIndex getOrCreateNamespaceIndex(String id) throws DatabaseException {
567 NamespaceIndex existing = null;
568 synchronized(namespaceIndexMap) {
569 existing = (NamespaceIndex)namespaceIndexMap.get(id);
570 if(existing == null) {
571 existing = new NamespaceIndex(id);
572 existing.clearResult(querySupport);
573 existing.setPending();
574 namespaceIndexMap.put(keyID(id), existing);
577 if(existing.requiresComputation()) {
578 existing.setPending();
582 if(existing.isPending()) waitPending(existing);
586 void remove(NamespaceIndex entry) {
587 synchronized(namespaceIndexMap) {
588 namespaceIndexMap.remove(entry.id);
592 static void runnerNamespaceIndex(ReadGraphImpl graph, String id, CacheEntry parent, ListenerBase listener, InternalProcedure<TObjectIntHashMap<String>> procedure) throws DatabaseException {
593 QueryCache cache = graph.processor.cache;
594 if(procedure == null) procedure = emptyProcedureNamespaceIndex;
595 NamespaceIndex entry = (NamespaceIndex)cache.getOrCreateNamespaceIndex(id);
596 ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure, false);
597 if(entry.isReady()) entry.performFromCache(graph, procedure);
599 entry.compute(graph, procedure);
600 if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());
604 AssertedPredicates getOrCreateAssertedPredicates(int r) throws DatabaseException {
605 AssertedPredicates existing = null;
606 synchronized(assertedPredicatesMap) {
607 existing = (AssertedPredicates)assertedPredicatesMap.get(r);
608 if(existing == null) {
609 existing = new AssertedPredicates(r);
610 existing.clearResult(querySupport);
611 existing.setPending();
612 assertedPredicatesMap.put(keyR(r), existing);
615 if(existing.requiresComputation()) {
616 existing.setPending();
620 if(existing.isPending()) waitPending(existing);
624 void remove(AssertedPredicates entry) {
625 synchronized(assertedPredicatesMap) {
626 assertedPredicatesMap.remove(entry.id);
630 static void runnerAssertedPredicates(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, IntProcedure procedure) throws DatabaseException {
631 QueryCache cache = graph.processor.cache;
632 if(procedure == null) procedure = emptyProcedureAssertedPredicates;
633 AssertedPredicates entry = (AssertedPredicates)cache.getOrCreateAssertedPredicates(r);
634 ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure, false);
635 if(entry.isReady()) entry.performFromCache(graph, procedure);
637 entry.compute(graph, procedure);
638 if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());
642 DirectSuperRelations getOrCreateDirectSuperRelations(int r) throws DatabaseException {
643 DirectSuperRelations existing = null;
644 synchronized(directSuperRelationsMap) {
645 existing = (DirectSuperRelations)directSuperRelationsMap.get(r);
646 if(existing == null) {
647 existing = new DirectSuperRelations(r);
648 existing.clearResult(querySupport);
649 existing.setPending();
650 directSuperRelationsMap.put(keyR(r), existing);
653 if(existing.requiresComputation()) {
654 existing.setPending();
658 if(existing.isPending()) waitPending(existing);
662 void remove(DirectSuperRelations entry) {
663 synchronized(directSuperRelationsMap) {
664 directSuperRelationsMap.remove(entry.id);
668 static void runnerDirectSuperRelations(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, IntProcedure procedure) throws DatabaseException {
669 QueryCache cache = graph.processor.cache;
670 if(procedure == null) procedure = emptyProcedureDirectSuperRelations;
671 DirectSuperRelations entry = (DirectSuperRelations)cache.getOrCreateDirectSuperRelations(r);
672 ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure, false);
673 if(entry.isReady()) entry.performFromCache(graph, procedure);
675 entry.compute(graph, procedure);
676 if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());
680 SuperTypes getOrCreateSuperTypes(int r) throws DatabaseException {
681 SuperTypes existing = null;
682 synchronized(superTypesMap) {
683 existing = (SuperTypes)superTypesMap.get(r);
684 if(existing == null) {
685 existing = new SuperTypes(r);
686 existing.clearResult(querySupport);
687 existing.setPending();
688 superTypesMap.put(keyR(r), existing);
691 if(existing.requiresComputation()) {
692 existing.setPending();
696 if(existing.isPending()) waitPending(existing);
700 void remove(SuperTypes entry) {
701 synchronized(superTypesMap) {
702 superTypesMap.remove(entry.id);
706 static void runnerSuperTypes(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, InternalProcedure<IntSet> procedure) throws DatabaseException {
707 QueryCache cache = graph.processor.cache;
708 if(procedure == null) procedure = emptyProcedureSuperTypes;
709 SuperTypes entry = (SuperTypes)cache.getOrCreateSuperTypes(r);
710 ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure, false);
711 if(entry.isReady()) entry.performFromCache(graph, procedure);
713 entry.compute(graph, procedure);
714 if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());
718 TypeHierarchy getOrCreateTypeHierarchy(int r) throws DatabaseException {
719 TypeHierarchy existing = null;
720 synchronized(typeHierarchyMap) {
721 existing = (TypeHierarchy)typeHierarchyMap.get(r);
722 if(existing == null) {
723 existing = new TypeHierarchy(r);
724 existing.clearResult(querySupport);
725 existing.setPending();
726 typeHierarchyMap.put(keyR(r), existing);
729 if(existing.requiresComputation()) {
730 existing.setPending();
734 if(existing.isPending()) waitPending(existing);
738 void remove(TypeHierarchy entry) {
739 synchronized(typeHierarchyMap) {
740 typeHierarchyMap.remove(entry.id);
744 static void runnerTypeHierarchy(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, InternalProcedure<IntSet> procedure) throws DatabaseException {
745 QueryCache cache = graph.processor.cache;
746 if(procedure == null) procedure = emptyProcedureTypeHierarchy;
747 TypeHierarchy entry = (TypeHierarchy)cache.getOrCreateTypeHierarchy(r);
748 ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure, false);
749 if(entry.isReady()) entry.performFromCache(graph, procedure);
751 entry.compute(graph, procedure);
752 if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());
756 SuperRelations getOrCreateSuperRelations(int r) throws DatabaseException {
757 SuperRelations existing = null;
758 synchronized(superRelationsMap) {
759 existing = (SuperRelations)superRelationsMap.get(r);
760 if(existing == null) {
761 existing = new SuperRelations(r);
762 existing.clearResult(querySupport);
763 existing.setPending();
764 superRelationsMap.put(keyR(r), existing);
767 if(existing.requiresComputation()) {
768 existing.setPending();
772 if(existing.isPending()) waitPending(existing);
776 void remove(SuperRelations entry) {
777 synchronized(superRelationsMap) {
778 superRelationsMap.remove(entry.id);
782 static void runnerSuperRelations(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, InternalProcedure<IntSet> procedure) throws DatabaseException {
783 QueryCache cache = graph.processor.cache;
784 if(procedure == null) procedure = emptyProcedureSuperRelations;
785 SuperRelations entry = (SuperRelations)cache.getOrCreateSuperRelations(r);
786 ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure, false);
787 if(entry.isReady()) entry.performFromCache(graph, procedure);
789 entry.compute(graph, procedure);
790 if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());
794 AsyncReadEntry getOrCreateAsyncReadEntry(AsyncRead<?> r) throws DatabaseException {
795 AsyncReadEntry existing = null;
796 synchronized(asyncReadEntryMap) {
797 existing = (AsyncReadEntry)asyncReadEntryMap.get(r);
798 if(existing == null) {
799 existing = new AsyncReadEntry(r);
800 existing.clearResult(querySupport);
801 existing.setPending();
802 asyncReadEntryMap.put(id(r), existing);
805 if(existing.requiresComputation()) {
806 existing.setPending();
810 if(existing.isPending()) waitPending(existing);
814 void remove(AsyncReadEntry entry) {
815 synchronized(asyncReadEntryMap) {
816 asyncReadEntryMap.remove(entry.request);
820 static void runnerAsyncReadEntry(ReadGraphImpl graph, AsyncRead<?> r, CacheEntry parent, ListenerBase listener, AsyncProcedure procedure) throws DatabaseException {
821 QueryCache cache = graph.processor.cache;
822 if(procedure == null) procedure = emptyProcedureAsyncReadEntry;
823 AsyncReadEntry entry = (AsyncReadEntry)cache.getOrCreateAsyncReadEntry(r);
824 ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure, false);
825 if(entry.isReady()) entry.performFromCache(graph, procedure);
827 entry.compute(graph, procedure);
828 if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());
832 MultiReadEntry getOrCreateMultiReadEntry(MultiRead<?> r) throws DatabaseException {
833 MultiReadEntry existing = null;
834 synchronized(multiReadEntryMap) {
835 existing = (MultiReadEntry)multiReadEntryMap.get(r);
836 if(existing == null) {
837 existing = new MultiReadEntry(r);
838 existing.clearResult(querySupport);
839 existing.setPending();
840 multiReadEntryMap.put(id(r), existing);
843 if(existing.requiresComputation()) {
844 existing.setPending();
848 if(existing.isPending()) waitPending(existing);
852 void remove(MultiReadEntry entry) {
853 synchronized(multiReadEntryMap) {
854 multiReadEntryMap.remove(entry.request);
858 static void runnerMultiReadEntry(ReadGraphImpl graph, MultiRead<?> r, CacheEntry parent, ListenerBase listener, AsyncMultiProcedure procedure) throws DatabaseException {
859 QueryCache cache = graph.processor.cache;
860 if(procedure == null) procedure = emptyProcedureMultiReadEntry;
861 MultiReadEntry entry = (MultiReadEntry)cache.getOrCreateMultiReadEntry(r);
862 ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure, false);
863 if(entry.isReady()) entry.performFromCache(graph, procedure);
865 entry.compute(graph, procedure);
866 if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());
870 AsyncMultiReadEntry getOrCreateAsyncMultiReadEntry(AsyncMultiRead<?> r) throws DatabaseException {
871 AsyncMultiReadEntry existing = null;
872 synchronized(asyncMultiReadEntryMap) {
873 existing = (AsyncMultiReadEntry)asyncMultiReadEntryMap.get(r);
874 if(existing == null) {
875 existing = new AsyncMultiReadEntry(r);
876 existing.clearResult(querySupport);
877 existing.setPending();
878 asyncMultiReadEntryMap.put(id(r), existing);
881 if(existing.requiresComputation()) {
882 existing.setPending();
886 if(existing.isPending()) waitPending(existing);
890 void remove(AsyncMultiReadEntry entry) {
891 synchronized(asyncMultiReadEntryMap) {
892 asyncMultiReadEntryMap.remove(entry.request);
896 static void runnerAsyncMultiReadEntry(ReadGraphImpl graph, AsyncMultiRead<?> r, CacheEntry parent, ListenerBase listener, AsyncMultiProcedure procedure) throws DatabaseException {
897 QueryCache cache = graph.processor.cache;
898 if(procedure == null) procedure = emptyProcedureAsyncMultiReadEntry;
899 AsyncMultiReadEntry entry = (AsyncMultiReadEntry)cache.getOrCreateAsyncMultiReadEntry(r);
900 ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure, false);
901 if(entry.isReady()) entry.performFromCache(graph, procedure);
903 entry.compute(graph, procedure);
904 if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());
908 ExternalReadEntry getOrCreateExternalReadEntry(ExternalRead<?> r) throws DatabaseException {
909 ExternalReadEntry existing = null;
910 synchronized(externalReadEntryMap) {
911 existing = (ExternalReadEntry)externalReadEntryMap.get(r);
912 if(existing == null) {
913 existing = new ExternalReadEntry(r);
914 existing.clearResult(querySupport);
915 existing.setPending();
916 externalReadEntryMap.put(id(r), existing);
919 if(existing.requiresComputation()) {
920 existing.setPending();
924 if(existing.isPending()) waitPending(existing);
928 void remove(ExternalReadEntry entry) {
929 synchronized(externalReadEntryMap) {
930 externalReadEntryMap.remove(entry.request);
934 static void runnerExternalReadEntry(ReadGraphImpl graph, ExternalRead<?> r, CacheEntry parent, ListenerBase listener, AsyncProcedure procedure) throws DatabaseException {
935 QueryCache cache = graph.processor.cache;
936 if(procedure == null) procedure = emptyProcedureExternalReadEntry;
937 ExternalReadEntry entry = (ExternalReadEntry)cache.getOrCreateExternalReadEntry(r);
938 ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure, false);
939 if(entry.isReady()) entry.performFromCache(graph, procedure);
941 entry.compute(graph, procedure);
942 if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());