1 package org.simantics.db.impl.query;
3 import org.simantics.db.ObjectResourceIdMap;
4 import org.simantics.db.RelationInfo;
5 import org.simantics.db.common.utils.Logger;
6 import org.simantics.db.exception.DatabaseException;
7 import org.simantics.db.impl.graph.ReadGraphImpl;
8 import org.simantics.db.impl.procedure.InternalProcedure;
9 import org.simantics.db.impl.query.QueryProcessor.SessionTask;
10 import org.simantics.db.procedure.AsyncMultiProcedure;
11 import org.simantics.db.procedure.AsyncProcedure;
12 import org.simantics.db.procedure.ListenerBase;
13 import org.simantics.db.procedure.SyncMultiProcedure;
14 import org.simantics.db.request.AsyncMultiRead;
15 import org.simantics.db.request.AsyncRead;
16 import org.simantics.db.request.ExternalRead;
17 import org.simantics.db.request.MultiRead;
18 import org.simantics.db.request.Read;
20 public class QueryCache extends QueryCacheBase {
22 private static final boolean SINGLE = true;
24 public QueryCache(QuerySupport querySupport, int threads) {
25 super(querySupport, threads);
28 Objects getOrCreateObjects(ReadGraphImpl graph, int r1, int r2) throws DatabaseException {
29 Objects existing = null;
30 synchronized(objectsMap) {
31 existing = (Objects)objectsMap.get(r1,r2);
32 if(existing == null) {
33 existing = new Objects(r1,r2);
34 existing.setPending(querySupport);
35 objectsMap.put(keyR2(r1,r2), existing);
39 if(existing.requiresComputation()) {
40 existing.setPending(querySupport);
44 if(existing.isPending()) {
45 waitPending(graph, existing);
50 void remove(Objects entry) {
51 synchronized(objectsMap) {
52 objectsMap.remove(entry.id);
56 public static void runnerObjects(ReadGraphImpl graph, int r1, int r2, CacheEntry parent, ListenerBase listener, final IntProcedure procedure) throws DatabaseException {
57 QueryCache cache = graph.processor.cache;
58 if(parent == null && listener == null && !cache.shouldCache(graph.processor, r1,r2)) {
60 Objects e = cache.peekObjects(r1,r2);
61 if (e != null && e.isReady()) {
62 e.performFromCache(graph, procedure);
66 Objects.computeForEach(graph, r1,r2, null, procedure);
69 Objects entry = (Objects)cache.getOrCreateObjects(graph, r1,r2);
70 IntProcedure procedure_ = procedure != null ? procedure : emptyProcedureObjects;
72 graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
73 entry.performFromCache(graph, procedure_);
76 assert(entry.isPending());
77 graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
78 Objects.computeForEach(graph, r1,r2, entry, procedure_);
82 private Objects peekObjects(int r1, int r2) {
83 synchronized(objectsMap) {
84 return (Objects) objectsMap.get(r1,r2);
88 Statements getOrCreateStatements(ReadGraphImpl graph, int r1, int r2) throws DatabaseException {
89 Statements existing = null;
90 synchronized(statementsMap) {
91 existing = (Statements)statementsMap.get(r1,r2);
92 if(existing == null) {
93 existing = new Statements(r1,r2);
94 existing.setPending(querySupport);
95 statementsMap.put(keyR2(r1,r2), existing);
99 if(existing.requiresComputation()) {
100 existing.setPending(querySupport);
104 if(existing.isPending()) {
105 waitPending(graph, existing);
110 void remove(Statements entry) {
111 synchronized(statementsMap) {
112 statementsMap.remove(entry.id);
116 public static void runnerStatements(ReadGraphImpl graph, int r1, int r2, CacheEntry parent, ListenerBase listener, final TripleIntProcedure procedure) throws DatabaseException {
117 QueryCache cache = graph.processor.cache;
118 if(parent == null && listener == null && !cache.shouldCache(graph.processor, r1,r2)) {
120 Statements e = cache.peekStatements(r1,r2);
121 if (e != null && e.isReady()) {
122 e.performFromCache(graph, procedure);
126 Statements.computeForEach(graph, r1,r2, null, procedure);
129 Statements entry = (Statements)cache.getOrCreateStatements(graph, r1,r2);
130 TripleIntProcedure procedure_ = procedure != null ? procedure : emptyProcedureStatements;
131 if(entry.isReady()) {
132 graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
133 entry.performFromCache(graph, procedure_);
136 assert(entry.isPending());
137 graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
138 Statements.computeForEach(graph, r1,r2, entry, procedure_);
142 private Statements peekStatements(int r1, int r2) {
143 synchronized(statementsMap) {
144 return (Statements) statementsMap.get(r1,r2);
148 DirectObjects getOrCreateDirectObjects(ReadGraphImpl graph, int r1, int r2) throws DatabaseException {
149 DirectObjects existing = null;
150 synchronized(directObjectsMap) {
151 existing = (DirectObjects)directObjectsMap.get(r1,r2);
152 if(existing == null) {
153 existing = new DirectObjects(r1,r2);
154 existing.setPending(querySupport);
155 directObjectsMap.put(keyR2(r1,r2), existing);
159 if(existing.requiresComputation()) {
160 existing.setPending(querySupport);
164 if(existing.isPending()) {
165 waitPending(graph, existing);
170 void remove(DirectObjects entry) {
171 synchronized(directObjectsMap) {
172 directObjectsMap.remove(entry.id);
176 public static void runnerDirectObjects(ReadGraphImpl graph, int r1, int r2, CacheEntry parent, ListenerBase listener, final IntProcedure procedure) throws DatabaseException {
177 QueryCache cache = graph.processor.cache;
178 if(parent == null && listener == null && !cache.shouldCache(graph.processor, r1,r2)) {
180 DirectObjects e = cache.peekDirectObjects(r1,r2);
181 if (e != null && e.isReady()) {
182 e.performFromCache(graph, procedure);
186 DirectObjects.computeForEach(graph, r1,r2, null, procedure);
189 DirectObjects entry = (DirectObjects)cache.getOrCreateDirectObjects(graph, r1,r2);
190 IntProcedure procedure_ = procedure != null ? procedure : emptyProcedureDirectObjects;
191 if(entry.isReady()) {
192 graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
193 entry.performFromCache(graph, procedure_);
196 assert(entry.isPending());
197 graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
198 DirectObjects.computeForEach(graph, r1,r2, entry, procedure_);
202 private DirectObjects peekDirectObjects(int r1, int r2) {
203 synchronized(directObjectsMap) {
204 return (DirectObjects) directObjectsMap.get(r1,r2);
208 RelationInfoQuery getOrCreateRelationInfoQuery(ReadGraphImpl graph, int r) throws DatabaseException {
209 RelationInfoQuery existing = null;
210 synchronized(relationInfoQueryMap) {
211 existing = (RelationInfoQuery)relationInfoQueryMap.get(r);
212 if(existing == null) {
213 existing = new RelationInfoQuery(r);
214 existing.setPending(querySupport);
215 relationInfoQueryMap.put(keyR(r), existing);
219 if(existing.requiresComputation()) {
220 existing.setPending(querySupport);
224 if(existing.isPending()) {
225 waitPending(graph, existing);
230 void remove(RelationInfoQuery entry) {
231 synchronized(relationInfoQueryMap) {
232 relationInfoQueryMap.remove(entry.id);
236 public static void runnerRelationInfoQuery(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, final InternalProcedure<RelationInfo> procedure) throws DatabaseException {
237 QueryCache cache = graph.processor.cache;
238 if(parent == null && listener == null && !cache.shouldCache(graph.processor, r)) {
240 RelationInfoQuery e = cache.peekRelationInfoQuery(r);
241 if (e != null && e.isReady()) {
242 e.performFromCache(graph, procedure);
246 RelationInfoQuery.computeForEach(graph, r, null, procedure);
249 RelationInfoQuery entry = (RelationInfoQuery)cache.getOrCreateRelationInfoQuery(graph, r);
250 InternalProcedure<RelationInfo> procedure_ = procedure != null ? procedure : emptyProcedureRelationInfoQuery;
251 if(entry.isReady()) {
252 graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
253 entry.performFromCache(graph, procedure_);
256 assert(entry.isPending());
257 graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
258 RelationInfoQuery.computeForEach(graph, r, entry, procedure_);
262 private RelationInfoQuery peekRelationInfoQuery(int r) {
263 synchronized(relationInfoQueryMap) {
264 return (RelationInfoQuery) relationInfoQueryMap.get(r);
268 URIToResource getOrCreateURIToResource(ReadGraphImpl graph, String id) throws DatabaseException {
269 URIToResource existing = null;
270 synchronized(uRIToResourceMap) {
271 existing = (URIToResource)uRIToResourceMap.get(id);
272 if(existing == null) {
273 existing = new URIToResource(id);
274 existing.setPending(querySupport);
275 uRIToResourceMap.put(keyID(id), existing);
279 if(existing.requiresComputation()) {
280 existing.setPending(querySupport);
284 if(existing.isPending()) {
285 waitPending(graph, existing);
290 void remove(URIToResource entry) {
291 synchronized(uRIToResourceMap) {
292 uRIToResourceMap.remove(entry.id);
296 public static void runnerURIToResource(ReadGraphImpl graph, String id, CacheEntry parent, ListenerBase listener, final InternalProcedure<Integer> procedure) throws DatabaseException {
297 QueryCache cache = graph.processor.cache;
298 if(parent == null && listener == null && !cache.shouldCache(graph.processor, id)) {
300 URIToResource e = cache.peekURIToResource(id);
301 if (e != null && e.isReady()) {
302 e.performFromCache(graph, procedure);
306 URIToResource.computeForEach(graph, id, null, procedure);
309 URIToResource entry = (URIToResource)cache.getOrCreateURIToResource(graph, id);
310 InternalProcedure<Integer> procedure_ = procedure != null ? procedure : emptyProcedureURIToResource;
311 if(entry.isReady()) {
312 graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
313 entry.performFromCache(graph, procedure_);
316 assert(entry.isPending());
317 graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
318 URIToResource.computeForEach(graph, id, entry, procedure_);
322 private URIToResource peekURIToResource(String id) {
323 synchronized(uRIToResourceMap) {
324 return (URIToResource) uRIToResourceMap.get(id);
328 ValueQuery getOrCreateValueQuery(ReadGraphImpl graph, int r) throws DatabaseException {
329 ValueQuery existing = null;
330 synchronized(valueQueryMap) {
331 existing = (ValueQuery)valueQueryMap.get(r);
332 if(existing == null) {
333 existing = new ValueQuery(r);
334 existing.setPending(querySupport);
335 valueQueryMap.put(keyR(r), existing);
339 if(existing.requiresComputation()) {
340 existing.setPending(querySupport);
344 if(existing.isPending()) {
345 waitPending(graph, existing);
350 void remove(ValueQuery entry) {
351 synchronized(valueQueryMap) {
352 valueQueryMap.remove(entry.id);
356 public static void runnerValueQuery(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, final InternalProcedure<byte[]> procedure) throws DatabaseException {
357 QueryCache cache = graph.processor.cache;
358 if(parent == null && listener == null && !cache.shouldCache(graph.processor, r)) {
360 ValueQuery e = cache.peekValueQuery(r);
361 if (e != null && e.isReady()) {
362 e.performFromCache(graph, procedure);
366 ValueQuery.computeForEach(graph, r, null, procedure);
369 ValueQuery entry = (ValueQuery)cache.getOrCreateValueQuery(graph, r);
370 InternalProcedure<byte[]> procedure_ = procedure != null ? procedure : emptyProcedureValueQuery;
371 if(entry.isReady()) {
372 graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
373 entry.performFromCache(graph, procedure_);
376 assert(entry.isPending());
377 graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
378 ValueQuery.computeForEach(graph, r, entry, procedure_);
382 private ValueQuery peekValueQuery(int r) {
383 synchronized(valueQueryMap) {
384 return (ValueQuery) valueQueryMap.get(r);
388 OrderedSet getOrCreateOrderedSet(ReadGraphImpl graph, int r) throws DatabaseException {
389 OrderedSet existing = null;
390 synchronized(orderedSetMap) {
391 existing = (OrderedSet)orderedSetMap.get(r);
392 if(existing == null) {
393 existing = new OrderedSet(r);
394 existing.setPending(querySupport);
395 orderedSetMap.put(keyR(r), existing);
399 if(existing.requiresComputation()) {
400 existing.setPending(querySupport);
404 if(existing.isPending()) {
405 waitPending(graph, existing);
410 void remove(OrderedSet entry) {
411 synchronized(orderedSetMap) {
412 orderedSetMap.remove(entry.id);
416 public static void runnerOrderedSet(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, final IntProcedure procedure) throws DatabaseException {
417 QueryCache cache = graph.processor.cache;
418 if(parent == null && listener == null && !cache.shouldCache(graph.processor, r)) {
420 OrderedSet e = cache.peekOrderedSet(r);
421 if (e != null && e.isReady()) {
422 e.performFromCache(graph, procedure);
426 OrderedSet.computeForEach(graph, r, null, procedure);
429 OrderedSet entry = (OrderedSet)cache.getOrCreateOrderedSet(graph, r);
430 IntProcedure procedure_ = procedure != null ? procedure : emptyProcedureOrderedSet;
431 if(entry.isReady()) {
432 graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
433 entry.performFromCache(graph, procedure_);
436 assert(entry.isPending());
437 graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
438 OrderedSet.computeForEach(graph, r, entry, procedure_);
442 private OrderedSet peekOrderedSet(int r) {
443 synchronized(orderedSetMap) {
444 return (OrderedSet) orderedSetMap.get(r);
448 PrincipalTypes getOrCreatePrincipalTypes(ReadGraphImpl graph, int r) throws DatabaseException {
449 PrincipalTypes existing = null;
450 synchronized(principalTypesMap) {
451 existing = (PrincipalTypes)principalTypesMap.get(r);
452 if(existing == null) {
453 existing = new PrincipalTypes(r);
454 existing.setPending(querySupport);
455 principalTypesMap.put(keyR(r), existing);
459 if(existing.requiresComputation()) {
460 existing.setPending(querySupport);
464 if(existing.isPending()) {
465 waitPending(graph, existing);
470 void remove(PrincipalTypes entry) {
471 synchronized(principalTypesMap) {
472 principalTypesMap.remove(entry.id);
476 public static void runnerPrincipalTypes(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, final IntProcedure procedure) throws DatabaseException {
477 QueryCache cache = graph.processor.cache;
478 if(parent == null && listener == null && !cache.shouldCache(graph.processor, r)) {
480 PrincipalTypes e = cache.peekPrincipalTypes(r);
481 if (e != null && e.isReady()) {
482 e.performFromCache(graph, procedure);
486 PrincipalTypes.computeForEach(graph, r, null, procedure);
489 PrincipalTypes entry = (PrincipalTypes)cache.getOrCreatePrincipalTypes(graph, r);
490 IntProcedure procedure_ = procedure != null ? procedure : emptyProcedurePrincipalTypes;
491 if(entry.isReady()) {
492 graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
493 entry.performFromCache(graph, procedure_);
496 assert(entry.isPending());
497 graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
498 PrincipalTypes.computeForEach(graph, r, entry, procedure_);
502 private PrincipalTypes peekPrincipalTypes(int r) {
503 synchronized(principalTypesMap) {
504 return (PrincipalTypes) principalTypesMap.get(r);
508 DirectPredicates getOrCreateDirectPredicates(ReadGraphImpl graph, int r) throws DatabaseException {
509 DirectPredicates existing = null;
510 synchronized(directPredicatesMap) {
511 existing = (DirectPredicates)directPredicatesMap.get(r);
512 if(existing == null) {
513 existing = new DirectPredicates(r);
514 existing.setPending(querySupport);
515 directPredicatesMap.put(keyR(r), existing);
519 if(existing.requiresComputation()) {
520 existing.setPending(querySupport);
524 if(existing.isPending()) {
525 waitPending(graph, existing);
530 void remove(DirectPredicates entry) {
531 synchronized(directPredicatesMap) {
532 directPredicatesMap.remove(entry.id);
536 public static void runnerDirectPredicates(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, final InternalProcedure<IntSet> procedure) throws DatabaseException {
537 QueryCache cache = graph.processor.cache;
538 if(parent == null && listener == null && !cache.shouldCache(graph.processor, r)) {
540 DirectPredicates e = cache.peekDirectPredicates(r);
541 if (e != null && e.isReady()) {
542 e.performFromCache(graph, procedure);
546 DirectPredicates.computeForEach(graph, r, null, procedure);
549 DirectPredicates entry = (DirectPredicates)cache.getOrCreateDirectPredicates(graph, r);
550 InternalProcedure<IntSet> procedure_ = procedure != null ? procedure : emptyProcedureDirectPredicates;
551 if(entry.isReady()) {
552 graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
553 entry.performFromCache(graph, procedure_);
556 assert(entry.isPending());
557 graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
558 DirectPredicates.computeForEach(graph, r, entry, procedure_);
562 private DirectPredicates peekDirectPredicates(int r) {
563 synchronized(directPredicatesMap) {
564 return (DirectPredicates) directPredicatesMap.get(r);
568 Predicates getOrCreatePredicates(ReadGraphImpl graph, int r) throws DatabaseException {
569 Predicates existing = null;
570 synchronized(predicatesMap) {
571 existing = (Predicates)predicatesMap.get(r);
572 if(existing == null) {
573 existing = new Predicates(r);
574 existing.setPending(querySupport);
575 predicatesMap.put(keyR(r), existing);
579 if(existing.requiresComputation()) {
580 existing.setPending(querySupport);
584 if(existing.isPending()) {
585 waitPending(graph, existing);
590 void remove(Predicates entry) {
591 synchronized(predicatesMap) {
592 predicatesMap.remove(entry.id);
596 public static void runnerPredicates(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, final InternalProcedure<IntSet> procedure) throws DatabaseException {
597 QueryCache cache = graph.processor.cache;
598 if(parent == null && listener == null && !cache.shouldCache(graph.processor, r)) {
600 Predicates e = cache.peekPredicates(r);
601 if (e != null && e.isReady()) {
602 e.performFromCache(graph, procedure);
606 Predicates.computeForEach(graph, r, null, procedure);
609 Predicates entry = (Predicates)cache.getOrCreatePredicates(graph, r);
610 InternalProcedure<IntSet> procedure_ = procedure != null ? procedure : emptyProcedurePredicates;
611 if(entry.isReady()) {
612 graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
613 entry.performFromCache(graph, procedure_);
616 assert(entry.isPending());
617 graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
618 Predicates.computeForEach(graph, r, entry, procedure_);
622 private Predicates peekPredicates(int r) {
623 synchronized(predicatesMap) {
624 return (Predicates) predicatesMap.get(r);
628 ReadEntry getOrCreateReadEntry(ReadGraphImpl graph, Read<?> r, boolean needsToBlock) throws DatabaseException {
629 ReadEntry existing = null;
630 synchronized(readEntryMap) {
631 existing = (ReadEntry)readEntryMap.get(r);
632 if(existing == null) {
633 existing = new ReadEntry(r);
634 existing.setPending(querySupport);
635 readEntryMap.put(id(r), existing);
639 if(existing.requiresComputation()) {
640 existing.setPending(querySupport);
644 if(existing.isPending()) {
646 waitPending(graph, existing);
654 void remove(ReadEntry entry) {
655 synchronized(readEntryMap) {
656 readEntryMap.remove(entry.id);
660 public static Object runnerReadEntry(ReadGraphImpl graph, Read<?> r, CacheEntry parent, ListenerBase listener, final AsyncProcedure procedure, boolean needsToBlock) throws DatabaseException {
661 QueryCache cache = graph.processor.cache;
662 if(parent == null && listener == null && !cache.shouldCache(graph.processor, r)) {
664 ReadEntry e = cache.peekReadEntry(r);
665 if (e != null && e.isReady()) {
666 return e.performFromCache(graph, procedure);
669 return ReadEntry.computeForEach(graph, r, null, procedure, needsToBlock);
671 ReadEntry entry = (ReadEntry)cache.getOrCreateReadEntry(graph, r, needsToBlock);
673 graph.processor.schedule(new SessionTask(graph) {
675 public void run0(int thread) {
677 runnerReadEntry(graph, r, parent, listener, procedure, needsToBlock);
678 } catch (DatabaseException e) {
679 Logger.defaultLogError(e);
685 AsyncProcedure procedure_ = procedure != null ? procedure : emptyProcedureReadEntry;
686 if(entry.isReady()) {
687 graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
688 Object result = entry.performFromCache(graph, procedure_);
689 graph.processor.listening.registerFirstKnown(listener, result);
693 assert(entry.isPending());
694 graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
695 Object result = ReadEntry.computeForEach(graph, r, entry, procedure_, needsToBlock);
696 graph.processor.listening.registerFirstKnown(listener, result);
701 private ReadEntry peekReadEntry(Read<?> r) {
702 synchronized(readEntryMap) {
703 return (ReadEntry) readEntryMap.get(r);
707 AsyncReadEntry getOrCreateAsyncReadEntry(ReadGraphImpl graph, AsyncRead<?> r, boolean needsToBlock) throws DatabaseException {
708 AsyncReadEntry existing = null;
709 synchronized(asyncReadEntryMap) {
710 existing = (AsyncReadEntry)asyncReadEntryMap.get(r);
711 if(existing == null) {
712 existing = new AsyncReadEntry(r);
713 existing.setPending(querySupport);
714 asyncReadEntryMap.put(id(r), existing);
718 if(existing.requiresComputation()) {
719 existing.setPending(querySupport);
723 if(existing.isPending()) {
725 waitPending(graph, existing);
733 void remove(AsyncReadEntry entry) {
734 synchronized(asyncReadEntryMap) {
735 asyncReadEntryMap.remove(entry.id);
739 public static Object runnerAsyncReadEntry(ReadGraphImpl graph, AsyncRead<?> r, CacheEntry parent, ListenerBase listener, final AsyncProcedure procedure, boolean needsToBlock) throws DatabaseException {
740 QueryCache cache = graph.processor.cache;
741 if(parent == null && listener == null && !cache.shouldCache(graph.processor, r)) {
743 AsyncReadEntry e = cache.peekAsyncReadEntry(r);
744 if (e != null && e.isReady()) {
745 return e.performFromCache(graph, procedure);
748 return AsyncReadEntry.computeForEach(graph, r, null, procedure, needsToBlock);
750 AsyncReadEntry entry = (AsyncReadEntry)cache.getOrCreateAsyncReadEntry(graph, r, needsToBlock);
752 graph.processor.schedule(new SessionTask(graph) {
754 public void run0(int thread) {
756 runnerAsyncReadEntry(graph, r, parent, listener, procedure, needsToBlock);
757 } catch (DatabaseException e) {
758 Logger.defaultLogError(e);
764 AsyncProcedure procedure_ = procedure != null ? procedure : emptyProcedureAsyncReadEntry;
765 if(entry.isReady()) {
766 graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
767 Object result = entry.performFromCache(graph, procedure_);
768 graph.processor.listening.registerFirstKnown(listener, result);
772 assert(entry.isPending());
773 graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
774 Object result = AsyncReadEntry.computeForEach(graph, r, entry, procedure_, needsToBlock);
775 graph.processor.listening.registerFirstKnown(listener, result);
780 private AsyncReadEntry peekAsyncReadEntry(AsyncRead<?> r) {
781 synchronized(asyncReadEntryMap) {
782 return (AsyncReadEntry) asyncReadEntryMap.get(r);
786 Types getOrCreateTypes(ReadGraphImpl graph, int r) throws DatabaseException {
787 Types existing = null;
788 synchronized(typesMap) {
789 existing = (Types)typesMap.get(r);
790 if(existing == null) {
791 existing = new Types(r);
792 existing.setPending(querySupport);
793 typesMap.put(keyR(r), existing);
797 if(existing.requiresComputation()) {
798 existing.setPending(querySupport);
802 if(existing.isPending()) {
803 waitPending(graph, existing);
808 void remove(Types entry) {
809 synchronized(typesMap) {
810 typesMap.remove(entry.id);
814 public static void runnerTypes(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, final InternalProcedure<IntSet> procedure) throws DatabaseException {
815 QueryCache cache = graph.processor.cache;
816 if(parent == null && listener == null && !cache.shouldCache(graph.processor, r)) {
818 Types e = cache.peekTypes(r);
819 if (e != null && e.isReady()) {
820 e.performFromCache(graph, procedure);
824 Types.computeForEach(graph, r, null, procedure);
827 Types entry = (Types)cache.getOrCreateTypes(graph, r);
828 InternalProcedure<IntSet> procedure_ = procedure != null ? procedure : emptyProcedureTypes;
829 if(entry.isReady()) {
830 graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
831 entry.performFromCache(graph, procedure_);
834 assert(entry.isPending());
835 graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
836 Types.computeForEach(graph, r, entry, procedure_);
840 private Types peekTypes(int r) {
841 synchronized(typesMap) {
842 return (Types) typesMap.get(r);
846 ChildMap getOrCreateChildMap(ReadGraphImpl graph, int r) throws DatabaseException {
847 ChildMap existing = null;
848 synchronized(childMapMap) {
849 existing = (ChildMap)childMapMap.get(r);
850 if(existing == null) {
851 existing = new ChildMap(r);
852 existing.setPending(querySupport);
853 childMapMap.put(keyR(r), existing);
857 if(existing.requiresComputation()) {
858 existing.setPending(querySupport);
862 if(existing.isPending()) {
863 waitPending(graph, existing);
868 void remove(ChildMap entry) {
869 synchronized(childMapMap) {
870 childMapMap.remove(entry.id);
874 public static void runnerChildMap(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, final InternalProcedure<ObjectResourceIdMap<String>> procedure) throws DatabaseException {
875 QueryCache cache = graph.processor.cache;
876 if(parent == null && listener == null && !cache.shouldCache(graph.processor, r)) {
878 ChildMap e = cache.peekChildMap(r);
879 if (e != null && e.isReady()) {
880 e.performFromCache(graph, procedure);
884 ChildMap.computeForEach(graph, r, null, procedure);
887 ChildMap entry = (ChildMap)cache.getOrCreateChildMap(graph, r);
888 InternalProcedure<ObjectResourceIdMap<String>> procedure_ = procedure != null ? procedure : emptyProcedureChildMap;
889 if(entry.isReady()) {
890 graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
891 entry.performFromCache(graph, procedure_);
894 assert(entry.isPending());
895 graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
896 ChildMap.computeForEach(graph, r, entry, procedure_);
900 private ChildMap peekChildMap(int r) {
901 synchronized(childMapMap) {
902 return (ChildMap) childMapMap.get(r);
906 TypeHierarchy getOrCreateTypeHierarchy(ReadGraphImpl graph, int r) throws DatabaseException {
907 TypeHierarchy existing = null;
908 synchronized(typeHierarchyMap) {
909 existing = (TypeHierarchy)typeHierarchyMap.get(r);
910 if(existing == null) {
911 existing = new TypeHierarchy(r);
912 existing.setPending(querySupport);
913 typeHierarchyMap.put(keyR(r), existing);
917 if(existing.requiresComputation()) {
918 existing.setPending(querySupport);
922 if(existing.isPending()) {
923 waitPending(graph, existing);
928 void remove(TypeHierarchy entry) {
929 synchronized(typeHierarchyMap) {
930 typeHierarchyMap.remove(entry.id);
934 public static void runnerTypeHierarchy(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, final InternalProcedure<IntSet> procedure) throws DatabaseException {
935 QueryCache cache = graph.processor.cache;
936 if(parent == null && listener == null && !cache.shouldCache(graph.processor, r)) {
938 TypeHierarchy e = cache.peekTypeHierarchy(r);
939 if (e != null && e.isReady()) {
940 e.performFromCache(graph, procedure);
944 TypeHierarchy.computeForEach(graph, r, null, procedure);
947 TypeHierarchy entry = (TypeHierarchy)cache.getOrCreateTypeHierarchy(graph, r);
948 InternalProcedure<IntSet> procedure_ = procedure != null ? procedure : emptyProcedureTypeHierarchy;
949 if(entry.isReady()) {
950 graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
951 entry.performFromCache(graph, procedure_);
954 assert(entry.isPending());
955 graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
956 TypeHierarchy.computeForEach(graph, r, entry, procedure_);
960 private TypeHierarchy peekTypeHierarchy(int r) {
961 synchronized(typeHierarchyMap) {
962 return (TypeHierarchy) typeHierarchyMap.get(r);
966 SuperTypes getOrCreateSuperTypes(ReadGraphImpl graph, int r) throws DatabaseException {
967 SuperTypes existing = null;
968 synchronized(superTypesMap) {
969 existing = (SuperTypes)superTypesMap.get(r);
970 if(existing == null) {
971 existing = new SuperTypes(r);
972 existing.setPending(querySupport);
973 superTypesMap.put(keyR(r), existing);
977 if(existing.requiresComputation()) {
978 existing.setPending(querySupport);
982 if(existing.isPending()) {
983 waitPending(graph, existing);
988 void remove(SuperTypes entry) {
989 synchronized(superTypesMap) {
990 superTypesMap.remove(entry.id);
994 public static void runnerSuperTypes(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, final InternalProcedure<IntSet> procedure) throws DatabaseException {
995 QueryCache cache = graph.processor.cache;
996 if(parent == null && listener == null && !cache.shouldCache(graph.processor, r)) {
998 SuperTypes e = cache.peekSuperTypes(r);
999 if (e != null && e.isReady()) {
1000 e.performFromCache(graph, procedure);
1004 SuperTypes.computeForEach(graph, r, null, procedure);
1007 SuperTypes entry = (SuperTypes)cache.getOrCreateSuperTypes(graph, r);
1008 InternalProcedure<IntSet> procedure_ = procedure != null ? procedure : emptyProcedureSuperTypes;
1009 if(entry.isReady()) {
1010 graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
1011 entry.performFromCache(graph, procedure_);
1014 assert(entry.isPending());
1015 graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
1016 SuperTypes.computeForEach(graph, r, entry, procedure_);
1020 private SuperTypes peekSuperTypes(int r) {
1021 synchronized(superTypesMap) {
1022 return (SuperTypes) superTypesMap.get(r);
1026 SuperRelations getOrCreateSuperRelations(ReadGraphImpl graph, int r) throws DatabaseException {
1027 SuperRelations existing = null;
1028 synchronized(superRelationsMap) {
1029 existing = (SuperRelations)superRelationsMap.get(r);
1030 if(existing == null) {
1031 existing = new SuperRelations(r);
1032 existing.setPending(querySupport);
1033 superRelationsMap.put(keyR(r), existing);
1037 if(existing.requiresComputation()) {
1038 existing.setPending(querySupport);
1042 if(existing.isPending()) {
1043 waitPending(graph, existing);
1048 void remove(SuperRelations entry) {
1049 synchronized(superRelationsMap) {
1050 superRelationsMap.remove(entry.id);
1054 public static void runnerSuperRelations(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, final InternalProcedure<IntSet> procedure) throws DatabaseException {
1055 QueryCache cache = graph.processor.cache;
1056 if(parent == null && listener == null && !cache.shouldCache(graph.processor, r)) {
1058 SuperRelations e = cache.peekSuperRelations(r);
1059 if (e != null && e.isReady()) {
1060 e.performFromCache(graph, procedure);
1064 SuperRelations.computeForEach(graph, r, null, procedure);
1067 SuperRelations entry = (SuperRelations)cache.getOrCreateSuperRelations(graph, r);
1068 InternalProcedure<IntSet> procedure_ = procedure != null ? procedure : emptyProcedureSuperRelations;
1069 if(entry.isReady()) {
1070 graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
1071 entry.performFromCache(graph, procedure_);
1074 assert(entry.isPending());
1075 graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
1076 SuperRelations.computeForEach(graph, r, entry, procedure_);
1080 private SuperRelations peekSuperRelations(int r) {
1081 synchronized(superRelationsMap) {
1082 return (SuperRelations) superRelationsMap.get(r);
1086 AssertedPredicates getOrCreateAssertedPredicates(ReadGraphImpl graph, int r) throws DatabaseException {
1087 AssertedPredicates existing = null;
1088 synchronized(assertedPredicatesMap) {
1089 existing = (AssertedPredicates)assertedPredicatesMap.get(r);
1090 if(existing == null) {
1091 existing = new AssertedPredicates(r);
1092 existing.setPending(querySupport);
1093 assertedPredicatesMap.put(keyR(r), existing);
1097 if(existing.requiresComputation()) {
1098 existing.setPending(querySupport);
1102 if(existing.isPending()) {
1103 waitPending(graph, existing);
1108 void remove(AssertedPredicates entry) {
1109 synchronized(assertedPredicatesMap) {
1110 assertedPredicatesMap.remove(entry.id);
1114 public static void runnerAssertedPredicates(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, final IntProcedure procedure) throws DatabaseException {
1115 QueryCache cache = graph.processor.cache;
1116 AssertedPredicates entry = (AssertedPredicates)cache.getOrCreateAssertedPredicates(graph, r);
1117 IntProcedure procedure_ = procedure != null ? procedure : emptyProcedureAssertedPredicates;
1118 if(entry.isReady()) {
1119 graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
1120 entry.performFromCache(graph, procedure_);
1123 assert(entry.isPending());
1124 graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
1125 entry.compute(graph, procedure_);
1129 private AssertedPredicates peekAssertedPredicates(int r) {
1130 synchronized(assertedPredicatesMap) {
1131 return (AssertedPredicates) assertedPredicatesMap.get(r);
1135 AssertedStatements getOrCreateAssertedStatements(ReadGraphImpl graph, int r1, int r2) throws DatabaseException {
1136 AssertedStatements existing = null;
1137 synchronized(assertedStatementsMap) {
1138 existing = (AssertedStatements)assertedStatementsMap.get(r1,r2);
1139 if(existing == null) {
1140 existing = new AssertedStatements(r1,r2);
1141 existing.setPending(querySupport);
1142 assertedStatementsMap.put(keyR2(r1,r2), existing);
1146 if(existing.requiresComputation()) {
1147 existing.setPending(querySupport);
1151 if(existing.isPending()) {
1152 waitPending(graph, existing);
1157 void remove(AssertedStatements entry) {
1158 synchronized(assertedStatementsMap) {
1159 assertedStatementsMap.remove(entry.id);
1163 public static void runnerAssertedStatements(ReadGraphImpl graph, int r1, int r2, CacheEntry parent, ListenerBase listener, final TripleIntProcedure procedure) throws DatabaseException {
1164 QueryCache cache = graph.processor.cache;
1165 AssertedStatements entry = (AssertedStatements)cache.getOrCreateAssertedStatements(graph, r1,r2);
1166 TripleIntProcedure procedure_ = procedure != null ? procedure : emptyProcedureAssertedStatements;
1167 if(entry.isReady()) {
1168 graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
1169 entry.performFromCache(graph, procedure_);
1172 assert(entry.isPending());
1173 graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
1174 entry.compute(graph, procedure_);
1178 private AssertedStatements peekAssertedStatements(int r1, int r2) {
1179 synchronized(assertedStatementsMap) {
1180 return (AssertedStatements) assertedStatementsMap.get(r1,r2);
1184 DirectSuperRelations getOrCreateDirectSuperRelations(ReadGraphImpl graph, int r) throws DatabaseException {
1185 DirectSuperRelations existing = null;
1186 synchronized(directSuperRelationsMap) {
1187 existing = (DirectSuperRelations)directSuperRelationsMap.get(r);
1188 if(existing == null) {
1189 existing = new DirectSuperRelations(r);
1190 existing.setPending(querySupport);
1191 directSuperRelationsMap.put(keyR(r), existing);
1195 if(existing.requiresComputation()) {
1196 existing.setPending(querySupport);
1200 if(existing.isPending()) {
1201 waitPending(graph, existing);
1206 void remove(DirectSuperRelations entry) {
1207 synchronized(directSuperRelationsMap) {
1208 directSuperRelationsMap.remove(entry.id);
1212 public static void runnerDirectSuperRelations(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, final IntProcedure procedure) throws DatabaseException {
1213 QueryCache cache = graph.processor.cache;
1214 DirectSuperRelations entry = (DirectSuperRelations)cache.getOrCreateDirectSuperRelations(graph, r);
1215 IntProcedure procedure_ = procedure != null ? procedure : emptyProcedureDirectSuperRelations;
1216 if(entry.isReady()) {
1217 graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
1218 entry.performFromCache(graph, procedure_);
1221 assert(entry.isPending());
1222 graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
1223 entry.compute(graph, procedure_);
1227 private DirectSuperRelations peekDirectSuperRelations(int r) {
1228 synchronized(directSuperRelationsMap) {
1229 return (DirectSuperRelations) directSuperRelationsMap.get(r);
1233 MultiReadEntry getOrCreateMultiReadEntry(ReadGraphImpl graph, MultiRead<?> r) throws DatabaseException {
1234 MultiReadEntry existing = null;
1235 synchronized(multiReadEntryMap) {
1236 existing = (MultiReadEntry)multiReadEntryMap.get(r);
1237 if(existing == null) {
1238 existing = new MultiReadEntry(r);
1239 existing.setPending(querySupport);
1240 multiReadEntryMap.put(id(r), existing);
1244 if(existing.requiresComputation()) {
1245 existing.setPending(querySupport);
1249 if(existing.isPending()) {
1250 waitPending(graph, existing);
1255 void remove(MultiReadEntry entry) {
1256 synchronized(multiReadEntryMap) {
1257 multiReadEntryMap.remove(entry.id);
1261 public static void runnerMultiReadEntry(ReadGraphImpl graph, MultiRead<?> r, CacheEntry parent, ListenerBase listener, final SyncMultiProcedure procedure) throws DatabaseException {
1262 QueryCache cache = graph.processor.cache;
1263 MultiReadEntry entry = (MultiReadEntry)cache.getOrCreateMultiReadEntry(graph, r);
1264 SyncMultiProcedure procedure_ = procedure != null ? procedure : emptyProcedureMultiReadEntry;
1265 if(entry.isReady()) {
1266 graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
1267 entry.performFromCache(graph, procedure_);
1270 assert(entry.isPending());
1271 graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
1272 entry.compute(graph, procedure_);
1276 private MultiReadEntry peekMultiReadEntry(MultiRead<?> r) {
1277 synchronized(multiReadEntryMap) {
1278 return (MultiReadEntry) multiReadEntryMap.get(r);
1282 AsyncMultiReadEntry getOrCreateAsyncMultiReadEntry(ReadGraphImpl graph, AsyncMultiRead<?> r) throws DatabaseException {
1283 AsyncMultiReadEntry existing = null;
1284 synchronized(asyncMultiReadEntryMap) {
1285 existing = (AsyncMultiReadEntry)asyncMultiReadEntryMap.get(r);
1286 if(existing == null) {
1287 existing = new AsyncMultiReadEntry(r);
1288 existing.setPending(querySupport);
1289 asyncMultiReadEntryMap.put(id(r), existing);
1293 if(existing.requiresComputation()) {
1294 existing.setPending(querySupport);
1298 if(existing.isPending()) {
1299 waitPending(graph, existing);
1304 void remove(AsyncMultiReadEntry entry) {
1305 synchronized(asyncMultiReadEntryMap) {
1306 asyncMultiReadEntryMap.remove(entry.id);
1310 public static void runnerAsyncMultiReadEntry(ReadGraphImpl graph, AsyncMultiRead<?> r, CacheEntry parent, ListenerBase listener, final AsyncMultiProcedure procedure) throws DatabaseException {
1311 QueryCache cache = graph.processor.cache;
1312 AsyncMultiReadEntry entry = (AsyncMultiReadEntry)cache.getOrCreateAsyncMultiReadEntry(graph, r);
1313 AsyncMultiProcedure procedure_ = procedure != null ? procedure : emptyProcedureAsyncMultiReadEntry;
1314 if(entry.isReady()) {
1315 graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
1316 entry.performFromCache(graph, procedure_);
1319 assert(entry.isPending());
1320 graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
1321 entry.compute(graph, procedure_);
1325 private AsyncMultiReadEntry peekAsyncMultiReadEntry(AsyncMultiRead<?> r) {
1326 synchronized(asyncMultiReadEntryMap) {
1327 return (AsyncMultiReadEntry) asyncMultiReadEntryMap.get(r);
1331 ExternalReadEntry getOrCreateExternalReadEntry(ReadGraphImpl graph, ExternalRead<?> r) throws DatabaseException {
1332 ExternalReadEntry existing = null;
1333 synchronized(externalReadEntryMap) {
1334 existing = (ExternalReadEntry)externalReadEntryMap.get(r);
1335 if(existing == null) {
1336 existing = new ExternalReadEntry(r, graph);
1337 existing.setPending(querySupport);
1338 externalReadEntryMap.put(id(r), existing);
1342 if(existing.requiresComputation()) {
1343 existing.setPending(querySupport);
1347 if(existing.isPending()) {
1348 waitPending(graph, existing);
1353 void remove(ExternalReadEntry entry) {
1354 synchronized(externalReadEntryMap) {
1355 externalReadEntryMap.remove(entry.id);
1359 public static void runnerExternalReadEntry(ReadGraphImpl graph, ExternalRead<?> r, CacheEntry parent, ListenerBase listener, final AsyncProcedure procedure) throws DatabaseException {
1360 QueryCache cache = graph.processor.cache;
1361 ExternalReadEntry entry = (ExternalReadEntry)cache.getOrCreateExternalReadEntry(graph, r);
1362 AsyncProcedure procedure_ = procedure != null ? procedure : emptyProcedureExternalReadEntry;
1363 if(entry.isReady()) {
1364 graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
1365 entry.performFromCache(graph, procedure_);
1368 assert(entry.isPending());
1369 graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
1370 entry.compute(graph, procedure_);
1374 private ExternalReadEntry peekExternalReadEntry(ExternalRead<?> r) {
1375 synchronized(externalReadEntryMap) {
1376 return (ExternalReadEntry) externalReadEntryMap.get(r);