*******************************************************************************/
package org.simantics.db.common.primitiverequest;
-import org.simantics.db.AsyncReadGraph;
+import org.simantics.db.ReadGraph;
import org.simantics.db.Resource;
-import org.simantics.db.common.request.ResourceAsyncRead2;
-import org.simantics.db.procedure.AsyncProcedure;
+import org.simantics.db.common.request.ResourceRead2;
+import org.simantics.db.exception.DatabaseException;
-final public class IsInstanceOf extends ResourceAsyncRead2<Boolean> {
+final public class IsInstanceOf extends ResourceRead2<Boolean> {
public IsInstanceOf(Resource resource, Resource resource2) {
super(resource, resource2);
}
- @Override
- public void perform(AsyncReadGraph graph, AsyncProcedure<Boolean> procedure) {
- graph.forIsInstanceOf(resource, resource2, procedure);
- }
+ @Override
+ public Boolean perform(ReadGraph graph) throws DatabaseException {
+ return graph.isInstanceOf(resource2, resource2);
+ }
}
package org.simantics.db.common.request;
import org.simantics.db.AsyncReadGraph;
+import org.simantics.db.ReadGraph;
import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
import org.simantics.db.procedure.AsyncProcedure;
import org.simantics.layer0.Layer0;
-public class PossibleTypedParent extends ResourceAsyncRead2<Resource> {
+public class PossibleTypedParent extends ResourceRead2<Resource> {
public PossibleTypedParent(Resource resource, Resource type) {
super(resource, type);
}
- @Override
- public void perform(AsyncReadGraph graph, final AsyncProcedure<Resource> procedure) {
-
- final Layer0 l0 = graph.getService(Layer0.class);
-
- graph.forIsInstanceOf(resource, resource2, new AsyncProcedure<Boolean>() {
-
- @Override
- public void execute(AsyncReadGraph graph, Boolean isInstance) {
- if(isInstance) {
- procedure.execute(graph, resource);
- } else {
-
- graph.forPossibleObject(resource, l0.PartOf, new AsyncProcedure<Resource>() {
-
- @Override
- public void execute(AsyncReadGraph graph, final Resource parent) {
- if(parent == null) {
- procedure.execute(graph, null);
- } else {
- graph.asyncRequest(new PossibleTypedParent(parent, resource2), procedure);
- }
-
- }
-
- @Override
- public void exception(AsyncReadGraph graph, Throwable throwable) {
- procedure.exception(graph, throwable);
- }
-
- });
-
- }
- }
-
- @Override
- public void exception(AsyncReadGraph graph, Throwable throwable) {
- procedure.exception(graph, throwable);
+ @Override
+ public Resource perform(ReadGraph graph) throws DatabaseException {
+ if(graph.isInstanceOf(resource, resource2)) {
+ return resource;
+ } else {
+ Layer0 L0 = Layer0.getInstance(graph);
+ Resource possibleParent = graph.getPossibleObject(resource, L0.PartOf);
+ if(possibleParent != null) {
+ return graph.syncRequest(new PossibleTypedParent(possibleParent, resource2));
+ } else {
+ return null;
}
- });
-
-
+ }
}
+// @Override
+// public void perform(AsyncReadGraph graph, final AsyncProcedure<Resource> procedure) {
+//
+// final Layer0 l0 = graph.getService(Layer0.class);
+//
+// graph.forIsInstanceOf(resource, resource2, new AsyncProcedure<Boolean>() {
+//
+// @Override
+// public void execute(AsyncReadGraph graph, Boolean isInstance) {
+// if(isInstance) {
+// procedure.execute(graph, resource);
+// } else {
+//
+// graph.forPossibleObject(resource, l0.PartOf, new AsyncProcedure<Resource>() {
+//
+// @Override
+// public void execute(AsyncReadGraph graph, final Resource parent) {
+//
+// if(parent == null) {
+// procedure.execute(graph, null);
+// } else {
+// graph.asyncRequest(new PossibleTypedParent(parent, resource2), procedure);
+// }
+//
+// }
+//
+// @Override
+// public void exception(AsyncReadGraph graph, Throwable throwable) {
+// procedure.exception(graph, throwable);
+// }
+//
+// });
+//
+// }
+// }
+//
+// @Override
+// public void exception(AsyncReadGraph graph, Throwable throwable) {
+// procedure.exception(graph, throwable);
+// }
+// });
+//
+//
+// }
+
}
import org.simantics.db.impl.procedure.ResultCallWrappedQueryProcedure4;
import org.simantics.db.impl.procedure.ResultCallWrappedSingleQueryProcedure4;
import org.simantics.db.impl.query.CacheEntry;
+import org.simantics.db.impl.query.QueryCache;
import org.simantics.db.impl.query.QueryProcessor;
import org.simantics.db.impl.query.QuerySupport;
import org.simantics.db.impl.query.TripleIntProcedure;
assert (request != null);
- return processor.query(this, request, parent, null, null);
+ return QueryCache.resultReadEntry(this, request, parent, null, null);
+
+ //return processor.query(this, request, parent, null, null);
// if (parent != null) {
//
ListenerBase listener = procedure != null ? getListenerBase(procedure) : null;
- return processor.query(this, request, parent, procedure, listener);
+ return QueryCache.resultReadEntry(this, request, parent, listener, procedure);
+
+// return processor.query(this, request, parent, procedure, listener);
// if (parent != null || listener != null) {
final ResultCallWrappedSingleQueryProcedure4<T> wrapper = new ResultCallWrappedSingleQueryProcedure4<T>(
procedure, request);
- processor.query(this, request, parent, wrapper, listener);
+ QueryCache.runnerAsyncReadEntry(this, request, parent, listener, wrapper);
+
+ //processor.query(this, request, parent, wrapper, listener);
return wrapper.getResult();
assert (request != null);
ListenerBase listener = getListenerBase(procedure);
+ assert(listener == null);
- final ResultCallWrappedSingleQueryProcedure4<T> wrapper = new ResultCallWrappedSingleQueryProcedure4<T>(
- procedure, request);
-
- processor.query(this, request, parent, wrapper, listener);
+// final ResultCallWrappedSingleQueryProcedure4<T> wrapper = new ResultCallWrappedSingleQueryProcedure4<T>(
+// procedure, request);
-// if (parent != null || listener != null || ((request.getFlags() & RequestFlags.SCHEDULE) > 0)) {
-//
-//
-// } else {
-//
-// try {
-//
-//// final ReadGraphImpl newGraph = newSync();
-// processor.tryQuery(this, request, procedure);
-//// newGraph.waitAsync(null);
-// waitAsyncProcedure(procedure);
-//
-// } catch (Throwable t) {
-// if(Development.DEVELOPMENT) {
-// if(Development.<Boolean>getProperty(DevelopmentKeys.WRITEGRAPH_EXCEPTION_STACKTRACES, Bindings.BOOLEAN)) {
-// t.printStackTrace();
-// }
-// }
-// procedure.exception(this, t);
-// waitAsyncProcedure(procedure);
-// }
-//
-// }
+ QueryCache.runnerAsyncReadEntry(this, request, parent, listener, procedure);
}
if (parent != null || listener != null) {
try {
- processor.query(this, request, parent, procedure,listener);
+ QueryCache.runnerReadEntry(this, request, parent, listener, procedure);
+ //processor.query(this, request, parent, procedure,listener);
} catch (DatabaseException e) {
Logger.defaultLogError(e);
// This throwable has already been transferred to procedure at this point - do nothing about it
if (parent != null || listener != null) {
try {
- processor.query(this, request, parent, procedure, listener);
+ QueryCache.runnerAsyncReadEntry(this, request, parent, listener, procedure);
+ //processor.query(this, request, parent, procedure, listener);
} catch (DatabaseException e) {
Logger.defaultLogError(e);
}
void forHasValue(ReadGraphImpl graph, Resource subject, AsyncProcedure<Boolean> procedure);
void forOrderedSet(ReadGraphImpl graph, Resource subject, AsyncMultiProcedure<Resource> procedure);
- <T> T query(ReadGraphImpl graph, Read<T> request, CacheEntry parent, AsyncProcedure<T> procedure, ListenerBase listener) throws DatabaseException;
+ //<T> T query(ReadGraphImpl graph, Read<T> request, CacheEntry parent, AsyncProcedure<T> procedure, ListenerBase listener) throws DatabaseException;
<T> void query(ReadGraphImpl graph, MultiRead<T> request, CacheEntry parent, AsyncMultiProcedure<T> procedure, ListenerBase listener);
- <T> void query(ReadGraphImpl graph, AsyncRead<T> request, CacheEntry parent, AsyncProcedure<T> procedure, ListenerBase listener) throws DatabaseException;
+// <T> void query(ReadGraphImpl graph, AsyncRead<T> request, CacheEntry parent, AsyncProcedure<T> procedure, ListenerBase listener) throws DatabaseException;
<T> void query(ReadGraphImpl graph, AsyncMultiRead<T> request, CacheEntry parent, AsyncMultiProcedure<T> procedure, ListenerBase listener);
<T> void query(ReadGraphImpl graph, ExternalRead<T> request, CacheEntry parent, Procedure<T> procedure, ListenerBase listener);
@Override
public Object compute(ReadGraphImpl graph, AsyncProcedure<T> procedure) throws DatabaseException {
- return graph.processor.cache.performQuery(graph, request, this, procedure);
+
+ ReadGraphImpl queryGraph = graph.withParent(this);
+
+ request.perform(queryGraph, new AsyncProcedure<T>() {
+
+ @Override
+ public void execute(AsyncReadGraph returnGraph, T result) {
+ ReadGraphImpl impl = (ReadGraphImpl)returnGraph;
+ AsyncReadEntry.this.addOrSet(graph, result);
+ try {
+ procedure.execute(graph, result);
+ } catch (Throwable t) {
+ t.printStackTrace();
+ }
+ // parentBarrier.dec(query);
+ }
+
+ @Override
+ public void exception(AsyncReadGraph returnGraph, Throwable t) {
+ ReadGraphImpl impl = (ReadGraphImpl)returnGraph;
+ // AsyncReadGraph resumeGraph = finalParentGraph.newAsync();
+ AsyncReadEntry.this.except(graph, t);
+ try {
+ procedure.exception(graph, t);
+ } catch (Throwable t2) {
+ t2.printStackTrace();
+ }
+ // parentBarrier.dec(query);
+ }
+
+ @Override
+ public String toString() {
+ return procedure.toString();
+ }
+
+ });
+
+ return getResult();
+
+ }
+
+ public static <T> void computeForEach(ReadGraphImpl parentGraph, AsyncRead<T> request, AsyncReadEntry<T> entry, AsyncProcedure<T> procedure) throws DatabaseException {
+
+ ReadGraphImpl queryGraph = parentGraph.withParent(entry);
+
+ request.perform(queryGraph, new AsyncProcedure<T>() {
+
+ @Override
+ public void execute(AsyncReadGraph returnGraph, T result) {
+ ReadGraphImpl impl = (ReadGraphImpl)returnGraph;
+ if(entry != null) entry.addOrSet(parentGraph, result);
+ try {
+ procedure.execute(parentGraph, result);
+ } catch (Throwable t) {
+ t.printStackTrace();
+ }
+ }
+
+ @Override
+ public void exception(AsyncReadGraph returnGraph, Throwable t) {
+ ReadGraphImpl impl = (ReadGraphImpl)returnGraph;
+ if(entry != null) entry.except(parentGraph, t);
+ try {
+ procedure.exception(parentGraph, t);
+ } catch (Throwable t2) {
+ t2.printStackTrace();
+ }
+ }
+
+ @Override
+ public String toString() {
+ return procedure.toString();
+ }
+
+ });
+
}
+
@Override
public String toString() {
if(isDiscarded()) return "DISCARDED " + request.toString();
public void generateRunner(StringBuilder content, String clazz, String[] signature, boolean shortcut) {
- line(content, "static void runner" + clazz + "(ReadGraphImpl graph, " + signature[0] + ", CacheEntry parent, ListenerBase listener, " + signature[4] + " procedure) throws DatabaseException {");
+ line(content, "public static void runner" + clazz + "(ReadGraphImpl graph, " + signature[0] + ", CacheEntry parent, ListenerBase listener, " + signature[4] + " procedure) throws DatabaseException {");
if(shortcut) {
line(content, " if(parent == null && listener == null) {");
line(content, " " + clazz + ".computeForEach(graph, " + signature[1] + ", null, procedure);");
generateQuery(content, "DirectPredicates", signatureR1IntSet, true);
generateQuery(content, "Predicates", signatureR1IntSet, true);
generateQuery(content, "ReadEntry", signatureRead, true);
+ generateQuery(content, "AsyncReadEntry", signatureAsyncRead, true);
generateQuery(content, "Types", signatureR1IntSet, true);
+ generateQuery(content, "NamespaceIndex", signatureID2, true);
generateQuery(content, "AssertedStatements", signatureR2TIP, false);
- generateQuery(content, "NamespaceIndex", signatureID2, false);
generateQuery(content, "AssertedPredicates", signatureR1IP, false);
generateQuery(content, "DirectSuperRelations", signatureR1IP, false);
generateQuery(content, "SuperTypes", signatureR1IntSet, false);
generateQuery(content, "TypeHierarchy", signatureR1IntSet, false);
generateQuery(content, "SuperRelations", signatureR1IntSet, false);
- generateQuery(content, "AsyncReadEntry", signatureAsyncRead, false);
generateQuery(content, "MultiReadEntry", signatureMultiRead, false);
generateQuery(content, "AsyncMultiReadEntry", signatureAsyncMultiRead, false);
generateQuery(content, "ExternalReadEntry", signatureExternalRead, false);
provider.cache.remove(this);
}
- final private void index(ReadGraphImpl graph, final QueryProcessor provider, int root, final InternalProcedure<TObjectIntHashMap<String>> procedure) throws DatabaseException {
+ final static private void index(ReadGraphImpl graph, int root, NamespaceIndex entry, final InternalProcedure<TObjectIntHashMap<String>> procedure) throws DatabaseException {
if(root == 0) {
- add2(graph, null);
+ if(entry != null)
+ entry.add2(graph, null);
procedure.execute(graph, null);
// System.err.println("NamespaceIndex[" + id + "]->null");
return;
}
- final int consistsOf = provider.getConsistsOf();
- final int hasName = provider.getHasName();
+ QueryProcessor processor = graph.processor;
+
+ final int consistsOf = processor.getConsistsOf();
+ final int hasName = processor.getHasName();
final TObjectIntHashMap<String> result = new TObjectIntHashMap<String>();
- QueryCache.runnerObjects(graph, root, consistsOf, graph.parent, null, new SyncIntProcedure() {
+ QueryCache.runnerObjects(graph, root, consistsOf, entry, null, new SyncIntProcedure() {
@Override
public void run(ReadGraphImpl graph) throws DatabaseException {
- if(isPending()) {
- add2(graph, result);
- procedure.execute(graph, result);
-// System.err.println("NamespaceIndex[" + id + "]->" + result.size());
- } else {
- procedure.exception(graph, (Throwable)statusOrException);
- }
+ if(entry != null) entry.add2(graph, result);
+ procedure.execute(graph, result);
}
inc();
- QueryCache.runnerObjects(graph, obj, hasName, graph.parent, null, new IntProcedure() {
+ QueryCache.runnerObjects(graph, obj, hasName, entry, null, new IntProcedure() {
@Override
public void execute(ReadGraphImpl graph, int i) throws DatabaseException {
inc();
- QueryCache.runnerValueQuery(graph, i, NamespaceIndex.this, null, new InternalProcedure<byte[]>() {
+ QueryCache.runnerValueQuery(graph, i, entry, null, new InternalProcedure<byte[]>() {
@Override
public void execute(ReadGraphImpl graph, byte[] value) throws DatabaseException {
@Override
public void exception(ReadGraphImpl graph, Throwable t) throws DatabaseException {
- except(t);
+ if(entry != null) entry.except(t);
dec(graph);
}
@Override
public void exception(ReadGraphImpl graph, Throwable t) throws DatabaseException {
- except(t);
+ if(entry != null) entry.except(t);
dec(graph);
}
}
+
@Override
public Object compute(ReadGraphImpl graph, final InternalProcedure<TObjectIntHashMap<String>> procedure) throws DatabaseException {
+ computeForEach(graph, id, this, procedure);
+ return getResult();
+ }
+
+ public static void computeForEach(ReadGraphImpl graph, final String id, final NamespaceIndex entry, final InternalProcedure<TObjectIntHashMap<String>> procedure) throws DatabaseException {
QueryProcessor processor = graph.processor;
// System.err.println("NamespaceIndex " + id);
if("http://".equals(id) || "http:/".equals(id)) {
- index(graph, processor, processor.getRootLibrary(), procedure);
+ index(graph, processor.getRootLibrary(), entry, procedure);
} else {
final String[] parts = URIStringUtils.splitURI(id);
if(parts != null) {
- QueryCache.runnerNamespaceIndex(graph, parts[0], this, null, new InternalProcedure<TObjectIntHashMap<String>>() {
+ QueryCache.runnerNamespaceIndex(graph, parts[0], entry, null, new InternalProcedure<TObjectIntHashMap<String>>() {
@Override
public void execute(ReadGraphImpl graph, TObjectIntHashMap<String> index) throws DatabaseException {
if(index != null) {
- index(graph, processor, index.get(parts[1]), procedure);
+ index(graph, index.get(parts[1]), entry, procedure);
} else {
- add2(graph, null);
+ if(entry != null) entry.add2(graph, null);
procedure.execute(graph, null);
// System.err.println("NamespaceIndex[" + id + "]->null");
}
@Override
public void exception(ReadGraphImpl graph, Throwable t) throws DatabaseException {
if(DebugException.DEBUG) new DebugException(t).printStackTrace();
- except(t);
+ if(entry != null) entry.except(t);
procedure.exception(graph, t);
}
});
} else {
- add2(graph, null);
+ if(entry != null) entry.add2(graph, null);
procedure.execute(graph, null);
// System.err.println("NamespaceIndex[" + id + "]->null");
}
}
- return getResult();
-
}
@Override
return "NamespaceIndex[" + id + "]";
}
- synchronized private void add(TObjectIntHashMap<String> result) {
-
- throw new Error("Not possible!");
-
- }
-
private void add2(ReadGraphImpl graph, TObjectIntHashMap<String> result) {
if(!isPending()) {
assert(isPending());
-// ArrayList<InternalProcedure<TObjectIntHashMap<String>>> p = null;
-
synchronized(this) {
setResult(result);
setReady();
-// p = procs;
-// procs = null;
}
-
-// if(p != null) {
-//
-// for(InternalProcedure<TObjectIntHashMap<String>> proc : p) proc.execute(graph, result);
-//
-// }
}
}
}
- static void runnerObjects(ReadGraphImpl graph, int r1, int r2, CacheEntry parent, ListenerBase listener, IntProcedure procedure) throws DatabaseException {
+ public static void runnerObjects(ReadGraphImpl graph, int r1, int r2, CacheEntry parent, ListenerBase listener, IntProcedure procedure) throws DatabaseException {
if(parent == null && listener == null) {
Objects.computeForEach(graph, r1,r2, null, procedure);
return;
}
}
- static void runnerStatements(ReadGraphImpl graph, int r1, int r2, CacheEntry parent, ListenerBase listener, TripleIntProcedure procedure) throws DatabaseException {
+ public static void runnerStatements(ReadGraphImpl graph, int r1, int r2, CacheEntry parent, ListenerBase listener, TripleIntProcedure procedure) throws DatabaseException {
if(parent == null && listener == null) {
Statements.computeForEach(graph, r1,r2, null, procedure);
return;
}
}
- static void runnerDirectObjects(ReadGraphImpl graph, int r1, int r2, CacheEntry parent, ListenerBase listener, IntProcedure procedure) throws DatabaseException {
+ public static void runnerDirectObjects(ReadGraphImpl graph, int r1, int r2, CacheEntry parent, ListenerBase listener, IntProcedure procedure) throws DatabaseException {
if(parent == null && listener == null) {
DirectObjects.computeForEach(graph, r1,r2, null, procedure);
return;
}
}
- static void runnerRelationInfoQuery(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, InternalProcedure<RelationInfo> procedure) throws DatabaseException {
+ public static void runnerRelationInfoQuery(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, InternalProcedure<RelationInfo> procedure) throws DatabaseException {
if(parent == null && listener == null) {
RelationInfoQuery.computeForEach(graph, r, null, procedure);
return;
}
}
- static void runnerURIToResource(ReadGraphImpl graph, String id, CacheEntry parent, ListenerBase listener, InternalProcedure<Integer> procedure) throws DatabaseException {
+ public static void runnerURIToResource(ReadGraphImpl graph, String id, CacheEntry parent, ListenerBase listener, InternalProcedure<Integer> procedure) throws DatabaseException {
if(parent == null && listener == null) {
URIToResource.computeForEach(graph, id, null, procedure);
return;
}
}
- static void runnerValueQuery(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, InternalProcedure<byte[]> procedure) throws DatabaseException {
+ public static void runnerValueQuery(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, InternalProcedure<byte[]> procedure) throws DatabaseException {
if(parent == null && listener == null) {
ValueQuery.computeForEach(graph, r, null, procedure);
return;
}
}
- static void runnerOrderedSet(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, IntProcedure procedure) throws DatabaseException {
+ public static void runnerOrderedSet(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, IntProcedure procedure) throws DatabaseException {
if(parent == null && listener == null) {
OrderedSet.computeForEach(graph, r, null, procedure);
return;
}
}
- static void runnerPrincipalTypes(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, IntProcedure procedure) throws DatabaseException {
+ public static void runnerPrincipalTypes(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, IntProcedure procedure) throws DatabaseException {
if(parent == null && listener == null) {
PrincipalTypes.computeForEach(graph, r, null, procedure);
return;
}
}
- static void runnerDirectPredicates(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, InternalProcedure<IntSet> procedure) throws DatabaseException {
+ public static void runnerDirectPredicates(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, InternalProcedure<IntSet> procedure) throws DatabaseException {
if(parent == null && listener == null) {
DirectPredicates.computeForEach(graph, r, null, procedure);
return;
}
}
- static void runnerPredicates(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, InternalProcedure<IntSet> procedure) throws DatabaseException {
+ public static void runnerPredicates(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, InternalProcedure<IntSet> procedure) throws DatabaseException {
if(parent == null && listener == null) {
Predicates.computeForEach(graph, r, null, procedure);
return;
}
}
- static void runnerReadEntry(ReadGraphImpl graph, Read<?> r, CacheEntry parent, ListenerBase listener, AsyncProcedure procedure) throws DatabaseException {
+ public static void runnerReadEntry(ReadGraphImpl graph, Read<?> r, CacheEntry parent, ListenerBase listener, AsyncProcedure procedure) throws DatabaseException {
if(parent == null && listener == null) {
ReadEntry.computeForEach(graph, r, null, procedure);
return;
}
}
+ AsyncReadEntry getOrCreateAsyncReadEntry(AsyncRead<?> r) throws DatabaseException {
+ AsyncReadEntry existing = null;
+ synchronized(asyncReadEntryMap) {
+ existing = (AsyncReadEntry)asyncReadEntryMap.get(r);
+ if(existing == null) {
+ existing = new AsyncReadEntry(r);
+ existing.clearResult(querySupport);
+ existing.setPending();
+ asyncReadEntryMap.put(id(r), existing);
+ return existing;
+ }
+ if(existing.requiresComputation()) {
+ existing.setPending();
+ return existing;
+ }
+ }
+ if(existing.isPending()) waitPending(existing);
+ return existing;
+ }
+
+ void remove(AsyncReadEntry entry) {
+ synchronized(asyncReadEntryMap) {
+ asyncReadEntryMap.remove(entry.request);
+ }
+ }
+
+ public static void runnerAsyncReadEntry(ReadGraphImpl graph, AsyncRead<?> r, CacheEntry parent, ListenerBase listener, AsyncProcedure procedure) throws DatabaseException {
+ if(parent == null && listener == null) {
+ AsyncReadEntry.computeForEach(graph, r, null, procedure);
+ return;
+ }
+ QueryCache cache = graph.processor.cache;
+ if(procedure == null) procedure = emptyProcedureAsyncReadEntry;
+ AsyncReadEntry entry = (AsyncReadEntry)cache.getOrCreateAsyncReadEntry(r);
+ ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure, false);
+ if(entry.isReady()) entry.performFromCache(graph, procedure);
+ else {
+ AsyncReadEntry.computeForEach(graph, r, entry, procedure);
+ if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());
+ }
+ }
+
Types getOrCreateTypes(int r) throws DatabaseException {
Types existing = null;
synchronized(typesMap) {
}
}
- static void runnerTypes(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, InternalProcedure<IntSet> procedure) throws DatabaseException {
+ public static void runnerTypes(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, InternalProcedure<IntSet> procedure) throws DatabaseException {
if(parent == null && listener == null) {
Types.computeForEach(graph, r, null, procedure);
return;
}
}
- AssertedStatements getOrCreateAssertedStatements(int r1, int r2) throws DatabaseException {
- AssertedStatements existing = null;
- synchronized(assertedStatementsMap) {
- existing = (AssertedStatements)assertedStatementsMap.get(r1,r2);
+ NamespaceIndex getOrCreateNamespaceIndex(String id) throws DatabaseException {
+ NamespaceIndex existing = null;
+ synchronized(namespaceIndexMap) {
+ existing = (NamespaceIndex)namespaceIndexMap.get(id);
if(existing == null) {
- existing = new AssertedStatements(r1,r2);
+ existing = new NamespaceIndex(id);
existing.clearResult(querySupport);
existing.setPending();
- assertedStatementsMap.put(keyR2(r1,r2), existing);
+ namespaceIndexMap.put(keyID(id), existing);
return existing;
}
if(existing.requiresComputation()) {
return existing;
}
- void remove(AssertedStatements entry) {
- synchronized(assertedStatementsMap) {
- assertedStatementsMap.remove(entry.id);
+ void remove(NamespaceIndex entry) {
+ synchronized(namespaceIndexMap) {
+ namespaceIndexMap.remove(entry.id);
}
}
- static void runnerAssertedStatements(ReadGraphImpl graph, int r1, int r2, CacheEntry parent, ListenerBase listener, TripleIntProcedure procedure) throws DatabaseException {
+ public static void runnerNamespaceIndex(ReadGraphImpl graph, String id, CacheEntry parent, ListenerBase listener, InternalProcedure<TObjectIntHashMap<String>> procedure) throws DatabaseException {
+ if(parent == null && listener == null) {
+ NamespaceIndex.computeForEach(graph, id, null, procedure);
+ return;
+ }
QueryCache cache = graph.processor.cache;
- if(procedure == null) procedure = emptyProcedureAssertedStatements;
- AssertedStatements entry = (AssertedStatements)cache.getOrCreateAssertedStatements(r1,r2);
+ if(procedure == null) procedure = emptyProcedureNamespaceIndex;
+ NamespaceIndex entry = (NamespaceIndex)cache.getOrCreateNamespaceIndex(id);
ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure, false);
if(entry.isReady()) entry.performFromCache(graph, procedure);
else {
- entry.compute(graph, procedure);
+ NamespaceIndex.computeForEach(graph, id, entry, procedure);
if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());
}
}
- NamespaceIndex getOrCreateNamespaceIndex(String id) throws DatabaseException {
- NamespaceIndex existing = null;
- synchronized(namespaceIndexMap) {
- existing = (NamespaceIndex)namespaceIndexMap.get(id);
+ AssertedStatements getOrCreateAssertedStatements(int r1, int r2) throws DatabaseException {
+ AssertedStatements existing = null;
+ synchronized(assertedStatementsMap) {
+ existing = (AssertedStatements)assertedStatementsMap.get(r1,r2);
if(existing == null) {
- existing = new NamespaceIndex(id);
+ existing = new AssertedStatements(r1,r2);
existing.clearResult(querySupport);
existing.setPending();
- namespaceIndexMap.put(keyID(id), existing);
+ assertedStatementsMap.put(keyR2(r1,r2), existing);
return existing;
}
if(existing.requiresComputation()) {
return existing;
}
- void remove(NamespaceIndex entry) {
- synchronized(namespaceIndexMap) {
- namespaceIndexMap.remove(entry.id);
+ void remove(AssertedStatements entry) {
+ synchronized(assertedStatementsMap) {
+ assertedStatementsMap.remove(entry.id);
}
}
- static void runnerNamespaceIndex(ReadGraphImpl graph, String id, CacheEntry parent, ListenerBase listener, InternalProcedure<TObjectIntHashMap<String>> procedure) throws DatabaseException {
+ public static void runnerAssertedStatements(ReadGraphImpl graph, int r1, int r2, CacheEntry parent, ListenerBase listener, TripleIntProcedure procedure) throws DatabaseException {
QueryCache cache = graph.processor.cache;
- if(procedure == null) procedure = emptyProcedureNamespaceIndex;
- NamespaceIndex entry = (NamespaceIndex)cache.getOrCreateNamespaceIndex(id);
+ if(procedure == null) procedure = emptyProcedureAssertedStatements;
+ AssertedStatements entry = (AssertedStatements)cache.getOrCreateAssertedStatements(r1,r2);
ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure, false);
if(entry.isReady()) entry.performFromCache(graph, procedure);
else {
}
}
- static void runnerAssertedPredicates(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, IntProcedure procedure) throws DatabaseException {
+ public static void runnerAssertedPredicates(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, IntProcedure procedure) throws DatabaseException {
QueryCache cache = graph.processor.cache;
if(procedure == null) procedure = emptyProcedureAssertedPredicates;
AssertedPredicates entry = (AssertedPredicates)cache.getOrCreateAssertedPredicates(r);
}
}
- static void runnerDirectSuperRelations(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, IntProcedure procedure) throws DatabaseException {
+ public static void runnerDirectSuperRelations(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, IntProcedure procedure) throws DatabaseException {
QueryCache cache = graph.processor.cache;
if(procedure == null) procedure = emptyProcedureDirectSuperRelations;
DirectSuperRelations entry = (DirectSuperRelations)cache.getOrCreateDirectSuperRelations(r);
}
}
- static void runnerSuperTypes(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, InternalProcedure<IntSet> procedure) throws DatabaseException {
+ public static void runnerSuperTypes(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, InternalProcedure<IntSet> procedure) throws DatabaseException {
QueryCache cache = graph.processor.cache;
if(procedure == null) procedure = emptyProcedureSuperTypes;
SuperTypes entry = (SuperTypes)cache.getOrCreateSuperTypes(r);
}
}
- static void runnerTypeHierarchy(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, InternalProcedure<IntSet> procedure) throws DatabaseException {
+ public static void runnerTypeHierarchy(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, InternalProcedure<IntSet> procedure) throws DatabaseException {
QueryCache cache = graph.processor.cache;
if(procedure == null) procedure = emptyProcedureTypeHierarchy;
TypeHierarchy entry = (TypeHierarchy)cache.getOrCreateTypeHierarchy(r);
}
}
- static void runnerSuperRelations(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, InternalProcedure<IntSet> procedure) throws DatabaseException {
+ public static void runnerSuperRelations(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, InternalProcedure<IntSet> procedure) throws DatabaseException {
QueryCache cache = graph.processor.cache;
if(procedure == null) procedure = emptyProcedureSuperRelations;
SuperRelations entry = (SuperRelations)cache.getOrCreateSuperRelations(r);
}
}
- AsyncReadEntry getOrCreateAsyncReadEntry(AsyncRead<?> r) throws DatabaseException {
- AsyncReadEntry existing = null;
- synchronized(asyncReadEntryMap) {
- existing = (AsyncReadEntry)asyncReadEntryMap.get(r);
- if(existing == null) {
- existing = new AsyncReadEntry(r);
- existing.clearResult(querySupport);
- existing.setPending();
- asyncReadEntryMap.put(id(r), existing);
- return existing;
- }
- if(existing.requiresComputation()) {
- existing.setPending();
- return existing;
- }
- }
- if(existing.isPending()) waitPending(existing);
- return existing;
- }
-
- void remove(AsyncReadEntry entry) {
- synchronized(asyncReadEntryMap) {
- asyncReadEntryMap.remove(entry.request);
- }
- }
-
- static void runnerAsyncReadEntry(ReadGraphImpl graph, AsyncRead<?> r, CacheEntry parent, ListenerBase listener, AsyncProcedure procedure) throws DatabaseException {
- QueryCache cache = graph.processor.cache;
- if(procedure == null) procedure = emptyProcedureAsyncReadEntry;
- AsyncReadEntry entry = (AsyncReadEntry)cache.getOrCreateAsyncReadEntry(r);
- ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure, false);
- if(entry.isReady()) entry.performFromCache(graph, procedure);
- else {
- entry.compute(graph, procedure);
- if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());
- }
- }
-
MultiReadEntry getOrCreateMultiReadEntry(MultiRead<?> r) throws DatabaseException {
MultiReadEntry existing = null;
synchronized(multiReadEntryMap) {
}
}
- static void runnerMultiReadEntry(ReadGraphImpl graph, MultiRead<?> r, CacheEntry parent, ListenerBase listener, AsyncMultiProcedure procedure) throws DatabaseException {
+ public static void runnerMultiReadEntry(ReadGraphImpl graph, MultiRead<?> r, CacheEntry parent, ListenerBase listener, AsyncMultiProcedure procedure) throws DatabaseException {
QueryCache cache = graph.processor.cache;
if(procedure == null) procedure = emptyProcedureMultiReadEntry;
MultiReadEntry entry = (MultiReadEntry)cache.getOrCreateMultiReadEntry(r);
}
}
- static void runnerAsyncMultiReadEntry(ReadGraphImpl graph, AsyncMultiRead<?> r, CacheEntry parent, ListenerBase listener, AsyncMultiProcedure procedure) throws DatabaseException {
+ public static void runnerAsyncMultiReadEntry(ReadGraphImpl graph, AsyncMultiRead<?> r, CacheEntry parent, ListenerBase listener, AsyncMultiProcedure procedure) throws DatabaseException {
QueryCache cache = graph.processor.cache;
if(procedure == null) procedure = emptyProcedureAsyncMultiReadEntry;
AsyncMultiReadEntry entry = (AsyncMultiReadEntry)cache.getOrCreateAsyncMultiReadEntry(r);
}
}
- static void runnerExternalReadEntry(ReadGraphImpl graph, ExternalRead<?> r, CacheEntry parent, ListenerBase listener, AsyncProcedure procedure) throws DatabaseException {
+ public static void runnerExternalReadEntry(ReadGraphImpl graph, ExternalRead<?> r, CacheEntry parent, ListenerBase listener, AsyncProcedure procedure) throws DatabaseException {
QueryCache cache = graph.processor.cache;
if(procedure == null) procedure = emptyProcedureExternalReadEntry;
ExternalReadEntry entry = (ExternalReadEntry)cache.getOrCreateExternalReadEntry(r);
listeners = new THashMap<CacheEntry, ArrayList<ListenerEntry>>(10, 0.75f);
}
- public <T> Object performQuery(ReadGraphImpl parentGraph, final AsyncRead<T> query, final CacheEntryBase entry_, AsyncProcedure procedure_) throws DatabaseException {
-
- AsyncReadEntry<T> entry = (AsyncReadEntry<T>)entry_;
- AsyncProcedure<T> procedure = (AsyncProcedure<T>)procedure_;
-
- ReadGraphImpl queryGraph = parentGraph.withParent(entry_);
-
- try {
-
- query.perform(queryGraph, new AsyncProcedure<T>() {
-
- @Override
- public void execute(AsyncReadGraph returnGraph, T result) {
- ReadGraphImpl impl = (ReadGraphImpl)returnGraph;
- entry.addOrSet(parentGraph, result);
- try {
- procedure.execute(parentGraph, result);
- } catch (Throwable t) {
- t.printStackTrace();
- }
-// parentBarrier.dec(query);
- }
-
- @Override
- public void exception(AsyncReadGraph returnGraph, Throwable t) {
- ReadGraphImpl impl = (ReadGraphImpl)returnGraph;
-// AsyncReadGraph resumeGraph = finalParentGraph.newAsync();
- entry.except(parentGraph, t);
- try {
- procedure.exception(parentGraph, t);
- } catch (Throwable t2) {
- t2.printStackTrace();
- }
-// parentBarrier.dec(query);
- }
-
- @Override
- public String toString() {
- return procedure.toString();
- }
-
- });
-
- } catch (Throwable t) {
-
- entry.except(t);
- try {
- procedure.exception(parentGraph, t);
- } catch (Throwable t2) {
- t2.printStackTrace();
- }
-// parentBarrier.dec(query);
-
- }
-
- return null;
-
- }
+// public <T> Object performQuery(ReadGraphImpl parentGraph, final AsyncRead<T> query, final CacheEntryBase entry_, AsyncProcedure procedure_) throws DatabaseException {
+//
+// AsyncReadEntry<T> entry = (AsyncReadEntry<T>)entry_;
+// AsyncProcedure<T> procedure = (AsyncProcedure<T>)procedure_;
+//
+// ReadGraphImpl queryGraph = parentGraph.withParent(entry_);
+//
+// try {
+//
+// query.perform(queryGraph, new AsyncProcedure<T>() {
+//
+// @Override
+// public void execute(AsyncReadGraph returnGraph, T result) {
+// ReadGraphImpl impl = (ReadGraphImpl)returnGraph;
+// entry.addOrSet(parentGraph, result);
+// try {
+// procedure.execute(parentGraph, result);
+// } catch (Throwable t) {
+// t.printStackTrace();
+// }
+//// parentBarrier.dec(query);
+// }
+//
+// @Override
+// public void exception(AsyncReadGraph returnGraph, Throwable t) {
+// ReadGraphImpl impl = (ReadGraphImpl)returnGraph;
+//// AsyncReadGraph resumeGraph = finalParentGraph.newAsync();
+// entry.except(parentGraph, t);
+// try {
+// procedure.exception(parentGraph, t);
+// } catch (Throwable t2) {
+// t2.printStackTrace();
+// }
+//// parentBarrier.dec(query);
+// }
+//
+// @Override
+// public String toString() {
+// return procedure.toString();
+// }
+//
+// });
+//
+// } catch (Throwable t) {
+//
+// entry.except(t);
+// try {
+// procedure.exception(parentGraph, t);
+// } catch (Throwable t2) {
+// t2.printStackTrace();
+// }
+//// parentBarrier.dec(query);
+//
+// }
+//
+// return null;
+//
+// }
// public <T> Object performQuery(ReadGraphImpl parentGraph, final Read<T> query, final CacheEntryBase entry_, AsyncProcedure procedure_) throws DatabaseException {
//
}
// Fall back to using the fixed builtins.
- result = querySupport.getBuiltin(id);
- if (result != 0) {
- procedure.execute(graph, result);
- return;
- }
+// result = querySupport.getBuiltin(id);
+// if (result != 0) {
+// procedure.execute(graph, result);
+// return;
+// }
- try {
- result = querySupport.getRandomAccessReference(id);
- } catch (ResourceNotFoundException e) {
- procedure.exception(graph, e);
- return;
- }
+// try {
+// result = querySupport.getRandomAccessReference(id);
+// } catch (ResourceNotFoundException e) {
+// procedure.exception(graph, e);
+// return;
+// }
if (result != 0) {
procedure.execute(graph, result);
QueryCache.runnerExternalReadEntry(graph, query, parent, listener, procedure);
}
- @Override
- public <T> T query(final ReadGraphImpl graph, final Read<T> query, final CacheEntry parent, final AsyncProcedure<T> procedure, final ListenerBase listener) throws DatabaseException {
-
- return QueryCache.resultReadEntry(graph, query, parent, listener, procedure);
-
- }
+// @Override
+// public <T> T query(final ReadGraphImpl graph, final Read<T> query, final CacheEntry parent, final AsyncProcedure<T> procedure, final ListenerBase listener) throws DatabaseException {
+//
+// return QueryCache.resultReadEntry(graph, query, parent, listener, procedure);
+//
+// }
public <T> void queryMultiRead(final ReadGraphImpl graph, final MultiRead<T> query, final CacheEntry parent, final ListenerBase listener, final AsyncMultiProcedure<T> procedure) throws DatabaseException {
CacheEntry entry = e.entry;
-// System.err.println("updateQuery " + entry);
+ System.err.println("updateQuery " + entry);
/*
* If the dependency graph forms a DAG, some entries are inserted in the
assert(procedure != null);
final ListenerBase listener = getListenerBase(procedure);
+ assert(listener == null);
InternalProcedure<IntSet> ip = new InternalProcedure<IntSet>() {
- AtomicBoolean first = new AtomicBoolean(true);
-
@Override
public void execute(final ReadGraphImpl graph, IntSet set) {
- try {
- if(first.compareAndSet(true, false)) {
- procedure.execute(graph, set);
-// impl.state.barrier.dec(this);
- } else {
- procedure.execute(impl.newRestart(graph), set);
- }
- } catch (Throwable t2) {
- Logger.defaultLogError(t2);
- }
+ procedure.execute(graph, set);
}
@Override
public void exception(ReadGraphImpl graph, Throwable t) {
- try {
- if(first.compareAndSet(true, false)) {
- procedure.exception(graph, t);
-// impl.state.barrier.dec(this);
- } else {
- procedure.exception(impl.newRestart(graph), t);
- }
- } catch (Throwable t2) {
- Logger.defaultLogError(t2);
- }
+ procedure.exception(graph, t);
}
};
@Override
final public void forRelationInfo(final ReadGraphImpl impl, final Resource subject, final AsyncProcedure<RelationInfo> procedure) {
-
+
assert(subject != null);
assert(procedure != null);
final ListenerBase listener = getListenerBase(procedure);
+ assert(listener == null);
try {
QueryCache.runnerRelationInfoQuery(impl, querySupport.getId(subject), impl.parent, listener, new InternalProcedure<RelationInfo>() {
- AtomicBoolean first = new AtomicBoolean(true);
-
@Override
public void execute(final ReadGraphImpl graph, RelationInfo set) {
- try {
- if(first.compareAndSet(true, false)) {
- procedure.execute(graph, set);
-// impl.state.barrier.dec();
- } else {
- procedure.execute(impl.newRestart(graph), set);
- }
- } catch (Throwable t2) {
- Logger.defaultLogError(t2);
- }
+ procedure.execute(graph, set);
}
@Override
public void exception(ReadGraphImpl graph, Throwable t) {
- try {
- if(first.compareAndSet(true, false)) {
- procedure.exception(graph, t);
-// impl.state.barrier.dec("ReadGraphSupportImpl.1353");
- } else {
- procedure.exception(impl.newRestart(graph), t);
- }
- } catch (Throwable t2) {
- Logger.defaultLogError(t2);
- }
+ procedure.exception(graph, t);
}
});
}
- @Override
- final public <T> void query(final ReadGraphImpl impl, final AsyncRead<T> request, final CacheEntry parent, final AsyncProcedure<T> procedure, ListenerBase listener) throws DatabaseException {
-
- assert(request != null);
- assert(procedure != null);
-
- QueryCache.runnerAsyncReadEntry(impl, request, parent, listener, procedure);
-
- }
+// @Override
+// final public <T> void query(final ReadGraphImpl impl, final AsyncRead<T> request, final CacheEntry parent, final AsyncProcedure<T> procedure, ListenerBase listener) throws DatabaseException {
+//
+// assert(request != null);
+// assert(procedure != null);
+//
+// QueryCache.runnerAsyncReadEntry(impl, request, parent, listener, procedure);
+//
+// }
// @Override
// final public <T> T tryQuery(final ReadGraphImpl graph, final Read<T> request) throws DatabaseException {
}
if(procedure.isDisposed()) return;
assert(this.procedure == null);
- this.session = graph.getSession();
this.procedure = procedure;
+ this.session = graph.getSession();
parameter.first.addListener(graph, parameter.second, this);
}
@Override
public void unregistered() {
+ if(session == null) return;
+// System.err.println("asd");
parameter.first.removeListener(session, parameter.second, this);
}
import org.simantics.db.impl.internal.RandomAccessValueSupport;
import org.simantics.db.impl.procedure.ResultCallWrappedQueryProcedure4;
import org.simantics.db.impl.procedure.ResultCallWrappedSingleQueryProcedure4;
+import org.simantics.db.impl.query.QueryCache;
import org.simantics.db.impl.query.QueryProcessor;
import org.simantics.db.impl.query.QueryProcessor.SessionRead;
import org.simantics.db.impl.query.QueryProcessor.SessionTask;
if (listener != null) {
try {
- newGraph.processor.query(newGraph, request, null, new AsyncProcedure<T>() {
+
+ AsyncProcedure ap = new AsyncProcedure<T>() {
@Override
public void exception(AsyncReadGraph graph, Throwable t) {
procedure.execute(graph, t);
}
- }, listener);
+ };
+
+ QueryCache.runnerReadEntry(newGraph, request, null, listener, ap);
+
} catch (Throwable t) {
// This is handled by the AsyncProcedure
//Logger.defaultLogError("Internal error", t);
if (listener != null) {
try {
- newGraph.processor.query(newGraph, request, null, procedure, listener);
+ QueryCache.runnerAsyncReadEntry(newGraph, request, null, listener, procedure);
+ //newGraph.processor.query(newGraph, request, null, procedure, listener);
} catch (DatabaseException e) {
Logger.defaultLogError(e);
}