1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.db.impl.query;
14 import java.io.BufferedOutputStream;
16 import java.io.FileOutputStream;
17 import java.io.IOException;
18 import java.io.PrintStream;
19 import java.util.ArrayList;
20 import java.util.Arrays;
21 import java.util.Collection;
22 import java.util.Collections;
23 import java.util.HashMap;
24 import java.util.HashSet;
25 import java.util.IdentityHashMap;
26 import java.util.Iterator;
27 import java.util.LinkedList;
28 import java.util.List;
31 import java.util.concurrent.Semaphore;
32 import java.util.concurrent.atomic.AtomicBoolean;
33 import java.util.concurrent.atomic.AtomicInteger;
35 import org.simantics.databoard.Bindings;
36 import org.simantics.db.AsyncReadGraph;
37 import org.simantics.db.DevelopmentKeys;
38 import org.simantics.db.DirectStatements;
39 import org.simantics.db.ReadGraph;
40 import org.simantics.db.RelationInfo;
41 import org.simantics.db.Resource;
42 import org.simantics.db.Session;
43 import org.simantics.db.Statement;
44 import org.simantics.db.VirtualGraph;
45 import org.simantics.db.common.procedure.adapter.AsyncMultiProcedureAdapter;
46 import org.simantics.db.common.utils.Logger;
47 import org.simantics.db.exception.DatabaseException;
48 import org.simantics.db.exception.ManyObjectsForFunctionalRelationException;
49 import org.simantics.db.exception.NoInverseException;
50 import org.simantics.db.exception.ResourceNotFoundException;
51 import org.simantics.db.impl.ResourceImpl;
52 import org.simantics.db.impl.graph.BarrierTracing;
53 import org.simantics.db.impl.graph.ReadGraphImpl;
54 import org.simantics.db.impl.graph.ReadGraphSupport;
55 import org.simantics.db.impl.procedure.IntProcedureAdapter;
56 import org.simantics.db.impl.procedure.InternalProcedure;
57 import org.simantics.db.impl.procedure.TripleIntProcedureAdapter;
58 import org.simantics.db.impl.support.ResourceSupport;
59 import org.simantics.db.procedure.AsyncMultiListener;
60 import org.simantics.db.procedure.AsyncMultiProcedure;
61 import org.simantics.db.procedure.AsyncProcedure;
62 import org.simantics.db.procedure.AsyncSetListener;
63 import org.simantics.db.procedure.ListenerBase;
64 import org.simantics.db.procedure.MultiProcedure;
65 import org.simantics.db.procedure.StatementProcedure;
66 import org.simantics.db.procedure.SyncMultiProcedure;
67 import org.simantics.db.request.AsyncMultiRead;
68 import org.simantics.db.request.ExternalRead;
69 import org.simantics.db.request.MultiRead;
70 import org.simantics.db.request.RequestFlags;
71 import org.simantics.layer0.Layer0;
72 import org.simantics.utils.DataContainer;
73 import org.simantics.utils.Development;
74 import org.simantics.utils.datastructures.Pair;
75 import org.simantics.utils.datastructures.collections.CollectionUtils;
76 import org.simantics.utils.datastructures.disposable.AbstractDisposable;
78 import gnu.trove.procedure.TIntProcedure;
79 import gnu.trove.procedure.TLongProcedure;
80 import gnu.trove.procedure.TObjectProcedure;
81 import gnu.trove.set.hash.THashSet;
82 import gnu.trove.set.hash.TIntHashSet;
84 @SuppressWarnings({"rawtypes", "unchecked"})
85 final public class QueryProcessor extends AbstractDisposable implements ReadGraphSupport {
87 public static int indent = 0;
92 public int boundQueries = 0;
95 final private int functionalRelation;
97 final private int superrelationOf;
99 final private int instanceOf;
101 final private int inverseOf;
103 final private int asserts;
105 final private int hasPredicate;
107 final private int hasPredicateInverse;
109 final private int hasObject;
111 final private int inherits;
113 final private int subrelationOf;
115 final private int rootLibrary;
118 * A cache for the root library resource. Initialized in
119 * {@link #getRootLibraryResource()}.
121 private volatile ResourceImpl rootLibraryResource;
123 final private int library;
125 final private int consistsOf;
127 final private int hasName;
129 AtomicInteger sleepers = new AtomicInteger(0);
131 boolean updating = false;
134 final public QueryCache cache;
135 final public QuerySupport querySupport;
136 final public Session session;
137 final public ResourceSupport resourceSupport;
139 final public Semaphore requests = new Semaphore(1);
141 final public QueryListening listening = new QueryListening(this);
143 QueryThread[] executors;
147 INIT, RUN, SLEEP, DISPOSED
151 final Scheduling scheduling;
153 public ThreadState[] threadStates;
155 final Object querySupportLock;
157 public Long modificationCounter = 0L;
159 public void close() {
164 * We are running errands while waiting for requests to complete.
165 * We can only run work that is part of the current root request to avoid any deadlocks
167 public boolean performPending(ReadGraphImpl under) {
168 SessionTask task = scheduling.getSubTask(under);
170 task.run(thread.get());
176 final public void scheduleNow(SessionTask request) {
177 SessionTask toExecute = scheduleOrReturnForExecution(request);
178 if(toExecute != null)
179 toExecute.run(thread.get());
182 final public SessionTask scheduleOrReturnForExecution(SessionTask request) {
184 return scheduling.scheduleOrReturnForExecution(request);
190 final public int THREAD_MASK;
192 final public static ThreadGroup QueryThreadGroup = new ThreadGroup("Query Thread Group");
194 public static abstract class SessionTask {
196 final protected ReadGraphImpl rootGraph;
197 private int counter = 0;
198 protected int position = 1;
199 private Exception trace;
201 public SessionTask() {
205 public SessionTask(ReadGraphImpl rootGraph) {
206 this.rootGraph = rootGraph;
209 public boolean isSubtask(ReadGraphImpl graph) {
210 return graph.isParent(rootGraph);
213 public abstract void run0(int thread);
215 public final void run(int thread) {
217 if(BarrierTracing.BOOKKEEPING) {
218 trace.printStackTrace();
219 new Exception().printStackTrace();
221 throw new IllegalStateException("Multiple invocations of SessionTask!");
223 if(BarrierTracing.BOOKKEEPING) {
224 trace = new Exception();
229 public boolean maybeReady() {
234 public String toString() {
235 if(rootGraph == null)
236 return "SessionTask[no graph]";
238 return "SessionTask[" + rootGraph.parent + "]";
243 public static abstract class SessionRead extends SessionTask {
245 final public Semaphore notify;
246 final public DataContainer<Throwable> throwable;
248 public SessionRead(DataContainer<Throwable> throwable, Semaphore notify) {
250 this.throwable = throwable;
251 this.notify = notify;
256 public boolean resume(ReadGraphImpl graph) {
257 return executors[0].runSynchronized();
260 public QueryProcessor(final int threads, QuerySupport core, Set<Thread> threadSet)
261 throws DatabaseException {
264 THREAD_MASK = threads - 1;
266 scheduling = new Scheduling(requests);
269 cache = new QueryCache(core, threads);
270 session = querySupport.getSession();
271 resourceSupport = querySupport.getSupport();
272 querySupportLock = core.getLock();
274 executors = new QueryThread[THREADS];
275 threadStates = new ThreadState[THREADS];
277 for (int i = 0; i < THREADS; i++) {
278 threadStates[i] = ThreadState.INIT;
281 for (int i = 0; i < THREADS; i++) {
285 executors[i] = new QueryThread(session, this, index, "Query Thread " + index);
287 threadSet.add(executors[i]);
292 for (int i = 0; i < THREADS; i++) {
293 executors[i].start();
296 // Make sure that query threads are up and running
297 while(sleepers.get() != THREADS) {
300 } catch (InterruptedException e) {
305 rootLibrary = core.getBuiltin("http:/");
306 boolean builtinsInstalled = rootLibrary != 0;
308 if (builtinsInstalled) {
309 functionalRelation = core.getBuiltin(Layer0.URIs.FunctionalRelation);
310 assert (functionalRelation != 0);
312 functionalRelation = 0;
314 if (builtinsInstalled) {
315 instanceOf = core.getBuiltin(Layer0.URIs.InstanceOf);
316 assert (instanceOf != 0);
320 if (builtinsInstalled) {
321 inverseOf = core.getBuiltin(Layer0.URIs.InverseOf);
322 assert (inverseOf != 0);
327 if (builtinsInstalled) {
328 inherits = core.getBuiltin(Layer0.URIs.Inherits);
329 assert (inherits != 0);
333 if (builtinsInstalled) {
334 asserts = core.getBuiltin(Layer0.URIs.Asserts);
335 assert (asserts != 0);
339 if (builtinsInstalled) {
340 hasPredicate = core.getBuiltin(Layer0.URIs.HasPredicate);
341 assert (hasPredicate != 0);
345 if (builtinsInstalled) {
346 hasPredicateInverse = core.getBuiltin(Layer0.URIs.HasPredicateInverse);
347 assert (hasPredicateInverse != 0);
349 hasPredicateInverse = 0;
351 if (builtinsInstalled) {
352 hasObject = core.getBuiltin(Layer0.URIs.HasObject);
353 assert (hasObject != 0);
357 if (builtinsInstalled) {
358 subrelationOf = core.getBuiltin(Layer0.URIs.SubrelationOf);
359 assert (subrelationOf != 0);
363 if (builtinsInstalled) {
364 superrelationOf = core.getBuiltin(Layer0.URIs.SuperrelationOf);
365 assert (superrelationOf != 0);
369 if (builtinsInstalled) {
370 library = core.getBuiltin(Layer0.URIs.Library);
371 assert (library != 0);
375 if (builtinsInstalled) {
376 consistsOf = core.getBuiltin(Layer0.URIs.ConsistsOf);
377 assert (consistsOf != 0);
381 if (builtinsInstalled) {
382 hasName = core.getBuiltin(Layer0.URIs.HasName);
383 assert (hasName != 0);
389 final public void releaseWrite(ReadGraphImpl graph) {
390 propagateChangesInQueryCache(graph);
391 modificationCounter++;
394 final public int getId(final Resource r) {
395 return querySupport.getId(r);
398 public QuerySupport getCore() {
402 public int getFunctionalRelation() {
403 return functionalRelation;
406 public int getInherits() {
410 public int getInstanceOf() {
414 public int getInverseOf() {
418 public int getSubrelationOf() {
419 return subrelationOf;
422 public int getSuperrelationOf() {
423 return superrelationOf;
426 public int getAsserts() {
430 public int getHasPredicate() {
434 public int getHasPredicateInverse() {
435 return hasPredicateInverse;
438 public int getHasObject() {
442 public int getRootLibrary() {
446 public Resource getRootLibraryResource() {
447 if (rootLibraryResource == null) {
448 // Synchronization is not needed here, it doesn't matter if multiple
449 // threads simultaneously set rootLibraryResource once.
450 int root = getRootLibrary();
452 throw new UnsupportedOperationException("database is not initialized, cannot get root library resource");
453 this.rootLibraryResource = new ResourceImpl(querySupport.getSupport(), root);
455 return rootLibraryResource;
458 public int getLibrary() {
462 public int getConsistsOf() {
466 public int getHasName() {
470 public void forResource(ReadGraphImpl graph, final String id, CacheEntry parent, final InternalProcedure<Integer> procedure) {
474 QueryCache.runnerURIToResource(graph, id, parent, null, new InternalProcedure<Integer>() {
477 public void execute(ReadGraphImpl graph, Integer result) throws DatabaseException {
479 if (result != null && result != 0) {
480 procedure.execute(graph, result);
484 // Fall back to using the fixed builtins.
485 // result = querySupport.getBuiltin(id);
486 // if (result != 0) {
487 // procedure.execute(graph, result);
492 // result = querySupport.getRandomAccessReference(id);
493 // } catch (ResourceNotFoundException e) {
494 // procedure.exception(graph, e);
499 procedure.execute(graph, result);
501 procedure.exception(graph, new ResourceNotFoundException(id));
507 public void exception(ReadGraphImpl graph, Throwable t) throws DatabaseException {
508 procedure.exception(graph, t);
512 } catch (DatabaseException e) {
516 procedure.exception(graph, e);
518 } catch (DatabaseException e1) {
520 Logger.defaultLogError(e1);
528 public void forBuiltin(ReadGraphImpl graph, final String id, CacheEntry parent, final InternalProcedure<Integer> procedure) throws DatabaseException {
530 Integer result = querySupport.getBuiltin(id);
532 procedure.execute(graph, result);
534 procedure.exception(graph, new ResourceNotFoundException(id));
539 final <T> void runMultiRead(final ReadGraphImpl graph, MultiReadEntry cached, final MultiRead<T> query, final CacheEntry parent, final QueryProcessor provider, final ListenerBase listener, final SyncMultiProcedure<T> procedure) {
542 QueryCache.runnerMultiReadEntry(graph, query, parent, listener, procedure);
543 } catch (DatabaseException e) {
544 throw new IllegalStateException(e);
549 public final <T> void runAsyncMultiRead(final ReadGraphImpl graph, final AsyncMultiRead<T> query, final CacheEntry parent, final ListenerBase listener, final AsyncMultiProcedure<T> procedure) {
553 QueryCache.runnerAsyncMultiReadEntry(graph, query, parent, listener, procedure);
554 } catch (DatabaseException e) {
555 throw new IllegalStateException(e);
560 final <T> void runPrimitiveRead(ReadGraphImpl graph, ExternalReadEntry cached, final ExternalRead<T> query, final CacheEntry parent, final QueryProcessor provider, final ListenerBase listener, final AsyncProcedure<T> procedure) throws DatabaseException {
561 QueryCache.runnerExternalReadEntry(graph, query, parent, listener, procedure);
565 // public <T> T query(final ReadGraphImpl graph, final Read<T> query, final CacheEntry parent, final AsyncProcedure<T> procedure, final ListenerBase listener) throws DatabaseException {
567 // return QueryCache.resultReadEntry(graph, query, parent, listener, procedure);
571 public <T> void queryMultiRead(final ReadGraphImpl graph, final MultiRead<T> query, final CacheEntry parent, final ListenerBase listener, final SyncMultiProcedure<T> procedure) throws DatabaseException {
573 QueryCache.runnerMultiReadEntry(graph, query, parent, listener, procedure);
577 public <T> void queryPrimitiveRead(final ReadGraphImpl graph, final ExternalRead<T> query, final CacheEntry parent, final ListenerBase listener, final AsyncProcedure<T> procedure) throws DatabaseException {
579 QueryCache.runnerExternalReadEntry(graph, query, parent, listener, procedure);
583 boolean isBound(ExternalReadEntry<?> entry) {
584 if(entry.hasParents()) return true;
585 else if(listening.hasListener(entry)) return true;
589 static class Dummy implements InternalProcedure<Object>, IntProcedure {
592 public void execute(ReadGraphImpl graph, int i) {
596 public void finished(ReadGraphImpl graph) {
600 public void execute(ReadGraphImpl graph, Object result) {
604 public void exception(ReadGraphImpl graph, Throwable throwable) {
609 private static final Dummy dummy = new Dummy();
612 public <Procedure> Object performForEach2(ReadGraphImpl graph, UnaryQuery<Procedure> query, CacheEntry parent, ListenerBase listener, Procedure procedure) throws Throwable {
614 if (DebugPolicy.PERFORM)
615 System.out.println("PE[ " + (query.hashCode() & THREAD_MASK) + "] " + query);
618 assert (!collecting);
620 assert(query.assertNotDiscarded());
622 registerDependencies(graph, query, parent, listener, procedure, false);
624 // FRESH, REFUTED, EXCEPTED go here
625 if (!query.isReady()) {
630 query.computeForEach(graph, this, (Procedure)dummy, true);
631 return query.get(graph, this, null);
637 return query.get(graph, this, procedure);
645 interface QueryCollectorSupport {
646 public CacheCollectionResult allCaches();
647 public Collection<CacheEntry> getRootList();
648 public int getCurrentSize();
649 public int calculateCurrentSize();
650 public CacheEntryBase iterate(int level);
651 public void remove();
652 public void setLevel(CacheEntryBase entry, int level);
653 public boolean start(boolean flush);
656 interface QueryCollector {
658 public void collect(int youngTarget, int allowedTimeInMs);
662 class QueryCollectorSupportImpl implements QueryCollectorSupport {
664 private static final boolean DEBUG = false;
665 private static final double ITERATION_RATIO = 0.2;
667 private CacheCollectionResult iteration = new CacheCollectionResult();
668 private boolean fresh = true;
669 private boolean needDataInStart = true;
671 QueryCollectorSupportImpl() {
675 public CacheCollectionResult allCaches() {
676 CacheCollectionResult result = new CacheCollectionResult();
677 QueryProcessor.this.allCaches(result);
682 public boolean start(boolean flush) {
683 // We need new data from query maps
685 if(needDataInStart || flush) {
686 // Last run ended after processing all queries => refresh data
687 restart(flush ? 0.0 : ITERATION_RATIO);
689 // continue with previous big data
691 // Notify caller about iteration situation
692 return iteration.isAtStart();
695 private void restart(double targetRatio) {
697 needDataInStart = true;
699 long start = System.nanoTime();
702 // We need new data from query maps
704 int iterationSize = iteration.size()+1;
705 int diff = calculateCurrentSize()-iterationSize;
707 double ratio = (double)diff / (double)iterationSize;
708 boolean dirty = Math.abs(ratio) >= targetRatio;
711 iteration = allCaches();
713 System.err.print("iterate: allCaches in " + 1e-9*(System.nanoTime()-start) + "s. (" + iteration.size() + ") ");
714 for(int i=0;i<CacheCollectionResult.LEVELS;i++)
715 System.err.print(" " + iteration.levels[i].size());
716 System.err.println("");
723 needDataInStart = false;
725 // We are returning here within the same GC round - reuse the cache table
734 public CacheEntryBase iterate(int level) {
736 CacheEntryBase entry = iteration.next(level);
738 restart(ITERATION_RATIO);
742 while(entry != null && entry.isDiscarded()) {
743 entry = iteration.next(level);
751 public void remove() {
756 public void setLevel(CacheEntryBase entry, int level) {
757 iteration.setLevel(entry, level);
760 public Collection<CacheEntry> getRootList() {
761 return cache.getRootList();
765 public int calculateCurrentSize() {
766 return cache.calculateCurrentSize();
770 public int getCurrentSize() {
775 // final private static int MINIMUM_SIZE = (int)(Runtime.getRuntime().maxMemory() / 600);
777 private QueryCollectorSupport collectorSupport = new QueryCollectorSupportImpl();
778 private QueryCollector collector = new QueryCollectorImpl(this, collectorSupport);
780 public int querySize() {
784 public void gc(int youngTarget, int allowedTimeInMs) {
786 collector.collect(youngTarget, allowedTimeInMs);
791 void processParentReport(CacheEntry entry, Map<CacheEntry, Set<CacheEntry>> workarea) {
793 if(entry.isDiscarded()) return;
794 if(workarea.containsKey(entry)) return;
796 Iterable<CacheEntry> parents = entry.getParents(this);
797 HashSet<CacheEntry> ps = new HashSet<CacheEntry>();
798 for(CacheEntry e : parents) {
799 if(e.isDiscarded()) continue;
801 processParentReport(e, workarea);
803 workarea.put(entry, ps);
807 public synchronized String reportQueryActivity(File file) throws IOException {
809 System.err.println("reportQueries " + file.getAbsolutePath());
814 PrintStream b = new PrintStream(new BufferedOutputStream(new FileOutputStream(file)));
816 List<Pair<String,Integer>> entries = CollectionUtils.valueSortedEntries(Development.histogram);
817 Collections.reverse(entries);
819 for(Pair<String,Integer> entry : entries) {
820 b.println(entry.first + ": " + entry.second);
825 Development.histogram.clear();
831 public synchronized String reportQueries(File file) throws IOException {
833 System.err.println("reportQueries " + file.getAbsolutePath());
838 PrintStream b = new PrintStream(new BufferedOutputStream(new FileOutputStream(file)));
840 long start = System.nanoTime();
842 // ArrayList<CacheEntry> all = ;
844 Map<CacheEntry, Set<CacheEntry>> workarea = new HashMap<CacheEntry, Set<CacheEntry>>();
845 Collection<CacheEntryBase> caches = allCaches(new CacheCollectionResult()).toCollection();
846 for(CacheEntryBase entry : caches) {
847 processParentReport(entry, workarea);
850 // for(CacheEntry e : all) System.err.println("entry: " + e);
852 long duration = System.nanoTime() - start;
853 System.err.println("Query root set in " + 1e-9*duration + "s.");
855 start = System.nanoTime();
857 HashMap<CacheEntry, Integer> flagMap = new HashMap<CacheEntry, Integer>();
861 for(CacheEntry entry : workarea.keySet()) {
862 boolean listener = listening.hasListenerAfterDisposing(entry);
863 boolean hasParents = entry.getParents(this).iterator().hasNext();
866 flagMap.put(entry, 0);
867 } else if (!hasParents) {
869 flagMap.put(entry, 1);
872 flagMap.put(entry, 2);
885 long start2 = System.nanoTime();
887 int boundCounter = 0;
888 int unboundCounter = 0;
889 int unknownCounter = 0;
891 for(CacheEntry<?> entry : workarea.keySet()) {
893 //System.err.println("process " + entry);
895 int flags = flagMap.get(entry);
896 int bindStatus = flags & 3;
898 if(bindStatus == 0) boundCounter++;
899 else if(bindStatus == 1) unboundCounter++;
900 else if(bindStatus == 2) unknownCounter++;
902 if(bindStatus < 2) continue;
905 for(CacheEntry parent : entry.getParents(this)) {
907 if(parent.isDiscarded()) flagMap.put(parent, 1);
909 int flags2 = flagMap.get(parent);
910 int bindStatus2 = flags2 & 3;
911 // Parent is bound => child is bound
912 if(bindStatus2 == 0) {
916 // Parent is unknown => child is unknown
917 else if (bindStatus2 == 2) {
924 flagMap.put(entry, newStatus);
928 duration = System.nanoTime() - start2;
929 System.err.println("Query analysis pass (" + boundCounter + "/" + unboundCounter + "/" + unknownCounter + ") in "+ 1e-9*duration + "s.");
930 b.println("Query analysis pass (" + boundCounter + "/" + unboundCounter + "/" + unknownCounter + ") in "+ 1e-9*duration + "s.");
932 } while(!done && loops++ < 20);
936 for(CacheEntry entry : workarea.keySet()) {
938 int bindStatus = flagMap.get(entry);
939 if(bindStatus == 2) System.err.println("Undefined bind status for " + entry);
945 duration = System.nanoTime() - start;
946 System.err.println("Query analysis in " + 1e-9*duration + "s.");
948 Map<Class<?>, Integer> counts = new HashMap<Class<?>, Integer>();
950 for(CacheEntry entry : workarea.keySet()) {
951 Class<?> clazz = entry.getClass();
952 if(entry instanceof ReadEntry) clazz = ((ReadEntry)entry).id.getClass();
953 else if(entry instanceof MultiReadEntry) clazz = ((MultiReadEntry)entry).id.getClass();
954 else if(entry instanceof AsyncReadEntry) clazz = ((AsyncReadEntry)entry).id.getClass();
955 else if(entry instanceof AsyncMultiReadEntry) clazz = ((AsyncMultiReadEntry)entry).id.getClass();
956 else if(entry instanceof ExternalReadEntry) clazz = ((ExternalReadEntry)entry).id.getClass();
957 Integer c = counts.get(clazz);
958 if(c == null) counts.put(clazz, -1);
959 else counts.put(clazz, c-1);
962 b.print("// Simantics DB client query report file\n");
963 b.print("// This file contains the following information\n");
964 b.print("// -The amount of cached query instances per query class\n");
965 b.print("// -The sizes of retained child sets\n");
966 b.print("// -List of parents for each query (search for 'P <query name>')\n");
967 b.print("// -Followed by status, where\n");
968 b.print("// -0=bound\n");
969 b.print("// -1=free\n");
970 b.print("// -2=unknown\n");
971 b.print("// -L=has listener\n");
972 b.print("// -List of children for each query (search for 'C <query name>')\n");
974 b.print("----------------------------------------\n");
976 b.print("// Queries by class\n");
977 for(Pair<Class<?>, Integer> p : CollectionUtils.valueSortedEntries(counts)) {
978 b.print(-p.second + " " + p.first.getName() + "\n");
981 Map<CacheEntry, Integer> hist = new HashMap<CacheEntry, Integer>();
982 for(CacheEntry e : workarea.keySet())
985 boolean changed = true;
987 while(changed && iter++<50) {
991 Map<CacheEntry, Integer> newHist = new HashMap<CacheEntry, Integer>();
992 for(CacheEntry e : workarea.keySet())
995 for(Map.Entry<CacheEntry, Set<CacheEntry>> e : workarea.entrySet()) {
996 Integer c = hist.get(e.getKey());
997 for(CacheEntry p : e.getValue()) {
998 Integer i = newHist.get(p);
1002 for(CacheEntry e : workarea.keySet()) {
1003 Integer value = newHist.get(e);
1004 Integer old = hist.get(e);
1005 if(!value.equals(old)) {
1007 // System.err.println("hist " + e + ": " + old + " => " + value);
1012 System.err.println("Retained set iteration " + iter);
1016 b.print("// Queries by retained set\n");
1017 for(Pair<CacheEntry, Integer> p : CollectionUtils.valueSortedEntries(hist)) {
1018 b.print("" + -p.second + " " + p.first + "\n");
1021 HashMap<CacheEntry, Collection<CacheEntry>> inverse = new HashMap<CacheEntry, Collection<CacheEntry>>();
1023 b.print("// Entry parent listing\n");
1024 for(CacheEntry entry : workarea.keySet()) {
1025 int status = flagMap.get(entry);
1026 boolean hasListener = listening.hasListenerAfterDisposing(entry);
1027 b.print("Q " + entry.toString());
1029 b.print(" (L" + status + ")");
1032 b.print(" (" + status + ")");
1035 for(CacheEntry parent : workarea.get(entry)) {
1036 Collection<CacheEntry> inv = inverse.get(parent);
1038 inv = new ArrayList<CacheEntry>();
1039 inverse.put(parent, inv);
1042 b.print(" " + parent.toString());
1047 b.print("// Entry child listing\n");
1048 for(Map.Entry<CacheEntry, Collection<CacheEntry>> entry : inverse.entrySet()) {
1049 b.print("C " + entry.getKey().toString());
1051 for(CacheEntry child : entry.getValue()) {
1052 Integer h = hist.get(child);
1056 b.print(" <no children>");
1058 b.print(" " + child.toString());
1063 b.print("#queries: " + workarea.keySet().size() + "\n");
1064 b.print("#listeners: " + listeners + "\n");
1068 return "Dumped " + workarea.keySet().size() + " queries.";
1072 boolean removeQuery(CacheEntry entry) {
1074 // This entry has been removed before. No need to do anything here.
1075 if(entry.isDiscarded()) return false;
1077 assert (!entry.isDiscarded());
1079 Query query = entry.getQuery();
1081 query.removeEntry(this);
1086 if((entry.getGCStatus() & CacheEntry.HAS_BEEN_BOUND) != 0)
1097 * @return true if this entry is being listened
1099 private boolean updateQuery(UpdateEntry e, LinkedList<UpdateEntry> todo, IdentityHashMap<CacheEntry, CacheEntry> immediates) throws DatabaseException {
1103 CacheEntry entry = e.entry;
1106 * If the dependency graph forms a DAG, some entries are inserted in the
1107 * todo list many times. They only need to be processed once though.
1109 if (entry.isDiscarded()) {
1110 if (Development.DEVELOPMENT) {
1111 if(Development.<Boolean>getProperty(DevelopmentKeys.QUERYPROCESSOR_UPDATE, Bindings.BOOLEAN)) {
1112 System.err.print("D");
1113 for (int i = 0; i < e.indent; i++)
1114 System.err.print(" ");
1115 System.err.println(entry.getQuery());
1118 // System.err.println(" => DISCARDED");
1122 // if (entry.isRefuted()) {
1123 // if (Development.DEVELOPMENT) {
1124 // if(Development.<Boolean>getProperty(DevelopmentKeys.QUERYPROCESSOR_UPDATE, Bindings.BOOLEAN)) {
1125 // System.err.print("R");
1126 // for (int i = 0; i < e.indent; i++)
1127 // System.err.print(" ");
1128 // System.err.println(entry.getQuery());
1134 if (entry.isExcepted()) {
1135 if (Development.DEVELOPMENT) {
1136 if(Development.<Boolean>getProperty(DevelopmentKeys.QUERYPROCESSOR_UPDATE, Bindings.BOOLEAN)) {
1137 System.err.print("E");
1142 if (entry.isPending()) {
1143 if (Development.DEVELOPMENT) {
1144 if(Development.<Boolean>getProperty(DevelopmentKeys.QUERYPROCESSOR_UPDATE, Bindings.BOOLEAN)) {
1145 System.err.print("P");
1152 if (Development.DEVELOPMENT) {
1153 if(Development.<Boolean>getProperty(DevelopmentKeys.QUERYPROCESSOR_UPDATE, Bindings.BOOLEAN)) {
1154 System.err.print("U ");
1155 for (int i = 0; i < e.indent; i++)
1156 System.err.print(" ");
1157 System.err.print(entry.getQuery());
1161 Query query = entry.getQuery();
1162 int type = query.type();
1164 boolean hasListener = listening.hasListener(entry);
1166 if (Development.DEVELOPMENT) {
1167 if(Development.<Boolean>getProperty(DevelopmentKeys.QUERYPROCESSOR_UPDATE, Bindings.BOOLEAN)) {
1168 if(listening.hasListener(entry)) {
1169 System.err.println(" (L)");
1171 System.err.println("");
1176 if(entry.isPending() || entry.isExcepted()) {
1179 if ((type & RequestFlags.UPDATE_MASK) == RequestFlags.IMMEDIATE_UPDATE) {
1181 immediates.put(entry, entry);
1196 if ((type & RequestFlags.UPDATE_MASK) == RequestFlags.IMMEDIATE_UPDATE) {
1198 immediates.put(entry, entry);
1212 // System.err.println(" => FOO " + type);
1215 ArrayList<ListenerEntry> entries = listening.listeners.get(entry);
1216 if(entries != null) {
1217 for (ListenerEntry le : entries) {
1218 listening.scheduleListener(le);
1223 // If invalid, update parents
1224 if (type == RequestFlags.INVALIDATE) {
1225 listening.updateParents(e.indent, entry, todo);
1233 * @param av1 an array (guaranteed)
1234 * @param av2 any object
1235 * @return <code>true</code> if the two arrays are equal
1237 private final boolean arrayEquals(Object av1, Object av2) {
1240 Class<?> c1 = av1.getClass().getComponentType();
1241 Class<?> c2 = av2.getClass().getComponentType();
1242 if (c2 == null || !c1.equals(c2))
1244 boolean p1 = c1.isPrimitive();
1245 boolean p2 = c2.isPrimitive();
1249 return Arrays.equals((Object[]) av1, (Object[]) av2);
1250 if (boolean.class.equals(c1))
1251 return Arrays.equals((boolean[]) av1, (boolean[]) av2);
1252 else if (byte.class.equals(c1))
1253 return Arrays.equals((byte[]) av1, (byte[]) av2);
1254 else if (int.class.equals(c1))
1255 return Arrays.equals((int[]) av1, (int[]) av2);
1256 else if (long.class.equals(c1))
1257 return Arrays.equals((long[]) av1, (long[]) av2);
1258 else if (float.class.equals(c1))
1259 return Arrays.equals((float[]) av1, (float[]) av2);
1260 else if (double.class.equals(c1))
1261 return Arrays.equals((double[]) av1, (double[]) av2);
1262 throw new RuntimeException("??? Contact application querySupport.");
1267 final Object compareTo(ReadGraphImpl graph, final CacheEntry entry, final Object oldValue) {
1271 Query query = entry.getQuery();
1273 if (Development.DEVELOPMENT) {
1274 if(Development.<Boolean>getProperty(DevelopmentKeys.QUERYPROCESSOR_RECOMPUTE, Bindings.BOOLEAN)) {
1275 System.err.println("R " + query);
1279 entry.prepareRecompute(querySupport);
1281 ReadGraphImpl parentGraph = graph.forRecompute(entry);
1283 query.recompute(parentGraph);
1285 if(entry.isExcepted()) return ListenerEntry.NO_VALUE;
1287 Object newValue = entry.getResult();
1289 if (ListenerEntry.NO_VALUE == oldValue) {
1290 if (Development.DEVELOPMENT) {
1291 if(Development.<Boolean>getProperty(DevelopmentKeys.QUERYPROCESSOR_CHANGES, Bindings.BOOLEAN)) {
1292 System.out.println("C " + query);
1293 System.out.println("- " + oldValue);
1294 System.out.println("- " + newValue);
1300 boolean changed = false;
1302 if (newValue != null) {
1303 if (newValue.getClass().isArray()) {
1304 changed = !arrayEquals(newValue, oldValue);
1306 changed = !newValue.equals(oldValue);
1309 changed = (oldValue != null);
1311 if (Development.DEVELOPMENT) {
1312 if(Development.<Boolean>getProperty(DevelopmentKeys.QUERYPROCESSOR_CHANGES, Bindings.BOOLEAN)) {
1313 System.err.println("C " + query);
1314 System.err.println("- " + oldValue);
1315 System.err.println("- " + newValue);
1319 return changed ? newValue : ListenerEntry.NOT_CHANGED;
1321 } catch (Throwable t) {
1323 Logger.defaultLogError(t);
1325 return ListenerEntry.NO_VALUE;
1334 * @return true if this entry still has listeners
1336 public boolean update(final ReadGraphImpl graph, final CacheEntry entry) {
1338 assert (!cache.collecting);
1342 boolean hadListeners = false;
1343 boolean listenersUnknown = false;
1347 assert(entry != null);
1348 LinkedList<UpdateEntry> todo = new LinkedList<UpdateEntry>();
1349 IdentityHashMap<CacheEntry, CacheEntry> immediates = new IdentityHashMap<CacheEntry, CacheEntry>();
1350 todo.add(new UpdateEntry(null, entry, 0));
1354 // Walk the tree and collect immediate updates
1355 while (!todo.isEmpty()) {
1356 UpdateEntry e = todo.pop();
1357 hadListeners |= updateQuery(e, todo, immediates);
1360 if(immediates.isEmpty()) break;
1362 // Evaluate all immediate updates and collect parents to update
1363 for(CacheEntry immediate : immediates.values()) {
1365 if(immediate.isDiscarded()) {
1369 if(immediate.isExcepted()) {
1371 Object newValue = compareTo(graph, immediate, ListenerEntry.NO_VALUE);
1372 if (newValue != ListenerEntry.NOT_CHANGED)
1373 listening.updateParents(0, immediate, todo);
1377 Object oldValue = immediate.getResult();
1378 Object newValue = compareTo(graph, immediate, oldValue);
1380 if (newValue != ListenerEntry.NOT_CHANGED) {
1381 listening.updateParents(0, immediate, todo);
1383 // If not changed, keep the old value
1384 immediate.setResult(oldValue);
1385 immediate.setReady();
1386 listenersUnknown = true;
1396 } catch (Throwable t) {
1397 Logger.defaultLogError(t);
1403 return hadListeners | listenersUnknown;
1407 private ObjectUpdateSet scheduledObjectUpdates = new ObjectUpdateSet();
1408 private ValueUpdateSet scheduledValueUpdates = new ValueUpdateSet();
1409 private ValueUpdateSet scheduledInvalidates = new ValueUpdateSet();
1410 // Maybe use a mutex from util.concurrent?
1411 private Object primitiveUpdateLock = new Object();
1412 private THashSet scheduledPrimitiveUpdates = new THashSet();
1414 private ArrayList<CacheEntry> refutations = new ArrayList<>();
1416 private void markForUpdate(ReadGraphImpl graph, CacheEntry e) {
1421 private void updateRefutations(ReadGraphImpl graph) {
1423 for(CacheEntry e : refutations)
1426 refutations.clear();
1430 public void propagateChangesInQueryCache(final ReadGraphImpl graph) {
1432 // Make sure that listening has performed its work
1435 cache.dirty = false;
1438 if (Development.DEVELOPMENT) {
1439 if(Development.<Boolean>getProperty(DevelopmentKeys.QUERYPROCESSOR_UPDATE, Bindings.BOOLEAN)) {
1440 System.err.println("== Query update ==");
1444 // Special case - one statement
1445 if(scheduledObjectUpdates.size() == 1 && scheduledValueUpdates.size() == 0 && scheduledPrimitiveUpdates.size() == 0 && scheduledInvalidates.size() == 0) {
1447 long arg0 = scheduledObjectUpdates.getFirst();
1449 final int subject = (int)(arg0 >>> 32);
1450 final int predicate = (int)(arg0 & 0xffffffff);
1452 for(Objects o : QueryCache.entriesObjects(QueryProcessor.this, subject)) markForUpdate(graph, o);
1453 for(DirectObjects o : QueryCache.entriesDirectObjects(QueryProcessor.this, subject)) markForUpdate(graph, o);
1454 for(Statements o : QueryCache.entriesStatements(QueryProcessor.this, subject)) markForUpdate(graph, o);
1456 if(predicate == instanceOf || predicate == inherits || predicate == subrelationOf) {
1457 PrincipalTypes principalTypes = QueryCache.entryPrincipalTypes(QueryProcessor.this, subject);
1458 if(principalTypes != null) markForUpdate(graph, principalTypes);
1459 Types types = QueryCache.entryTypes(QueryProcessor.this, subject);
1460 if(types != null) markForUpdate(graph, types);
1463 if(predicate == subrelationOf) {
1464 SuperRelations superRelations = SuperRelations.entry(QueryProcessor.this, subject);
1465 if(superRelations != null) markForUpdate(graph, superRelations);
1468 DirectPredicates dp = QueryCache.entryDirectPredicates(QueryProcessor.this, subject);
1469 if(dp != null) markForUpdate(graph, dp);
1470 OrderedSet os = QueryCache.entryOrderedSet(QueryProcessor.this, predicate);
1471 if(os != null) markForUpdate(graph, os);
1473 updateRefutations(graph);
1475 scheduledObjectUpdates.clear();
1477 if (Development.DEVELOPMENT) {
1478 if(Development.<Boolean>getProperty(DevelopmentKeys.QUERYPROCESSOR_UPDATE, Bindings.BOOLEAN)) {
1479 System.err.println("== Query update ends ==");
1487 // Special case - one value
1488 if(scheduledObjectUpdates.size() == 0 && scheduledValueUpdates.size() == 1 && scheduledPrimitiveUpdates.size() == 0 && scheduledInvalidates.size() == 0) {
1490 int arg0 = scheduledValueUpdates.getFirst();
1492 ValueQuery valueQuery = QueryCache.entryValueQuery(QueryProcessor.this, arg0);
1493 if(valueQuery != null) markForUpdate(graph, valueQuery);
1495 updateRefutations(graph);
1497 scheduledValueUpdates.clear();
1499 if (Development.DEVELOPMENT) {
1500 if(Development.<Boolean>getProperty(DevelopmentKeys.QUERYPROCESSOR_UPDATE, Bindings.BOOLEAN)) {
1501 System.err.println("== Query update ends ==");
1509 final TIntHashSet predicates = new TIntHashSet();
1510 final TIntHashSet orderedSets = new TIntHashSet();
1512 THashSet primitiveUpdates;
1513 synchronized (primitiveUpdateLock) {
1514 primitiveUpdates = scheduledPrimitiveUpdates;
1515 scheduledPrimitiveUpdates = new THashSet();
1518 scheduledValueUpdates.forEach(new TIntProcedure() {
1521 public boolean execute(int arg0) {
1522 ValueQuery valueQuery = QueryCache.entryValueQuery(QueryProcessor.this, arg0);
1523 if(valueQuery != null) markForUpdate(graph, valueQuery);
1529 scheduledInvalidates.forEach(new TIntProcedure() {
1532 public boolean execute(int resource) {
1534 ValueQuery valueQuery = QueryCache.entryValueQuery(QueryProcessor.this, resource);
1535 if(valueQuery != null) markForUpdate(graph, valueQuery);
1537 PrincipalTypes principalTypes = QueryCache.entryPrincipalTypes(QueryProcessor.this, resource);
1538 if(principalTypes != null) markForUpdate(graph, principalTypes);
1539 Types types = QueryCache.entryTypes(QueryProcessor.this, resource);
1540 if(types != null) markForUpdate(graph, types);
1542 SuperRelations superRelations = SuperRelations.entry(QueryProcessor.this, resource);
1543 if(superRelations != null) markForUpdate(graph, superRelations);
1545 predicates.add(resource);
1552 scheduledObjectUpdates.forEach(new TLongProcedure() {
1555 public boolean execute(long arg0) {
1557 final int subject = (int)(arg0 >>> 32);
1558 final int predicate = (int)(arg0 & 0xffffffff);
1560 if(predicate == instanceOf || predicate == inherits || predicate == subrelationOf) {
1561 PrincipalTypes principalTypes = QueryCache.entryPrincipalTypes(QueryProcessor.this, subject);
1562 if(principalTypes != null) markForUpdate(graph, principalTypes);
1563 Types types = QueryCache.entryTypes(QueryProcessor.this, subject);
1564 if(types != null) markForUpdate(graph, types);
1567 if(predicate == subrelationOf) {
1568 SuperRelations superRelations = SuperRelations.entry(QueryProcessor.this, subject);
1569 if(superRelations != null) markForUpdate(graph, superRelations);
1572 predicates.add(subject);
1573 orderedSets.add(predicate);
1581 predicates.forEach(new TIntProcedure() {
1584 public boolean execute(final int subject) {
1586 for(Objects o : QueryCache.entriesObjects(QueryProcessor.this, subject)) markForUpdate(graph, o);
1587 for(DirectObjects o : QueryCache.entriesDirectObjects(QueryProcessor.this, subject)) markForUpdate(graph, o);
1588 for(Statements o : QueryCache.entriesStatements(QueryProcessor.this, subject)) markForUpdate(graph, o);
1590 DirectPredicates entry = QueryCache.entryDirectPredicates(QueryProcessor.this, subject);
1591 if(entry != null) markForUpdate(graph, entry);
1599 orderedSets.forEach(new TIntProcedure() {
1602 public boolean execute(int orderedSet) {
1604 OrderedSet entry = QueryCache.entryOrderedSet(QueryProcessor.this, orderedSet);
1605 if(entry != null) markForUpdate(graph, entry);
1613 updateRefutations(graph);
1615 primitiveUpdates.forEach(new TObjectProcedure() {
1618 public boolean execute(Object arg0) {
1620 ExternalReadEntry query = (ExternalReadEntry)cache.externalReadEntryMap.get(arg0);
1621 if (query != null) {
1622 boolean listening = update(graph, query);
1623 if (!listening && !query.hasParents()) {
1624 cache.externalReadEntryMap.remove(arg0);
1633 scheduledValueUpdates.clear();
1634 scheduledObjectUpdates.clear();
1635 scheduledInvalidates.clear();
1637 if (Development.DEVELOPMENT) {
1638 if(Development.<Boolean>getProperty(DevelopmentKeys.QUERYPROCESSOR_UPDATE, Bindings.BOOLEAN)) {
1639 System.err.println("== Query update ends ==");
1645 public void updateValue(final int resource) {
1646 scheduledValueUpdates.add(resource);
1650 public void updateStatements(final int resource, final int predicate) {
1651 scheduledObjectUpdates.add((((long)resource) << 32) + predicate);
1655 private int lastInvalidate = 0;
1657 public void invalidateResource(final int resource) {
1658 if(lastInvalidate == resource) return;
1659 scheduledValueUpdates.add(resource);
1660 lastInvalidate = resource;
1664 public void updatePrimitive(final ExternalRead primitive) {
1666 // External reads may be updated from arbitrary threads.
1667 // Synchronize to prevent race-conditions.
1668 synchronized (primitiveUpdateLock) {
1669 scheduledPrimitiveUpdates.add(primitive);
1671 querySupport.dirtyPrimitives();
1676 public synchronized String toString() {
1677 return "QueryProvider [size = " + cache.size + ", hits = " + cache.hits + " misses = " + cache.misses + ", updates = " + cache.updates + "]";
1681 protected void doDispose() {
1683 requests.release(Integer.MAX_VALUE / 2);
1685 for(int index = 0; index < THREADS; index++) {
1686 executors[index].dispose();
1690 for(int i=0;i<100;i++) {
1692 boolean alive = false;
1693 for(int index = 0; index < THREADS; index++) {
1694 alive |= executors[index].isAlive();
1699 } catch (InterruptedException e) {
1700 Logger.defaultLogError(e);
1705 // Then start interrupting
1706 for(int i=0;i<100;i++) {
1708 boolean alive = false;
1709 for(int index = 0; index < THREADS; index++) {
1710 alive |= executors[index].isAlive();
1713 for(int index = 0; index < THREADS; index++) {
1714 executors[index].interrupt();
1718 // // Then just destroy
1719 // for(int index = 0; index < THREADS; index++) {
1720 // executors[index].destroy();
1723 for(int index = 0; index < THREADS; index++) {
1725 executors[index].join(5000);
1726 } catch (InterruptedException e) {
1727 Logger.defaultLogError("QueryThread " + index + " will not die.", e);
1729 executors[index] = null;
1734 public int getHits() {
1738 public int getMisses() {
1739 return cache.misses;
1742 public int getSize() {
1746 public Set<Long> getReferencedClusters() {
1747 HashSet<Long> result = new HashSet<Long>();
1748 for (CacheEntry entry : QueryCache.entriesObjects(this)) {
1749 Objects query = (Objects) entry.getQuery();
1750 result.add(querySupport.getClusterId(query.r1()));
1752 for (CacheEntry entry : QueryCache.entriesDirectPredicates(this)) {
1753 DirectPredicates query = (DirectPredicates) entry.getQuery();
1754 result.add(querySupport.getClusterId(query.id));
1756 for (CacheEntry entry : cache.valueQueryMap.values()) {
1757 ValueQuery query = (ValueQuery) entry.getQuery();
1758 result.add(querySupport.getClusterId(query.id));
1763 public void assertDone() {
1766 CacheCollectionResult allCaches(CacheCollectionResult result) {
1768 return cache.allCaches(result);
1772 public void printDiagnostics() {
1775 public void requestCluster(ReadGraphImpl graph, long clusterId, Runnable runnable) {
1776 querySupport.requestCluster(graph, clusterId, runnable);
1779 public int clean() {
1780 collector.collect(0, Integer.MAX_VALUE);
1784 public void clean(final Collection<ExternalRead<?>> requests) {
1785 QueryCollectorSupport collectorSupport = new QueryCollectorSupport() {
1786 Iterator<ExternalRead<?>> iterator = requests.iterator();
1788 public CacheCollectionResult allCaches() {
1789 throw new UnsupportedOperationException();
1792 public CacheEntryBase iterate(int level) {
1793 if(iterator.hasNext()) {
1794 ExternalRead<?> request = iterator.next();
1795 ExternalReadEntry entry = cache.externalReadEntryMap.get(request);
1796 if (entry != null) return entry;
1797 else return iterate(level);
1799 iterator = requests.iterator();
1804 public void remove() {
1805 throw new UnsupportedOperationException();
1808 public void setLevel(CacheEntryBase entry, int level) {
1809 throw new UnsupportedOperationException();
1812 public Collection<CacheEntry> getRootList() {
1813 ArrayList<CacheEntry> result = new ArrayList<CacheEntry>(requests.size());
1814 for (ExternalRead<?> request : requests) {
1815 ExternalReadEntry entry = cache.externalReadEntryMap.get(request);
1822 public int getCurrentSize() {
1826 public int calculateCurrentSize() {
1827 // This tells the collector to attempt collecting everything.
1828 return Integer.MAX_VALUE;
1831 public boolean start(boolean flush) {
1835 new QueryCollectorImpl2(this, collectorSupport).collect(0, Integer.MAX_VALUE);
1838 public void scanPending() {
1840 cache.scanPending();
1844 public ReadGraphImpl graphForVirtualRequest() {
1845 return ReadGraphImpl.createAsync(this);
1849 private HashMap<Resource, Class<?>> builtinValues;
1851 public Class<?> getBuiltinValue(Resource r) {
1852 if(builtinValues == null) initBuiltinValues();
1853 return builtinValues.get(r);
1856 Exception callerException = null;
1858 public interface AsyncBarrier {
1861 public void waitBarrier(Object request, ReadGraphImpl impl);
1862 public boolean isBlocking();
1865 // final public QueryProcessor processor;
1866 // final public QuerySupport support;
1868 // boolean disposed = false;
1870 private void initBuiltinValues() {
1872 Layer0 b = getSession().peekService(Layer0.class);
1873 if(b == null) return;
1875 builtinValues = new HashMap<Resource, Class<?>>();
1877 builtinValues.put(b.String, String.class);
1878 builtinValues.put(b.Double, Double.class);
1879 builtinValues.put(b.Float, Float.class);
1880 builtinValues.put(b.Long, Long.class);
1881 builtinValues.put(b.Integer, Integer.class);
1882 builtinValues.put(b.Byte, Byte.class);
1883 builtinValues.put(b.Boolean, Boolean.class);
1885 builtinValues.put(b.StringArray, String[].class);
1886 builtinValues.put(b.DoubleArray, double[].class);
1887 builtinValues.put(b.FloatArray, float[].class);
1888 builtinValues.put(b.LongArray, long[].class);
1889 builtinValues.put(b.IntegerArray, int[].class);
1890 builtinValues.put(b.ByteArray, byte[].class);
1891 builtinValues.put(b.BooleanArray, boolean[].class);
1895 // public ReadGraphSupportImpl(final QueryProcessor provider2) {
1897 // if (null == provider2) {
1898 // this.processor = null;
1902 // this.processor = provider2;
1903 // support = provider2.getCore();
1904 // initBuiltinValues();
1908 // final static public ReadGraphSupportImpl basedOn(ReadGraphSupportImpl impl) {
1909 // return new ReadGraphSupportImpl(impl.processor);
1913 final public Session getSession() {
1917 final public ResourceSupport getResourceSupport() {
1918 return resourceSupport;
1922 final public void forEachPredicate(final ReadGraphImpl impl, final Resource subject, final AsyncMultiProcedure<Resource> procedure) {
1926 for(Resource predicate : getPredicates(impl, subject))
1927 procedure.execute(impl, predicate);
1929 procedure.finished(impl);
1931 } catch (Throwable e) {
1932 procedure.exception(impl, e);
1938 final public void forEachPredicate(final ReadGraphImpl impl, final Resource subject, final MultiProcedure<Resource> procedure) {
1940 throw new UnsupportedOperationException();
1942 // assert(subject != null);
1943 // assert(procedure != null);
1945 // final ListenerBase listener = getListenerBase(procedure);
1948 // QueryCache.runnerPredicates(impl, querySupport.getId(subject), impl.parent, listener, new IntProcedure() {
1951 // public void execute(ReadGraphImpl graph, int i) {
1953 // procedure.execute(querySupport.getResource(i));
1954 // } catch (Throwable t2) {
1955 // Logger.defaultLogError(t2);
1960 // public void finished(ReadGraphImpl graph) {
1962 // procedure.finished();
1963 // } catch (Throwable t2) {
1964 // Logger.defaultLogError(t2);
1966 //// impl.state.barrier.dec();
1970 // public void exception(ReadGraphImpl graph, Throwable t) {
1972 // procedure.exception(t);
1973 // } catch (Throwable t2) {
1974 // Logger.defaultLogError(t2);
1976 //// impl.state.barrier.dec();
1980 // } catch (DatabaseException e) {
1981 // Logger.defaultLogError(e);
1987 final public IntSet getPredicates(final ReadGraphImpl impl, final Resource subject) throws Throwable {
1988 return QueryCacheBase.resultPredicates(impl, querySupport.getId(subject), impl.parent, null);
1992 final public void forEachStatement(final ReadGraphImpl impl, final Resource subject,
1993 final Resource predicate, final MultiProcedure<Statement> procedure) {
1995 assert(subject != null);
1996 assert(predicate != null);
1997 assert(procedure != null);
1999 final ListenerBase listener = getListenerBase(procedure);
2001 // impl.state.barrier.inc();
2004 Statements.queryEach(impl, querySupport.getId(subject), querySupport.getId(predicate), this, impl.parent, listener, new TripleIntProcedureAdapter() {
2007 public void execute(ReadGraphImpl graph, int s, int p, int o) {
2009 procedure.execute(querySupport.getStatement(s, p, o));
2010 } catch (Throwable t2) {
2011 Logger.defaultLogError(t2);
2016 public void finished(ReadGraphImpl graph) {
2018 procedure.finished();
2019 } catch (Throwable t2) {
2020 Logger.defaultLogError(t2);
2022 // impl.state.barrier.dec();
2026 public void exception(ReadGraphImpl graph, Throwable t) {
2028 procedure.exception(t);
2029 } catch (Throwable t2) {
2030 Logger.defaultLogError(t2);
2032 // impl.state.barrier.dec();
2036 } catch (DatabaseException e) {
2037 Logger.defaultLogError(e);
2043 final public void forEachStatement(final ReadGraphImpl impl, final Resource subject,
2044 final Resource predicate, final AsyncMultiProcedure<Statement> procedure) {
2046 assert(subject != null);
2047 assert(predicate != null);
2048 assert(procedure != null);
2050 final ListenerBase listener = getListenerBase(procedure);
2052 TripleIntProcedureAdapter proc = new TripleIntProcedureAdapter() {
2054 boolean first = true;
2057 public void execute(ReadGraphImpl graph, int s, int p, int o) {
2060 procedure.execute(graph, querySupport.getStatement(s, p, o));
2062 procedure.execute(impl.newRestart(graph), querySupport.getStatement(s, p, o));
2064 } catch (Throwable t2) {
2065 Logger.defaultLogError(t2);
2070 public void finished(ReadGraphImpl graph) {
2075 procedure.finished(graph);
2076 // impl.state.barrier.dec(this);
2078 procedure.finished(impl.newRestart(graph));
2080 } catch (Throwable t2) {
2081 Logger.defaultLogError(t2);
2087 public void exception(ReadGraphImpl graph, Throwable t) {
2092 procedure.exception(graph, t);
2093 // impl.state.barrier.dec(this);
2095 procedure.exception(impl.newRestart(graph), t);
2097 } catch (Throwable t2) {
2098 Logger.defaultLogError(t2);
2105 int sId = querySupport.getId(subject);
2106 int pId = querySupport.getId(predicate);
2108 // if(AsyncBarrierImpl.BOOKKEEPING) impl.state.barrier.inc(proc, "#Statements" + sId + "#" + pId);
2109 // else impl.state.barrier.inc(null, null);
2112 Statements.queryEach(impl, sId, pId, this, impl.parent, listener, proc);
2113 } catch (DatabaseException e) {
2114 Logger.defaultLogError(e);
2120 final public void forEachStatement(final ReadGraphImpl impl, final Resource subject,
2121 final Resource predicate, final StatementProcedure procedure) {
2123 assert(subject != null);
2124 assert(predicate != null);
2125 assert(procedure != null);
2127 final ListenerBase listener = getListenerBase(procedure);
2129 TripleIntProcedureAdapter proc = new TripleIntProcedureAdapter() {
2131 boolean first = true;
2134 public void execute(ReadGraphImpl graph, int s, int p, int o) {
2137 procedure.execute(graph, s, p, o);
2139 procedure.execute(impl.newRestart(graph), s, p, o);
2141 } catch (Throwable t2) {
2142 Logger.defaultLogError(t2);
2147 public void finished(ReadGraphImpl graph) {
2152 procedure.finished(graph);
2153 // impl.state.barrier.dec(this);
2155 procedure.finished(impl.newRestart(graph));
2157 } catch (Throwable t2) {
2158 Logger.defaultLogError(t2);
2164 public void exception(ReadGraphImpl graph, Throwable t) {
2169 procedure.exception(graph, t);
2170 // impl.state.barrier.dec(this);
2172 procedure.exception(impl.newRestart(graph), t);
2174 } catch (Throwable t2) {
2175 Logger.defaultLogError(t2);
2182 int sId = querySupport.getId(subject);
2183 int pId = querySupport.getId(predicate);
2185 // if(AsyncBarrierImpl.BOOKKEEPING) impl.state.barrier.inc(proc, "#Statements" + sId + "#" + pId);
2186 // else impl.state.barrier.inc(null, null);
2189 Statements.queryEach(impl, sId, pId, this, impl.parent, listener, proc);
2190 } catch (DatabaseException e) {
2191 Logger.defaultLogError(e);
2197 final public void forStatementSet(final ReadGraphImpl impl, final Resource subject, final Resource predicate, final AsyncSetListener<Statement> procedure) {
2199 assert(subject != null);
2200 assert(predicate != null);
2201 assert(procedure != null);
2203 forEachStatement(impl, subject, predicate, new AsyncMultiListener<Statement>() {
2205 private Set<Statement> current = null;
2206 private Set<Statement> run = new HashSet<Statement>();
2209 public void execute(AsyncReadGraph graph, Statement result) {
2211 boolean found = false;
2213 if(current != null) {
2215 found = current.remove(result);
2219 if(!found) procedure.add(graph, result);
2226 public void finished(AsyncReadGraph graph) {
2228 if(current != null) {
2229 for(Statement r : current) procedure.remove(graph, r);
2234 run = new HashSet<Statement>();
2239 public void exception(AsyncReadGraph graph, Throwable t) {
2240 procedure.exception(graph, t);
2244 public boolean isDisposed() {
2245 return procedure.isDisposed();
2253 final public void forEachAssertedStatement(final ReadGraphImpl impl, final Resource subject,
2254 final Resource predicate, final AsyncMultiProcedure<Statement> procedure) {
2256 assert(subject != null);
2257 assert(predicate != null);
2258 assert(procedure != null);
2260 final ListenerBase listener = getListenerBase(procedure);
2262 // impl.state.barrier.inc();
2265 QueryCache.runnerAssertedStatements(impl, querySupport.getId(subject), querySupport.getId(predicate), impl.parent, listener, new TripleIntProcedureAdapter() {
2268 public void execute(ReadGraphImpl graph, int s, int p, int o) {
2270 procedure.execute(graph, querySupport.getStatement(s, p, o));
2271 } catch (Throwable t2) {
2272 Logger.defaultLogError(t2);
2277 public void finished(ReadGraphImpl graph) {
2279 procedure.finished(graph);
2280 } catch (Throwable t2) {
2281 Logger.defaultLogError(t2);
2283 // impl.state.barrier.dec();
2287 public void exception(ReadGraphImpl graph, Throwable t) {
2289 procedure.exception(graph, t);
2290 } catch (Throwable t2) {
2291 Logger.defaultLogError(t2);
2293 // impl.state.barrier.dec();
2297 } catch (DatabaseException e) {
2298 Logger.defaultLogError(e);
2303 private static ListenerBase getListenerBase(Object procedure) {
2304 if(procedure instanceof ListenerBase) return (ListenerBase)procedure;
2309 final public void forEachObject(final ReadGraphImpl impl, final Resource subject, final Resource predicate, final MultiProcedure<Resource> procedure) {
2311 assert(subject != null);
2312 assert(predicate != null);
2313 assert(procedure != null);
2315 final ListenerBase listener = getListenerBase(procedure);
2317 // impl.state.barrier.inc();
2320 QueryCache.runnerObjects(impl, querySupport.getId(subject), querySupport.getId(predicate), impl.parent, listener, new IntProcedure() {
2323 public void execute(ReadGraphImpl graph, int i) {
2325 procedure.execute(querySupport.getResource(i));
2326 } catch (Throwable t2) {
2327 Logger.defaultLogError(t2);
2332 public void finished(ReadGraphImpl graph) {
2334 procedure.finished();
2335 } catch (Throwable t2) {
2336 Logger.defaultLogError(t2);
2338 // impl.state.barrier.dec();
2342 public void exception(ReadGraphImpl graph, Throwable t) {
2343 System.out.println("forEachObject exception " + t);
2345 procedure.exception(t);
2346 } catch (Throwable t2) {
2347 Logger.defaultLogError(t2);
2349 // impl.state.barrier.dec();
2353 } catch (DatabaseException e) {
2354 Logger.defaultLogError(e);
2360 final public void forEachDirectPredicate(final ReadGraphImpl impl, final Resource subject, final AsyncProcedure<Set<Resource>> procedure) {
2362 assert(subject != null);
2363 assert(procedure != null);
2365 final ListenerBase listener = getListenerBase(procedure);
2367 int sId = querySupport.getId(subject);
2370 QueryCache.runnerDirectPredicates(impl, sId, impl.parent, listener, new InternalProcedure<IntSet>() {
2373 public void execute(ReadGraphImpl graph, IntSet result) throws DatabaseException {
2374 procedure.execute(graph, result);
2378 public void exception(ReadGraphImpl graph, Throwable throwable) throws DatabaseException {
2379 procedure.exception(graph, throwable);
2383 } catch (DatabaseException e) {
2384 Logger.defaultLogError(e);
2389 final public DirectStatements getDirectStatements(final ReadGraphImpl impl, final Resource subject, final boolean ignoreVirtual) {
2391 // assert(subject != null);
2392 // assert(procedure != null);
2394 // final ListenerBase listener = getListenerBase(procedure);
2396 // org.simantics.db.impl.query.DirectStatements.queryEach(impl, querySupport.getId(subject), this, impl.parent, listener, procedure);
2398 return querySupport.getStatements(impl, querySupport.getId(subject), this, ignoreVirtual);
2403 // final public void forEachDirectStatement(final ReadGraphImpl impl, final Resource subject, final SyncProcedure<DirectStatements> procedure, boolean ignoreVirtual) {
2405 // assert(subject != null);
2406 // assert(procedure != null);
2408 // final ListenerBase listener = getListenerBase(procedure);
2410 // org.simantics.db.impl.query.DirectStatements.queryEach(impl, querySupport.getId(subject), this, impl.parent, listener, procedure, ignoreVirtual);
2414 private static final Resource INVALID_RESOURCE = new ResourceImpl(null, Integer.MIN_VALUE);
2417 final public void forPossibleObject(final ReadGraphImpl impl, final Resource subject, final Resource predicate, final AsyncProcedure<Resource> procedure) {
2419 forEachObject(impl, subject, predicate, new AsyncMultiProcedure<Resource>() {
2421 private Resource single = null;
2424 public synchronized void execute(AsyncReadGraph graph, Resource result) {
2425 if(single == null) {
2428 single = INVALID_RESOURCE;
2433 public synchronized void finished(AsyncReadGraph graph) {
2434 if(single == null || single == INVALID_RESOURCE) procedure.execute(graph, null);
2435 else procedure.execute(graph, single);
2439 public synchronized void exception(AsyncReadGraph graph, Throwable throwable) {
2440 procedure.exception(graph, throwable);
2447 final public void forEachObject(final ReadGraphImpl impl, final Resource subject, final Resource predicate, final ListenerBase listener, final IntProcedure procedure) {
2449 final int sId = querySupport.getId(subject);
2450 final int pId = querySupport.getId(predicate);
2453 QueryCache.runnerObjects(impl, sId, pId, impl.parent, listener, procedure);
2454 } catch (DatabaseException e) {
2455 Logger.defaultLogError(e);
2460 static class Runner2Procedure implements IntProcedure {
2462 public int single = 0;
2463 public Throwable t = null;
2465 public void clear() {
2471 public void execute(ReadGraphImpl graph, int i) {
2472 if(single == 0) single = i;
2477 public void finished(ReadGraphImpl graph) {
2478 if(single == -1) single = 0;
2482 public void exception(ReadGraphImpl graph, Throwable throwable) {
2487 public int get() throws DatabaseException {
2489 if(t instanceof DatabaseException) throw (DatabaseException)t;
2490 else throw new DatabaseException(t);
2497 final public int getSingleObject(final ReadGraphImpl impl, final Resource subject, final Resource predicate) throws DatabaseException {
2499 final int sId = querySupport.getId(subject);
2500 final int pId = querySupport.getId(predicate);
2502 Runner2Procedure proc = new Runner2Procedure();
2503 QueryCache.runnerObjects(impl, sId, pId, impl.parent, null, proc);
2508 final public void forEachObject(final ReadGraphImpl impl, final Resource subject, final Resource predicate, final AsyncMultiProcedure<Resource> procedure) {
2510 assert(subject != null);
2511 assert(predicate != null);
2513 final ListenerBase listener = getListenerBase(procedure);
2515 if(impl.parent != null || listener != null) {
2517 IntProcedure ip = new IntProcedure() {
2519 AtomicBoolean first = new AtomicBoolean(true);
2522 public void execute(ReadGraphImpl graph, int i) {
2525 procedure.execute(impl, querySupport.getResource(i));
2527 procedure.execute(impl.newRestart(graph), querySupport.getResource(i));
2529 } catch (Throwable t2) {
2530 Logger.defaultLogError(t2);
2536 public void finished(ReadGraphImpl graph) {
2538 if(first.compareAndSet(true, false)) {
2539 procedure.finished(impl);
2540 // impl.state.barrier.dec(this);
2542 procedure.finished(impl.newRestart(graph));
2544 } catch (Throwable t2) {
2545 Logger.defaultLogError(t2);
2550 public void exception(ReadGraphImpl graph, Throwable t) {
2552 procedure.exception(graph, t);
2553 } catch (Throwable t2) {
2554 Logger.defaultLogError(t2);
2556 // impl.state.barrier.dec(this);
2560 public String toString() {
2561 return "forEachObject with " + procedure;
2566 // if(AsyncBarrierImpl.BOOKKEEPING) impl.state.barrier.inc(ip, "#Objects" + subject + "#" + predicate);
2567 // else impl.state.barrier.inc(null, null);
2569 forEachObject(impl, subject, predicate, listener, ip);
2573 IntProcedure ip = new IntProcedure() {
2576 public void execute(ReadGraphImpl graph, int i) {
2577 procedure.execute(graph, querySupport.getResource(i));
2581 public void finished(ReadGraphImpl graph) {
2582 procedure.finished(graph);
2586 public void exception(ReadGraphImpl graph, Throwable t) {
2587 procedure.exception(graph, t);
2591 public String toString() {
2592 return "forEachObject with " + procedure;
2597 forEachObject(impl, subject, predicate, listener, ip);
2604 final public void forObjectSet(final ReadGraphImpl impl, final Resource subject, final Resource predicate, final AsyncSetListener<Resource> procedure) {
2606 assert(subject != null);
2607 assert(predicate != null);
2608 assert(procedure != null);
2610 forEachObject(impl, subject, predicate, new AsyncMultiListener<Resource>() {
2612 private Set<Resource> current = null;
2613 private Set<Resource> run = new HashSet<Resource>();
2616 public void execute(AsyncReadGraph graph, Resource result) {
2618 boolean found = false;
2620 if(current != null) {
2622 found = current.remove(result);
2626 if(!found) procedure.add(graph, result);
2633 public void finished(AsyncReadGraph graph) {
2635 if(current != null) {
2636 for(Resource r : current) procedure.remove(graph, r);
2641 run = new HashSet<Resource>();
2646 public boolean isDisposed() {
2647 return procedure.isDisposed();
2651 public void exception(AsyncReadGraph graph, Throwable t) {
2652 procedure.exception(graph, t);
2656 public String toString() {
2657 return "forObjectSet " + procedure;
2665 final public void forPredicateSet(final ReadGraphImpl impl, final Resource subject, final AsyncSetListener<Resource> procedure) {
2667 assert(subject != null);
2668 assert(procedure != null);
2670 forEachPredicate(impl, subject, new AsyncMultiListener<Resource>() {
2672 private Set<Resource> current = null;
2673 private Set<Resource> run = new HashSet<Resource>();
2676 public void execute(AsyncReadGraph graph, Resource result) {
2678 boolean found = false;
2680 if(current != null) {
2682 found = current.remove(result);
2686 if(!found) procedure.add(graph, result);
2693 public void finished(AsyncReadGraph graph) {
2695 if(current != null) {
2696 for(Resource r : current) procedure.remove(graph, r);
2701 run = new HashSet<Resource>();
2706 public boolean isDisposed() {
2707 return procedure.isDisposed();
2711 public void exception(AsyncReadGraph graph, Throwable t) {
2712 procedure.exception(graph, t);
2716 public String toString() {
2717 return "forPredicateSet " + procedure;
2725 final public void forPrincipalTypeSet(final ReadGraphImpl impl, final Resource subject, final AsyncSetListener<Resource> procedure) {
2727 assert(subject != null);
2728 assert(procedure != null);
2730 forEachPrincipalType(impl, subject, new AsyncMultiListener<Resource>() {
2732 private Set<Resource> current = null;
2733 private Set<Resource> run = new HashSet<Resource>();
2736 public void execute(AsyncReadGraph graph, Resource result) {
2738 boolean found = false;
2740 if(current != null) {
2742 found = current.remove(result);
2746 if(!found) procedure.add(graph, result);
2753 public void finished(AsyncReadGraph graph) {
2755 if(current != null) {
2756 for(Resource r : current) procedure.remove(graph, r);
2761 run = new HashSet<Resource>();
2766 public boolean isDisposed() {
2767 return procedure.isDisposed();
2771 public void exception(AsyncReadGraph graph, Throwable t) {
2772 procedure.exception(graph, t);
2776 public String toString() {
2777 return "forPrincipalTypeSet " + procedure;
2785 final public void forAssertedObjectSet(final ReadGraphImpl impl, final Resource subject, final Resource predicate, final AsyncSetListener<Resource> procedure) {
2787 assert(subject != null);
2788 assert(predicate != null);
2789 assert(procedure != null);
2791 forEachAssertedObject(impl, subject, predicate, new AsyncMultiListener<Resource>() {
2793 private Set<Resource> current = null;
2794 private Set<Resource> run = new HashSet<Resource>();
2797 public void execute(AsyncReadGraph graph, Resource result) {
2799 boolean found = false;
2801 if(current != null) {
2803 found = current.remove(result);
2807 if(!found) procedure.add(graph, result);
2814 public void finished(AsyncReadGraph graph) {
2816 if(current != null) {
2817 for(Resource r : current) procedure.remove(graph, r);
2822 run = new HashSet<Resource>();
2827 public boolean isDisposed() {
2828 return procedure.isDisposed();
2832 public void exception(AsyncReadGraph graph, Throwable t) {
2833 procedure.exception(graph, t);
2837 public String toString() {
2838 return "forObjectSet " + procedure;
2846 final public void forAssertedStatementSet(final ReadGraphImpl impl, final Resource subject, final Resource predicate, final AsyncSetListener<Statement> procedure) {
2848 assert(subject != null);
2849 assert(predicate != null);
2850 assert(procedure != null);
2852 forEachAssertedStatement(impl, subject, predicate, new AsyncMultiListener<Statement>() {
2854 private Set<Statement> current = null;
2855 private Set<Statement> run = new HashSet<Statement>();
2858 public void execute(AsyncReadGraph graph, Statement result) {
2860 boolean found = false;
2862 if(current != null) {
2864 found = current.remove(result);
2868 if(!found) procedure.add(graph, result);
2875 public void finished(AsyncReadGraph graph) {
2877 if(current != null) {
2878 for(Statement s : current) procedure.remove(graph, s);
2883 run = new HashSet<Statement>();
2888 public boolean isDisposed() {
2889 return procedure.isDisposed();
2893 public void exception(AsyncReadGraph graph, Throwable t) {
2894 procedure.exception(graph, t);
2898 public String toString() {
2899 return "forStatementSet " + procedure;
2907 final public void forEachAssertedObject(final ReadGraphImpl impl, final Resource subject,
2908 final Resource predicate, final AsyncMultiProcedure<Resource> procedure) {
2910 assert(subject != null);
2911 assert(predicate != null);
2912 assert(procedure != null);
2914 final ListenerBase listener = getListenerBase(procedure);
2917 QueryCache.runnerAssertedStatements(impl, querySupport.getId(subject), querySupport.getId(predicate), impl.parent, listener, new TripleIntProcedure() {
2920 public void execute(ReadGraphImpl graph, int s, int p, int o) {
2922 procedure.execute(graph, querySupport.getResource(o));
2923 } catch (Throwable t2) {
2924 Logger.defaultLogError(t2);
2929 public void finished(ReadGraphImpl graph) {
2931 procedure.finished(graph);
2932 } catch (Throwable t2) {
2933 Logger.defaultLogError(t2);
2935 // impl.state.barrier.dec();
2939 public void exception(ReadGraphImpl graph, Throwable t) {
2941 procedure.exception(graph, t);
2942 } catch (Throwable t2) {
2943 Logger.defaultLogError(t2);
2945 // impl.state.barrier.dec();
2949 } catch (DatabaseException e) {
2950 Logger.defaultLogError(e);
2956 final public void forEachPrincipalType(final ReadGraphImpl impl, final Resource subject, final AsyncMultiProcedure<Resource> procedure) {
2958 assert(subject != null);
2959 assert(procedure != null);
2961 final ListenerBase listener = getListenerBase(procedure);
2963 IntProcedure ip = new IntProcedure() {
2966 public void execute(ReadGraphImpl graph, int i) {
2968 procedure.execute(graph, querySupport.getResource(i));
2969 } catch (Throwable t2) {
2970 Logger.defaultLogError(t2);
2975 public void finished(ReadGraphImpl graph) {
2977 procedure.finished(graph);
2978 } catch (Throwable t2) {
2979 Logger.defaultLogError(t2);
2981 // impl.state.barrier.dec(this);
2985 public void exception(ReadGraphImpl graph, Throwable t) {
2987 procedure.exception(graph, t);
2988 } catch (Throwable t2) {
2989 Logger.defaultLogError(t2);
2991 // impl.state.barrier.dec(this);
2996 int sId = querySupport.getId(subject);
2998 // if(AsyncBarrierImpl.BOOKKEEPING) impl.state.barrier.inc(ip, "#PrincipalTypes#" + sId);
2999 // else impl.state.barrier.inc(null, null);
3002 QueryCache.runnerPrincipalTypes(impl, sId, impl.parent, listener, ip);
3003 } catch (DatabaseException e) {
3004 Logger.defaultLogError(e);
3010 final public void forEachPrincipalType(final ReadGraphImpl impl, final Resource subject, final MultiProcedure<Resource> procedure) {
3012 assert(subject != null);
3013 assert(procedure != null);
3015 final ListenerBase listener = getListenerBase(procedure);
3017 // impl.state.barrier.inc();
3020 QueryCache.runnerPrincipalTypes(impl, querySupport.getId(subject), impl.parent, listener, new IntProcedure() {
3023 public void execute(ReadGraphImpl graph, int i) {
3025 procedure.execute(querySupport.getResource(i));
3026 } catch (Throwable t2) {
3027 Logger.defaultLogError(t2);
3032 public void finished(ReadGraphImpl graph) {
3034 procedure.finished();
3035 } catch (Throwable t2) {
3036 Logger.defaultLogError(t2);
3038 // impl.state.barrier.dec();
3042 public void exception(ReadGraphImpl graph, Throwable t) {
3044 procedure.exception(t);
3045 } catch (Throwable t2) {
3046 Logger.defaultLogError(t2);
3048 // impl.state.barrier.dec();
3052 } catch (DatabaseException e) {
3053 Logger.defaultLogError(e);
3057 final public void forTypes(final ReadGraphImpl impl, final Resource subject, final AsyncProcedure<Set<Resource>> procedure) {
3059 assert(subject != null);
3060 assert(procedure != null);
3062 final ListenerBase listener = getListenerBase(procedure);
3063 assert(listener == null);
3065 InternalProcedure<IntSet> ip = new InternalProcedure<IntSet>() {
3068 public void execute(final ReadGraphImpl graph, IntSet set) {
3069 procedure.execute(graph, set);
3073 public void exception(ReadGraphImpl graph, Throwable t) {
3074 procedure.exception(graph, t);
3079 int sId = querySupport.getId(subject);
3082 QueryCache.runnerTypes(impl, sId, impl.parent, listener, ip);
3083 } catch (DatabaseException e) {
3084 Logger.defaultLogError(e);
3090 final public IntSet getTypes(final ReadGraphImpl impl, final Resource subject) throws Throwable {
3092 assert(subject != null);
3094 return QueryCacheBase.resultTypes(impl, querySupport.getId(subject), impl.parent, null);
3099 final public RelationInfo getRelationInfo(final ReadGraphImpl impl, final Resource subject) throws DatabaseException {
3101 assert(subject != null);
3103 return QueryCache.resultRelationInfoQuery(impl, querySupport.getId(subject), impl.parent, null);
3108 final public void forSupertypes(final ReadGraphImpl impl, final Resource subject, final AsyncProcedure<Set<Resource>> procedure) {
3110 assert(subject != null);
3111 assert(procedure != null);
3113 final ListenerBase listener = getListenerBase(procedure);
3116 QueryCache.runnerSuperTypes(impl, querySupport.getId(subject), impl.parent, listener, new InternalProcedure<IntSet>() {
3118 AtomicBoolean first = new AtomicBoolean(true);
3121 public void execute(final ReadGraphImpl graph, IntSet set) {
3122 // final HashSet<Resource> result = new HashSet<Resource>();
3123 // set.forEach(new TIntProcedure() {
3126 // public boolean execute(int type) {
3127 // result.add(querySupport.getResource(type));
3133 if(first.compareAndSet(true, false)) {
3134 procedure.execute(graph, set);
3135 // impl.state.barrier.dec();
3137 procedure.execute(impl.newRestart(graph), set);
3139 } catch (Throwable t2) {
3140 Logger.defaultLogError(t2);
3145 public void exception(ReadGraphImpl graph, Throwable t) {
3147 if(first.compareAndSet(true, false)) {
3148 procedure.exception(graph, t);
3149 // impl.state.barrier.dec();
3151 procedure.exception(impl.newRestart(graph), t);
3153 } catch (Throwable t2) {
3154 Logger.defaultLogError(t2);
3159 } catch (DatabaseException e) {
3160 Logger.defaultLogError(e);
3166 final public void forDirectSuperrelations(final ReadGraphImpl impl, final Resource subject, final AsyncMultiProcedure<Resource> procedure) {
3168 assert(subject != null);
3169 assert(procedure != null);
3171 final ListenerBase listener = getListenerBase(procedure);
3173 IntProcedure ip = new IntProcedureAdapter() {
3176 public void execute(final ReadGraphImpl graph, int superRelation) {
3178 procedure.execute(graph, querySupport.getResource(superRelation));
3179 } catch (Throwable t2) {
3180 Logger.defaultLogError(t2);
3185 public void finished(final ReadGraphImpl graph) {
3187 procedure.finished(graph);
3188 } catch (Throwable t2) {
3189 Logger.defaultLogError(t2);
3191 // impl.state.barrier.dec(this);
3196 public void exception(ReadGraphImpl graph, Throwable t) {
3198 procedure.exception(graph, t);
3199 } catch (Throwable t2) {
3200 Logger.defaultLogError(t2);
3202 // impl.state.barrier.dec(this);
3207 int sId = querySupport.getId(subject);
3209 // if(AsyncBarrierImpl.BOOKKEEPING) impl.state.barrier.inc(ip, "#DirectSuperRelations#" + sId);
3210 // else impl.state.barrier.inc(null, null);
3213 QueryCache.runnerDirectSuperRelations(impl, sId, impl.parent, listener, ip);
3214 } catch (DatabaseException e) {
3215 Logger.defaultLogError(e);
3218 // DirectSuperRelations.queryEach(impl, sId, this, impl.parent, listener, ip);
3223 final public void forPossibleSuperrelation(final ReadGraphImpl impl, final Resource subject, final AsyncProcedure<Resource> procedure) {
3225 assert(subject != null);
3226 assert(procedure != null);
3228 final ListenerBase listener = getListenerBase(procedure);
3230 // impl.state.barrier.inc();
3232 PossibleSuperRelation.queryEach(impl, querySupport.getId(subject), this, impl.parent, listener, procedure);
3237 final public void forSuperrelations(final ReadGraphImpl impl, final Resource subject, final AsyncProcedure<Set<Resource>> procedure) {
3239 assert(subject != null);
3240 assert(procedure != null);
3242 final ListenerBase listener = getListenerBase(procedure);
3244 InternalProcedure<IntSet> ip = new InternalProcedure<IntSet>() {
3247 public void execute(final ReadGraphImpl graph, IntSet set) {
3248 // final HashSet<Resource> result = new HashSet<Resource>();
3249 // set.forEach(new TIntProcedure() {
3252 // public boolean execute(int type) {
3253 // result.add(querySupport.getResource(type));
3259 procedure.execute(graph, set);
3260 } catch (Throwable t2) {
3261 Logger.defaultLogError(t2);
3263 // impl.state.barrier.dec(this);
3267 public void exception(ReadGraphImpl graph, Throwable t) {
3269 procedure.exception(graph, t);
3270 } catch (Throwable t2) {
3271 Logger.defaultLogError(t2);
3273 // impl.state.barrier.dec(this);
3278 int sId = querySupport.getId(subject);
3280 // if(AsyncBarrierImpl.BOOKKEEPING) impl.state.barrier.inc(ip, "#SuperRelations#" + sId);
3281 // else impl.state.barrier.inc(null, null);
3284 QueryCache.runnerSuperRelations(impl, sId, impl.parent, listener, ip);
3285 } catch (DatabaseException e) {
3286 Logger.defaultLogError(e);
3291 final public byte[] getValue(final ReadGraphImpl impl, final Resource subject) throws DatabaseException {
3292 return getValue(impl, querySupport.getId(subject));
3295 final public byte[] getValue(final ReadGraphImpl impl, final int subject) throws DatabaseException {
3296 return QueryCache.resultValueQuery(impl, subject, impl.parent, null);
3300 final public void forValue(final ReadGraphImpl impl, final Resource subject, final AsyncProcedure<byte[]> procedure) {
3302 assert(subject != null);
3303 assert(procedure != null);
3305 int sId = querySupport.getId(subject);
3307 // if(procedure != null) {
3309 final ListenerBase listener = getListenerBase(procedure);
3311 InternalProcedure<byte[]> ip = new InternalProcedure<byte[]>() {
3313 AtomicBoolean first = new AtomicBoolean(true);
3316 public void execute(ReadGraphImpl graph, byte[] result) {
3318 if(first.compareAndSet(true, false)) {
3319 procedure.execute(graph, result);
3320 // impl.state.barrier.dec(this);
3322 procedure.execute(impl.newRestart(graph), result);
3324 } catch (Throwable t2) {
3325 Logger.defaultLogError(t2);
3330 public void exception(ReadGraphImpl graph, Throwable t) {
3332 if(first.compareAndSet(true, false)) {
3333 procedure.exception(graph, t);
3334 // impl.state.barrier.dec(this);
3336 procedure.exception(impl.newRestart(graph), t);
3338 } catch (Throwable t2) {
3339 Logger.defaultLogError(t2);
3345 // if(AsyncBarrierImpl.BOOKKEEPING) impl.state.barrier.inc(ip, "#Value" + sId);
3346 // else impl.state.barrier.inc(null, null);
3349 QueryCache.runnerValueQuery(impl, sId, impl.parent, listener, ip);
3350 } catch (DatabaseException e) {
3351 throw new IllegalStateException("Internal error");
3356 // return QueryCacheBase.runnerValueQuery(impl, sId, impl.parent, null, null);
3360 // throw new IllegalStateException("Internal error");
3365 final public void forPossibleValue(final ReadGraphImpl impl, final Resource subject, final AsyncProcedure<byte[]> procedure) {
3367 assert(subject != null);
3368 assert(procedure != null);
3370 final ListenerBase listener = getListenerBase(procedure);
3372 if(impl.parent != null || listener != null) {
3374 InternalProcedure<byte[]> ip = new InternalProcedure<byte[]>() {
3376 AtomicBoolean first = new AtomicBoolean(true);
3379 public void execute(ReadGraphImpl graph, byte[] result) {
3381 if(first.compareAndSet(true, false)) {
3382 procedure.execute(graph, result);
3383 // impl.state.barrier.dec(this);
3385 procedure.execute(impl.newRestart(graph), result);
3387 } catch (Throwable t2) {
3388 Logger.defaultLogError(t2);
3393 public void exception(ReadGraphImpl graph, Throwable t) {
3395 if(first.compareAndSet(true, false)) {
3396 procedure.exception(graph, t);
3397 // impl.state.barrier.dec(this);
3399 procedure.exception(impl.newRestart(graph), t);
3401 } catch (Throwable t2) {
3402 Logger.defaultLogError(t2);
3408 int sId = querySupport.getId(subject);
3410 // if(AsyncBarrierImpl.BOOKKEEPING) impl.state.barrier.inc(ip, "#Value" + sId);
3411 // else impl.state.barrier.inc(null, null);
3414 QueryCache.runnerValueQuery(impl, sId, impl.parent, listener, ip);
3415 } catch (DatabaseException e) {
3416 Logger.defaultLogError(e);
3421 InternalProcedure<byte[]> ip = new InternalProcedure<byte[]>() {
3424 public void execute(ReadGraphImpl graph, byte[] result) {
3426 procedure.execute(graph, result);
3431 public void exception(ReadGraphImpl graph, Throwable t) {
3433 procedure.exception(graph, t);
3439 int sId = querySupport.getId(subject);
3442 QueryCache.runnerValueQuery(impl, sId, impl.parent, listener, ip);
3443 } catch (DatabaseException e) {
3444 Logger.defaultLogError(e);
3452 final public void forInverse(final ReadGraphImpl impl, final Resource relation, final AsyncProcedure<Resource> procedure) {
3454 assert(relation != null);
3455 assert(procedure != null);
3457 final ListenerBase listener = getListenerBase(procedure);
3459 IntProcedure ip = new IntProcedure() {
3461 private int result = 0;
3463 final AtomicBoolean found = new AtomicBoolean(false);
3464 final AtomicBoolean done = new AtomicBoolean(false);
3467 public void finished(ReadGraphImpl graph) {
3469 // Shall fire exactly once!
3470 if(done.compareAndSet(false, true)) {
3473 procedure.exception(graph, new NoInverseException(""));
3474 // impl.state.barrier.dec(this);
3476 procedure.execute(graph, querySupport.getResource(result));
3477 // impl.state.barrier.dec(this);
3479 } catch (Throwable t) {
3480 Logger.defaultLogError(t);
3487 public void execute(ReadGraphImpl graph, int i) {
3489 if(found.compareAndSet(false, true)) {
3492 // Shall fire exactly once!
3493 if(done.compareAndSet(false, true)) {
3495 procedure.exception(graph, new ManyObjectsForFunctionalRelationException("Multiple items e.g. " + this.result + " and " + result));
3496 // impl.state.barrier.dec(this);
3497 } catch (Throwable t) {
3498 Logger.defaultLogError(t);
3506 public void exception(ReadGraphImpl graph, Throwable t) {
3507 // Shall fire exactly once!
3508 if(done.compareAndSet(false, true)) {
3510 procedure.exception(graph, t);
3511 // impl.state.barrier.dec(this);
3512 } catch (Throwable t2) {
3513 Logger.defaultLogError(t2);
3520 int sId = querySupport.getId(relation);
3522 // if(AsyncBarrierImpl.BOOKKEEPING) impl.state.barrier.inc(ip, "#DirectObjects#" + sId);
3523 // else impl.state.barrier.inc(null, null);
3526 QueryCache.runnerObjects(impl, sId, getInverseOf(), impl.parent, listener, ip);
3527 } catch (DatabaseException e) {
3528 Logger.defaultLogError(e);
3534 final public void forResource(final ReadGraphImpl impl, final String id, final AsyncProcedure<Resource> procedure) {
3537 assert(procedure != null);
3539 InternalProcedure<Integer> ip = new InternalProcedure<Integer>() {
3542 public void execute(ReadGraphImpl graph, Integer result) {
3544 procedure.execute(graph, querySupport.getResource(result));
3545 } catch (Throwable t2) {
3546 Logger.defaultLogError(t2);
3548 // impl.state.barrier.dec(this);
3552 public void exception(ReadGraphImpl graph, Throwable t) {
3555 procedure.exception(graph, t);
3556 } catch (Throwable t2) {
3557 Logger.defaultLogError(t2);
3559 // impl.state.barrier.dec(this);
3564 // if(AsyncBarrierImpl.BOOKKEEPING) impl.state.barrier.inc(ip, "Resource");
3565 // else impl.state.barrier.inc(null, null);
3567 forResource(impl, id, impl.parent, ip);
3572 final public void forBuiltin(final ReadGraphImpl impl, final String id, final AsyncProcedure<Resource> procedure) {
3575 assert(procedure != null);
3577 // impl.state.barrier.inc();
3580 forBuiltin(impl, id, impl.parent, new InternalProcedure<Integer>() {
3583 public void execute(ReadGraphImpl graph, Integer result) {
3585 procedure.execute(graph, querySupport.getResource(result));
3586 } catch (Throwable t2) {
3587 Logger.defaultLogError(t2);
3589 // impl.state.barrier.dec();
3593 public void exception(ReadGraphImpl graph, Throwable t) {
3595 procedure.exception(graph, t);
3596 } catch (Throwable t2) {
3597 Logger.defaultLogError(t2);
3599 // impl.state.barrier.dec();
3603 } catch (DatabaseException e) {
3604 Logger.defaultLogError(e);
3610 final public void forHasStatement(final ReadGraphImpl impl, final Resource subject, final AsyncProcedure<Boolean> procedure) {
3612 assert(subject != null);
3613 assert(procedure != null);
3615 final ListenerBase listener = getListenerBase(procedure);
3618 IntSet result = QueryCache.resultDirectPredicates(impl, querySupport.getId(subject), impl.parent, listener);
3619 procedure.execute(impl, !result.isEmpty());
3620 } catch (DatabaseException e) {
3621 procedure.exception(impl, e);
3627 final public void forHasStatement(final ReadGraphImpl impl, final Resource subject, final Resource predicate, final AsyncProcedure<Boolean> procedure) {
3629 assert(subject != null);
3630 assert(predicate != null);
3631 assert(procedure != null);
3633 AsyncMultiProcedure<Resource> ip = new AsyncMultiProcedureAdapter<Resource>() {
3635 boolean found = false;
3638 synchronized public void execute(AsyncReadGraph graph, Resource resource) {
3643 synchronized public void finished(AsyncReadGraph graph) {
3645 procedure.execute(graph, found);
3646 } catch (Throwable t2) {
3647 Logger.defaultLogError(t2);
3649 // impl.state.barrier.dec(this);
3653 public void exception(AsyncReadGraph graph, Throwable t) {
3655 procedure.exception(graph, t);
3656 } catch (Throwable t2) {
3657 Logger.defaultLogError(t2);
3659 // impl.state.barrier.dec(this);
3664 // if(AsyncBarrierImpl.BOOKKEEPING) impl.state.barrier.inc(ip, "#ForEachObject#" + subject + "#" + predicate);
3665 // else impl.state.barrier.inc(null, null);
3667 forEachObject(impl, subject, predicate, ip);
3672 final public void forHasStatement(final ReadGraphImpl impl, final Resource subject, final Resource predicate, final Resource object, final AsyncProcedure<Boolean> procedure) {
3674 assert(subject != null);
3675 assert(predicate != null);
3676 assert(procedure != null);
3678 // impl.state.barrier.inc();
3680 forEachObject(impl, subject, predicate, new AsyncMultiProcedureAdapter<Resource>() {
3682 boolean found = false;
3685 synchronized public void execute(AsyncReadGraph graph, Resource resource) {
3686 if(resource.equals(object)) found = true;
3690 synchronized public void finished(AsyncReadGraph graph) {
3692 procedure.execute(graph, found);
3693 } catch (Throwable t2) {
3694 Logger.defaultLogError(t2);
3696 // impl.state.barrier.dec();
3700 public void exception(AsyncReadGraph graph, Throwable t) {
3702 procedure.exception(graph, t);
3703 } catch (Throwable t2) {
3704 Logger.defaultLogError(t2);
3706 // impl.state.barrier.dec();
3714 final public void forHasValue(final ReadGraphImpl impl, final Resource subject, final AsyncProcedure<Boolean> procedure) {
3716 assert(subject != null);
3717 assert(procedure != null);
3719 final ListenerBase listener = getListenerBase(procedure);
3721 // impl.state.barrier.inc();
3724 QueryCache.runnerValueQuery(impl, querySupport.getId(subject), impl.parent, listener, new InternalProcedure<byte[]>() {
3727 public void execute(ReadGraphImpl graph, byte[] object) {
3728 boolean result = object != null;
3730 procedure.execute(graph, result);
3731 } catch (Throwable t2) {
3732 Logger.defaultLogError(t2);
3734 // impl.state.barrier.dec();
3738 public void exception(ReadGraphImpl graph, Throwable t) {
3740 procedure.exception(graph, t);
3741 } catch (Throwable t2) {
3742 Logger.defaultLogError(t2);
3744 // impl.state.barrier.dec();
3748 } catch (DatabaseException e) {
3749 Logger.defaultLogError(e);
3755 final public void forOrderedSet(final ReadGraphImpl impl, final Resource subject, final AsyncMultiProcedure<Resource> procedure) {
3757 assert(subject != null);
3758 assert(procedure != null);
3760 final ListenerBase listener = getListenerBase(procedure);
3764 QueryCache.runnerOrderedSet(impl, querySupport.getId(subject), impl.parent, listener, new IntProcedure() {
3767 public void exception(ReadGraphImpl graph, Throwable t) {
3769 procedure.exception(graph, t);
3770 } catch (Throwable t2) {
3771 Logger.defaultLogError(t2);
3773 // impl.state.barrier.dec();
3777 public void execute(ReadGraphImpl graph, int i) {
3779 procedure.execute(graph, querySupport.getResource(i));
3780 } catch (Throwable t2) {
3781 Logger.defaultLogError(t2);
3786 public void finished(ReadGraphImpl graph) {
3788 procedure.finished(graph);
3789 } catch (Throwable t2) {
3790 Logger.defaultLogError(t2);
3792 // impl.state.barrier.dec();
3796 } catch (DatabaseException e) {
3797 Logger.defaultLogError(e);
3803 // final public <T> void query(final ReadGraphImpl impl, final AsyncRead<T> request, final CacheEntry parent, final AsyncProcedure<T> procedure, ListenerBase listener) throws DatabaseException {
3805 // assert(request != null);
3806 // assert(procedure != null);
3808 // QueryCache.runnerAsyncReadEntry(impl, request, parent, listener, procedure);
3813 // final public <T> T tryQuery(final ReadGraphImpl graph, final Read<T> request) throws DatabaseException {
3815 // assert(graph != null);
3816 // assert(request != null);
3818 // final ReadEntry entry = (ReadEntry)cache.getCached(request);
3819 // if(entry != null && entry.isReady()) {
3820 // return (T)entry.get(graph, this, null);
3822 // return request.perform(graph);
3827 // final public <T> T tryQuery(final ReadGraphImpl graph, final ExternalRead<T> request) throws DatabaseException {
3829 // assert(graph != null);
3830 // assert(request != null);
3832 // final ExternalReadEntry<T> entry = cache.externalReadMap.get(request);
3833 // if(entry != null && entry.isReady()) {
3834 // if(entry.isExcepted()) {
3835 // Throwable t = (Throwable)entry.getResult();
3836 // if(t instanceof DatabaseException) throw (DatabaseException)t;
3837 // else throw new DatabaseException(t);
3839 // return (T)entry.getResult();
3843 // final DataContainer<T> result = new DataContainer<T>();
3844 // final DataContainer<Throwable> exception = new DataContainer<Throwable>();
3846 // request.register(graph, new Listener<T>() {
3849 // public void exception(Throwable t) {
3850 // exception.set(t);
3854 // public void execute(T t) {
3859 // public boolean isDisposed() {
3865 // Throwable t = exception.get();
3867 // if(t instanceof DatabaseException) throw (DatabaseException)t;
3868 // else throw new DatabaseException(t);
3871 // return result.get();
3878 // final public <T> void tryQuery(final ReadGraphImpl graph, final AsyncRead<T> request, AsyncProcedure<T> procedure) {
3880 // assert(graph != null);
3881 // assert(request != null);
3883 // final AsyncReadEntry entry = cache.asyncReadMap.get(request);
3884 // if(entry != null && entry.isReady()) {
3885 // if(entry.isExcepted()) {
3886 // procedure.exception(graph, (Throwable)entry.getResult());
3888 // procedure.execute(graph, (T)entry.getResult());
3891 // request.perform(graph, procedure);
3897 final public <T> void query(final ReadGraphImpl impl, final MultiRead<T> request, final CacheEntry parent, final SyncMultiProcedure<T> procedure, ListenerBase listener) {
3899 assert(request != null);
3900 assert(procedure != null);
3904 queryMultiRead(impl, request, parent, listener, procedure);
3906 } catch (DatabaseException e) {
3908 throw new IllegalStateException(e);
3915 final public <T> void query(final ReadGraphImpl impl, final AsyncMultiRead<T> request, final CacheEntry parent, final AsyncMultiProcedure<T> procedure, ListenerBase listener) {
3917 assert(request != null);
3918 assert(procedure != null);
3920 // impl.state.barrier.inc();
3922 runAsyncMultiRead(impl, request, parent, listener, new AsyncMultiProcedure<T>() {
3924 public void execute(AsyncReadGraph graph, T result) {
3927 procedure.execute(graph, result);
3928 } catch (Throwable t2) {
3929 Logger.defaultLogError(t2);
3934 public void finished(AsyncReadGraph graph) {
3937 procedure.finished(graph);
3938 } catch (Throwable t2) {
3939 Logger.defaultLogError(t2);
3942 // impl.state.barrier.dec();
3947 public String toString() {
3948 return procedure.toString();
3952 public void exception(AsyncReadGraph graph, Throwable t) {
3955 procedure.exception(graph, t);
3956 } catch (Throwable t2) {
3957 Logger.defaultLogError(t2);
3960 // impl.state.barrier.dec();
3969 // final public <T> void query(final ReadGraphImpl impl, final ExternalRead<T> request, final CacheEntry parent, final Procedure<T> procedure, ListenerBase listener) throws DatabaseException {
3971 // assert(request != null);
3972 // assert(procedure != null);
3976 // queryPrimitiveRead(impl, request, parent, listener, new AsyncProcedure<T>() {
3979 // public String toString() {
3980 // return procedure.toString();
3984 // public void execute(AsyncReadGraph graph, T result) {
3986 // procedure.execute(result);
3987 // } catch (Throwable t2) {
3988 // Logger.defaultLogError(t2);
3993 // public void exception(AsyncReadGraph graph, Throwable throwable) {
3995 // procedure.exception(throwable);
3996 // } catch (Throwable t2) {
3997 // Logger.defaultLogError(t2);
4003 // } catch (DatabaseException e) {
4005 // throw new IllegalStateException(e);
4012 public VirtualGraph getProvider(Resource subject, Resource predicate, Resource object) {
4014 return querySupport.getProvider(querySupport.getId(subject), querySupport.getId(predicate), querySupport.getId(object));
4019 public VirtualGraph getProvider(Resource subject, Resource predicate) {
4021 return querySupport.getProvider(querySupport.getId(subject), querySupport.getId(predicate));
4026 public VirtualGraph getValueProvider(Resource subject) {
4028 return querySupport.getValueProvider(querySupport.getId(subject));
4032 public boolean resumeTasks(ReadGraphImpl graph) {
4034 return querySupport.resume(graph);
4038 public boolean isImmutable(int resourceId) {
4039 return querySupport.isImmutable(resourceId);
4042 public boolean isImmutable(Resource resource) {
4043 ResourceImpl impl = (ResourceImpl)resource;
4044 return isImmutable(impl.id);
4049 public Layer0 getL0(ReadGraph graph) {
4051 L0 = Layer0.getInstance(graph);
4056 public static ThreadLocal<Integer> thread = new ThreadLocal<Integer>() {
4057 protected Integer initialValue() {