import org.simantics.db.exception.DatabaseException;
import org.simantics.db.impl.graph.ReadGraphImpl;
import org.simantics.db.impl.procedure.IntProcedureAdapter;
-import org.simantics.db.impl.procedure.InternalProcedure;
-import org.simantics.db.procedure.ListenerBase;
-final public class AssertedPredicates extends CollectionUnaryQuery<IntProcedure> {
+final public class AssertedPredicates extends UnaryQuery<IntProcedure> {
AssertedPredicates(final int r) {
super(r);
public static AssertedPredicates newInstance(final int r) {
return new AssertedPredicates(r);
}
-
-// final public static void queryEach(ReadGraphImpl graph, final int r, final QueryProcessor provider, final CacheEntry parent, final ListenerBase listener, final IntProcedure procedure) throws DatabaseException {
-// QueryCache.runnerAssertedPredicates(graph, r, parent, listener, procedure);
-// }
+ @Override
+ final public void clearResult(QuerySupport support) {
+ setResult(new IntArray());
+ }
+
+ @Override
+ final public void setReady() {
+ super.setReady();
+ IntArray v = (IntArray)getResult();
+ int size = v.size();
+ if(size == 0) setResult(IntArray.EMPTY);
+ else v.trim();
+ }
+
@Override
final public void removeEntry(QueryProcessor provider) {
provider.cache.remove(this);
import org.simantics.db.AsyncReadGraph;
import org.simantics.db.common.GraphSemaphore;
import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.exception.RuntimeDatabaseException;
import org.simantics.db.impl.DebugPolicy;
import org.simantics.db.impl.graph.ReadGraphImpl;
import org.simantics.db.procedure.AsyncProcedure;
import org.simantics.db.request.AsyncRead;
-final public class AsyncReadEntry<T> extends CacheEntryBase<AsyncProcedure<T>> {
+final public class AsyncReadEntry<T> extends CacheEntryBase<AsyncProcedure<T>> implements AsyncProcedure<T> {
protected AsyncRead<T> request;
AsyncReadEntry(AsyncRead<T> request) {
- this.request = request;
- if(DebugPolicy.QUERY_STATE) System.out.println("[QUERY STATE]: created " + this);
+ this.request = request;
+ if (DebugPolicy.QUERY_STATE)
+ System.out.println("[QUERY STATE]: created " + this);
}
@Override
int makeHash() {
- return request.hashCode();
+ return request.hashCode();
}
-
+
@Override
public Object getOriginalRequest() {
return request;
}
-
+
@Override
public void discard() {
- super.discard();
- setResult(null);
+ super.discard();
+ setResult(null);
}
-
- final public void addOrSet(AsyncReadGraph graph, Object item) {
-// System.err.println("addOrSet " + request + " " + Thread.currentThread() + " " + item);
-
- assert(isPending());
-
- synchronized(this) {
- setResult(item);
- setReady();
- }
-
- }
-
-
public void except(AsyncReadGraph graph, Throwable t) {
-
- assert(isPending());
- synchronized(this) {
+ assert (isPending());
+
+ synchronized (this) {
except(t);
}
-
+
}
-
-
+
@Override
final public Query getQuery() {
-
+
return new Query() {
- @Override
- public void recompute(ReadGraphImpl graph) {
+ @Override
+ public void recompute(ReadGraphImpl graph) {
- try {
+ try {
- GraphSemaphore s = new GraphSemaphore(graph, 0);
-
- request.perform(graph , new AsyncProcedure<T>() {
+ GraphSemaphore s = new GraphSemaphore(graph, 0);
+
+ request.perform(graph, new AsyncProcedure<T>() {
@Override
public void execute(AsyncReadGraph graph, T result) {
- addOrSet(graph, result);
+ setResult(result);
+ setReady();
s.release();
}
-
- @Override
- public void exception(AsyncReadGraph graph, Throwable t) {
- except(t);
+
+ @Override
+ public void exception(AsyncReadGraph graph, Throwable t) {
+ except(t);
s.release();
}
s.waitFor(1);
- } catch (Throwable t) {
- except(t);
+ } catch (Throwable t) {
+ except(t);
}
-
- }
-
- @Override
- public void removeEntry(QueryProcessor qp) {
- qp.cache.remove(AsyncReadEntry.this);
- }
-
- @Override
- public int type() {
- return request.getFlags();
- }
-
- @Override
- public String toString() {
- if(request == null) return "DISCARDED";
- else if(isExcepted()) return request.toString() + " " + getResult();
- else return request.toString() + " " + statusOrException;
- }
-
+
+ }
+
+ @Override
+ public void removeEntry(QueryProcessor qp) {
+ qp.cache.remove(AsyncReadEntry.this);
+ }
+
+ @Override
+ public int type() {
+ return request.getFlags();
+ }
+
+ @Override
+ public String toString() {
+ if (request == null)
+ return "DISCARDED";
+ else if (isExcepted())
+ return request.toString() + " " + getResult();
+ else
+ return request.toString() + " " + statusOrException;
+ }
+
};
-
+
}
@Override
- public Object performFromCache(ReadGraphImpl graph, AsyncProcedure<T> proc) {
-
- if(isExcepted()) {
-
+ public Object performFromCache(ReadGraphImpl graph, AsyncProcedure<T> proc) {
+
+ if (isExcepted()) {
+
try {
- proc.exception(graph, (Throwable)getResult());
+ proc.exception(graph, (Throwable) getResult());
} catch (Throwable t) {
t.printStackTrace();
}
-
+
} else {
-
+
try {
- proc.execute(graph, (T)getResult());
+ proc.execute(graph, (T) getResult());
} catch (Throwable t) {
t.printStackTrace();
}
-
+
+ }
+
+ return getResult();
+
+ }
+
+ public static <T> void computeForEach(ReadGraphImpl parentGraph, AsyncRead<T> request, AsyncReadEntry<T> entry,
+ AsyncProcedure<T> procedure_) throws DatabaseException {
+
+ AsyncProcedure<T> procedure = entry != null ? entry : procedure_;
+
+ GraphSemaphore s = new GraphSemaphore(parentGraph, 0);
+
+ ReadGraphImpl queryGraph = parentGraph.withParent(entry);
+
+ request.perform(queryGraph, new AsyncProcedure<T>() {
+
+ @Override
+ public void execute(AsyncReadGraph returnGraph, T result) {
+ try {
+ procedure.execute(parentGraph, result);
+ } catch (Throwable t) {
+ t.printStackTrace();
+ }
+ s.release();
+ }
+
+ @Override
+ public void exception(AsyncReadGraph returnGraph, Throwable t) {
+ try {
+ procedure.exception(parentGraph, t);
+ } catch (Throwable t2) {
+ t2.printStackTrace();
+ }
+ s.release();
+ }
+
+ @Override
+ public String toString() {
+ return procedure.toString();
+ }
+
+ });
+
+ try {
+ s.waitFor(1);
+ } catch (InterruptedException e) {
+ throw new RuntimeDatabaseException(e);
}
-
- return getResult();
-
- }
-
- //@Override
- public Object compute(ReadGraphImpl graph, AsyncProcedure<T> procedure) throws DatabaseException {
-
- 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();
-
+
+ if (entry != null)
+ entry.performFromCache(parentGraph, procedure_);
+
+ }
+
+ @Override
+ public String toString() {
+ if (isDiscarded())
+ return "DISCARDED " + request.toString();
+ else if (isExcepted())
+ return request.toString() + " " + getResult();
+ else
+ return request.toString() + " " + statusOrException;
}
-
- 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 void execute(AsyncReadGraph graph, T result) {
+ setResult(result);
+ setReady();
+ }
+
+ @Override
+ public void exception(AsyncReadGraph graph, Throwable throwable) {
+ except(throwable);
}
-
-
- @Override
- public String toString() {
- if(isDiscarded()) return "DISCARDED " + request.toString();
- else if(isExcepted()) return request.toString() + " " + getResult();
- else return request.toString() + " " + statusOrException;
- }
}
}
@Override
- public void except(Throwable t) {
+ public void except(Throwable throwable) {
if(DebugPolicy.QUERY_STATE) System.out.println("[QUERY STATE]: excepted " + this);
if(statusOrException != DISCARDED) {
statusOrException = EXCEPTED;
- result = t;
+ result = throwable;
} else {
- LOGGER.warn("Cache entry got excepted status after being discarded: " + getClass().getSimpleName(), t);
- result = t;
+ LOGGER.warn("Cache entry got excepted status after being discarded: " + getClass().getSimpleName(), throwable);
+ result = throwable;
}
}
import org.simantics.db.impl.procedure.InternalProcedure;
import org.simantics.db.service.CollectionSupport;
-final public class ChildMap extends UnaryQuery<InternalProcedure<ObjectResourceIdMap<String>>> {
-
+final public class ChildMap extends UnaryQueryP<ObjectResourceIdMap<String>> {
+
ChildMap(final int r) {
super(r);
}
-
- @Override
- final public void removeEntry(QueryProcessor provider) {
- provider.cache.remove(this);
- }
-
- //@Override
- public Object compute(ReadGraphImpl graph, final InternalProcedure<ObjectResourceIdMap<String>> procedure) throws DatabaseException {
- computeForEach(graph, id, this, procedure);
- return getResult();
+
+ @Override
+ final public void removeEntry(QueryProcessor provider) {
+ provider.cache.remove(this);
}
- public static void computeForEach(ReadGraphImpl graph, final int root, final ChildMap entry, final InternalProcedure<ObjectResourceIdMap<String>> procedure) throws DatabaseException {
-
- if(root == 0) {
- if(entry != null)
- entry.add2(graph, null);
+ @Override
+ public void compute(ReadGraphImpl graph, final InternalProcedure<ObjectResourceIdMap<String>> procedure)
+ throws DatabaseException {
+ computeForEach(graph, id, this, procedure);
+ }
+
+ public static void computeForEach(ReadGraphImpl graph, final int root, final ChildMap entry,
+ final InternalProcedure<ObjectResourceIdMap<String>> procedure_) throws DatabaseException {
+
+ InternalProcedure<ObjectResourceIdMap<String>> procedure = entry != null ? entry : procedure_;
+
+ computeForEach2(graph, root, entry, procedure);
+
+ if (entry != null)
+ entry.performFromCache(graph, procedure_);
+
+ }
+
+ public static void computeForEach2(ReadGraphImpl graph, final int root, final ChildMap parent,
+ final InternalProcedure<ObjectResourceIdMap<String>> procedure) throws DatabaseException {
+
+ if (root == 0) {
procedure.execute(graph, null);
return;
- }
-
- QueryProcessor processor = graph.processor;
-
- final int consistsOf = processor.getConsistsOf();
- final int hasName = processor.getHasName();
-
- ObjectResourceIdMap<String> result = graph.getService(CollectionSupport.class).createObjectResourceMap(String.class);
-
- QueryCache.runnerObjects(graph, root, consistsOf, entry, null, new SyncIntProcedure() {
-
- @Override
- public void run(ReadGraphImpl graph) throws DatabaseException {
-
- if(entry != null) entry.add2(graph, result);
- procedure.execute(graph, result);
-
- }
-
- @Override
- public void finished(ReadGraphImpl graph) throws DatabaseException {
- dec(graph);
- }
-
- @Override
- public void execute(ReadGraphImpl graph, final int obj) throws DatabaseException {
-
- inc();
-
- QueryCache.runnerObjects(graph, obj, hasName, entry, null, new IntProcedure() {
-
- @Override
- public void execute(ReadGraphImpl graph, int i) throws DatabaseException {
-
- inc();
-
- QueryCache.runnerValueQuery(graph, i, entry, null, new InternalProcedure<byte[]>() {
-
- @Override
- public void execute(ReadGraphImpl graph, byte[] value) throws DatabaseException {
-
- if(value != null) {
-
- try {
-
- Binding b = WriteBindings.STRING;
- Serializer serializer = b.serializer();
- final String part = (String)serializer.deserialize(value);
- result.putId(part, obj);
-
- } catch (Throwable e) {
- if(DebugException.DEBUG) new DebugException(e).printStackTrace();
- }
-
- }
-
- dec(graph);
-
- }
-
- @Override
- public void exception(ReadGraphImpl graph, Throwable t) throws DatabaseException {
- if(entry != null) entry.except(t);
- dec(graph);
+ }
+
+ QueryProcessor processor = graph.processor;
+
+ final int consistsOf = processor.getConsistsOf();
+ final int hasName = processor.getHasName();
+
+ ObjectResourceIdMap<String> result = graph.getService(CollectionSupport.class)
+ .createObjectResourceMap(String.class);
+
+ QueryCache.runnerObjects(graph, root, consistsOf, parent, null, new SyncIntProcedure() {
+
+ @Override
+ public void run(ReadGraphImpl graph) throws DatabaseException {
+ procedure.execute(graph, result);
+ }
+
+ @Override
+ public void finished(ReadGraphImpl graph) throws DatabaseException {
+ dec(graph);
+ }
+
+ @Override
+ public void execute(ReadGraphImpl graph, final int obj) throws DatabaseException {
+
+ inc();
+
+ QueryCache.runnerObjects(graph, obj, hasName, parent, null, new IntProcedure() {
+
+ @Override
+ public void execute(ReadGraphImpl graph, int i) throws DatabaseException {
+
+ inc();
+
+ QueryCache.runnerValueQuery(graph, i, parent, null, new InternalProcedure<byte[]>() {
+
+ @Override
+ public void execute(ReadGraphImpl graph, byte[] value) throws DatabaseException {
+
+ if (value != null) {
+
+ try {
+
+ Binding b = WriteBindings.STRING;
+ Serializer serializer = b.serializer();
+ final String part = (String) serializer.deserialize(value);
+ result.putId(part, obj);
+
+ } catch (Throwable e) {
+ if (DebugException.DEBUG)
+ new DebugException(e).printStackTrace();
+ }
+
+ }
+
+ dec(graph);
+
+ }
+
+ @Override
+ public void exception(ReadGraphImpl graph, Throwable t) throws DatabaseException {
+ dec(graph);
}
- });
-
- }
-
- @Override
- public void finished(ReadGraphImpl graph) throws DatabaseException {
- dec(graph);
- }
-
- @Override
- public void exception(ReadGraphImpl graph, Throwable t) throws DatabaseException {
- if(entry != null) entry.except(t);
+ });
+
+ }
+
+ @Override
+ public void finished(ReadGraphImpl graph) throws DatabaseException {
+ dec(graph);
+ }
+
+ @Override
+ public void exception(ReadGraphImpl graph, Throwable t) throws DatabaseException {
dec(graph);
}
});
- }
-
+ }
+
});
-
- }
- @Override
- public String toString() {
- return "ChildMap[" + id + "]";
}
- private void add2(ReadGraphImpl graph, ObjectResourceIdMap<String> result) {
-
- assert(isPending());
-
- synchronized(this) {
-
- setResult(result);
- setReady();
-
- }
-
- }
-
@Override
- public Object performFromCache(ReadGraphImpl graph, InternalProcedure<ObjectResourceIdMap<String>> procedure) throws DatabaseException {
-
- assert(isReady());
-
- if(handleException(graph, procedure)) return (Throwable)statusOrException;
-
- ObjectResourceIdMap<String> result = (ObjectResourceIdMap<String>)getResult();
-
- procedure.execute(graph, result);
-
- return result;
-
+ public String toString() {
+ return "ChildMap[" + id + "]";
}
-
- @Override
- public void recompute(ReadGraphImpl graph) throws DatabaseException {
-
- compute(graph, new InternalProcedure<ObjectResourceIdMap<String>>() {
-
- @Override
- public void execute(ReadGraphImpl graph, ObjectResourceIdMap<String> result) {
- }
-
- @Override
- public void exception(ReadGraphImpl graph, Throwable t) {
- if(DebugException.DEBUG) new DebugException(t).printStackTrace();
- throw new Error("Error in recompute.", t);
- }
- });
-
- }
-
}
-
int indent = 4;
-
-
String[] signatureR1RelationInfo = { "int r", "r", "keyR", "long", "InternalProcedure<RelationInfo>", "entry.id" };
String[] signatureR1Bytes = { "int r", "r", "keyR", "long", "InternalProcedure<byte[]>", "entry.id" };
String[] signatureR1IntSet = { "int r", "r", "keyR", "long", "InternalProcedure<IntSet>", "entry.id" };
generateQuery(content, "ReadEntry", signatureRead, true, true);
generateQuery(content, "AsyncReadEntry", signatureAsyncRead, true, true);
generateQuery(content, "Types", signatureR1IntSet, true, false);
- //generateQuery(content, "NamespaceIndex", signatureID2, true);
generateQuery(content, "ChildMap", signatureChildMap, true, false);
+ generateQuery(content, "TypeHierarchy", signatureR1IntSet, true, false);
+ generateQuery(content, "SuperTypes", signatureR1IntSet, true, false);
+ generateQuery(content, "SuperRelations", signatureR1IntSet, true, false);
- generateQuery(content, "AssertedStatements", signatureR2TIP, false, false);
generateQuery(content, "AssertedPredicates", signatureR1IP, false, false);
+ generateQuery(content, "AssertedStatements", signatureR2TIP, false, false);
generateQuery(content, "DirectSuperRelations", signatureR1IP, false, false);
- generateQuery(content, "SuperTypes", signatureR1IntSet, false, false);
- generateQuery(content, "TypeHierarchy", signatureR1IntSet, false, false);
- generateQuery(content, "SuperRelations", signatureR1IntSet, false, false);
generateQuery(content, "MultiReadEntry", signatureMultiRead, false, false);
generateQuery(content, "AsyncMultiReadEntry", signatureAsyncMultiRead, false, false);
generateQuery(content, "ExternalReadEntry", signatureExternalRead, false, false);
*******************************************************************************/
package org.simantics.db.impl.query;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.impl.graph.ReadGraphImpl;
+import org.simantics.db.impl.procedure.IntProcedureAdapter;
-
-
-abstract public class CollectionUnaryQuery<T> extends UnaryQuery<T> {
+abstract public class CollectionUnaryQuery extends UnaryQuery<IntProcedure> implements IntProcedure {
public CollectionUnaryQuery(final int id) {
super(id);
}
+ abstract public void compute(ReadGraphImpl graph, IntProcedure procedure) throws DatabaseException;
+
@Override
- public void clearResult(QuerySupport support) {
+ final public void clearResult(QuerySupport support) {
setResult(new IntArray());
}
@Override
- public void setReady() {
+ final public void setReady() {
super.setReady();
IntArray v = (IntArray)getResult();
int size = v.size();
else v.trim();
}
+ @Override
+ final public Object performFromCache(ReadGraphImpl graph, final IntProcedure procedure) throws DatabaseException {
+
+ assert(isReady());
+
+ if(handleException(graph, procedure)) return EXCEPTED;
+
+ final IntArray value = (IntArray)getResult();
+ if(value.data == null) {
+ if(value.sizeOrData != IntArray.NO_DATA) procedure.execute(graph, value.sizeOrData);
+ } else {
+ for(int i = 0;i < value.sizeOrData ; i++) procedure.execute(graph, value.data[i]);
+ }
+
+ procedure.finished(graph);
+
+ return getResult();
+
+ }
+
+ @Override
+ final public void recompute(ReadGraphImpl graph) throws DatabaseException {
+
+ compute(graph, new IntProcedureAdapter() {
+
+ @Override
+ public void finished(ReadGraphImpl graph) {
+ }
+
+ @Override
+ public void exception(ReadGraphImpl graph, Throwable t) {
+ new Error("Error in recompute.", t).printStackTrace();
+ }
+
+ });
+
+ }
+
+ @Override
+ final boolean isImmutable(ReadGraphImpl graph) {
+ return graph.processor.isImmutable(id);
+ }
+
+ @Override
+ final public void execute(ReadGraphImpl graph, int i) throws DatabaseException {
+ IntArray v = (IntArray)getResult();
+ v.add(i);
+ }
+
+ @Override
+ final public void finished(ReadGraphImpl graph) throws DatabaseException {
+ setReady();
+ }
+
+ @Override
+ final public void exception(ReadGraphImpl graph, Throwable throwable) throws DatabaseException {
+ except(throwable);
+ }
+
}
*******************************************************************************/
package org.simantics.db.impl.query;
-import org.simantics.db.common.exception.DebugException;
import org.simantics.db.exception.DatabaseException;
import org.simantics.db.impl.graph.ReadGraphImpl;
-import org.simantics.db.procedure.ListenerBase;
import org.simantics.db.request.RequestFlags;
-final public class DirectObjects extends CollectionBinaryQuery<IntProcedure> {
+final public class DirectObjects extends CollectionBinaryQuery<IntProcedure> implements IntProcedure {
- DirectObjects(final int r1, final int r2) {
- super(r1, r2);
- }
+ DirectObjects(final int r1, final int r2) {
+ super(r1, r2);
+ }
- @Override
- public int type() {
- return RequestFlags.INVALIDATE;
- }
-
-// @Override
-// public void clearResult(QuerySupport support) {
-// setResult(INVALID_RESULT);
-// }
+ @Override
+ public int type() {
+ return RequestFlags.INVALIDATE;
+ }
-// final public static void queryEach(ReadGraphImpl graph, final int r1, final int r2, final QueryProcessor provider, final CacheEntry parent, final ListenerBase listener, final IntProcedure procedure) throws DatabaseException {
-//
-// assert(r1 != 0);
-// assert(r2 != 0);
-//
-// if(parent == null && listener == null) {
-// DirectObjects.computeForEach(graph, r1, r2, null, procedure);
-// } else {
-// QueryCache.runnerDirectObjects(graph, r1, r2, parent, listener, procedure);
-// }
-//
-// }
+ @Override
+ final public void removeEntry(QueryProcessor provider) {
+ provider.cache.remove(this);
+ }
- @Override
- final public void removeEntry(QueryProcessor provider) {
- provider.cache.remove(this);
- }
+ // @Override
+ public Object compute(ReadGraphImpl graph, final IntProcedure procedure) throws DatabaseException {
+ computeForEach(graph, r1(), r2(), this, procedure);
+ return getResult();
+ }
- //@Override
- public Object compute(ReadGraphImpl graph, final IntProcedure procedure) throws DatabaseException {
- computeForEach(graph, r1(), r2(), this, procedure);
- return getResult();
- }
+ static public void computeForEach(ReadGraphImpl graph, int r1, int r2, final DirectObjects entry,
+ final IntProcedure procedure_) throws DatabaseException {
- static public void computeForEach(ReadGraphImpl graph, int r1, int r2, final DirectObjects entry, final IntProcedure procedure) throws DatabaseException {
+ IntProcedure procedure = entry != null ? entry : procedure_;
- QueryProcessor processor = graph.processor;
-
- processor.querySupport.ensureLoaded(graph, r1, r2);
+ QueryProcessor processor = graph.processor;
- processor.querySupport.getObjects(graph, r1, r2, new IntProcedure() {
+ processor.querySupport.ensureLoaded(graph, r1, r2);
- @Override
- public void execute(ReadGraphImpl graph, int i) throws DatabaseException {
- procedure.execute(graph, i);
- if(entry != null) entry.add(i);
- }
+ processor.querySupport.getObjects(graph, r1, r2, procedure);
- @Override
- public void finished(ReadGraphImpl graph) {
- }
+ procedure.finished(graph);
- @Override
- public void exception(ReadGraphImpl graph, Throwable t) {
- if(DebugException.DEBUG) new DebugException(t).printStackTrace();
- }
+ if (entry != null)
+ entry.performFromCache(graph, procedure_);
- });
+ }
- if(entry != null) entry.finish(graph, processor);
- procedure.finished(graph);
+ @Override
+ public String toString() {
+ return "DirectObjects[" + r1() + " - " + r2() + "]";
+ }
- }
+ @Override
+ public void setReady() {
+ statusOrException = READY;
+ }
- @Override
- public String toString() {
- return "DirectObjects[" + r1() + " - " + r2() + "]";
- }
+// final public void add(int add) {
+//
+// assert(isPending());
+//
+// IntArray value = (IntArray)getResult();
+// value.add(add);
+//
+// }
- @Override
- public void setReady() {
- statusOrException = READY;
- }
-
- final public void add(int add) {
+ @Override
+ public Object performFromCache(ReadGraphImpl graph, IntProcedure procedure) throws DatabaseException {
- assert(isPending());
+ assert (isReady());
- IntArray value = (IntArray)getResult();
- value.add(add);
+ if (handleException(graph, procedure))
+ return getResult();
- }
+ final IntArray value = (IntArray) getResult();
+ if (value.data == null) {
+ if (value.sizeOrData != IntArray.NO_DATA)
+ procedure.execute(graph, value.sizeOrData);
+ } else {
+ for (int i = 0; i < value.sizeOrData; i++)
+ procedure.execute(graph, value.data[i]);
+ }
- final private void finish(ReadGraphImpl graph, QueryProcessor provider) {
- setReady();
- }
+ procedure.finished(graph);
- @Override
- public Object performFromCache(ReadGraphImpl graph, IntProcedure procedure) throws DatabaseException {
+ return value;
- assert(isReady());
+ }
- if(handleException(graph, procedure)) return getResult();
+ @Override
+ public void recompute(ReadGraphImpl graph) throws DatabaseException {
- final IntArray value = (IntArray)getResult();
- if(value.data == null) {
- if(value.sizeOrData != IntArray.NO_DATA) procedure.execute(graph, value.sizeOrData);
- } else {
- for(int i = 0;i < value.sizeOrData ; i++) procedure.execute(graph, value.data[i]);
- }
+ compute(graph, new IntProcedure() {
- procedure.finished(graph);
-
- return value;
+ @Override
+ public void finished(ReadGraphImpl graph) {
+ }
- }
+ @Override
+ public void exception(ReadGraphImpl graph, Throwable t) {
+ throw new Error("Error in recompute.", t);
+ }
- @Override
- public void recompute(ReadGraphImpl graph) throws DatabaseException {
-
- compute(graph, new IntProcedure() {
+ @Override
+ public void execute(ReadGraphImpl graphd, int i) {
+ }
- @Override
- public void finished(ReadGraphImpl graph) {
- }
+ });
- @Override
- public void exception(ReadGraphImpl graph, Throwable t) {
- throw new Error("Error in recompute.", t);
- }
+ }
- @Override
- public void execute(ReadGraphImpl graphd, int i) {
- }
+ @Override
+ boolean isImmutable(ReadGraphImpl graph) {
+ return graph.processor.isImmutable(r1());
+ }
- });
+ @Override
+ public void execute(ReadGraphImpl graph, int i) throws DatabaseException {
+ IntArray value = (IntArray) getResult();
+ value.add(i);
+ }
- }
+ @Override
+ public void finished(ReadGraphImpl graph) throws DatabaseException {
+ setReady();
+ }
@Override
- boolean isImmutable(ReadGraphImpl graph) {
- return graph.processor.isImmutable(r1());
+ public void exception(ReadGraphImpl graph, Throwable throwable) throws DatabaseException {
+ except(throwable);
}
-
-}
+}
import org.simantics.db.impl.graph.ReadGraphImpl;
import org.simantics.db.impl.procedure.InternalProcedure;
-final public class DirectPredicates extends CollectionUnaryQuery<InternalProcedure<IntSet>> {
+final public class DirectPredicates extends UnaryQueryP<IntSet> {
DirectPredicates(final int resource) {
super(resource);
}
- @Override
- public void clearResult(QuerySupport support) {
- // The cached result is never used
- setResult(INVALID_RESULT);
- }
-
@Override
final public void removeEntry(QueryProcessor provider) {
provider.cache.remove(this);
}
- //@Override
- public Object compute(ReadGraphImpl graph, InternalProcedure<IntSet> procedure) throws DatabaseException {
- return computeForEach(graph, id, this, procedure);
+ @Override
+ public void compute(ReadGraphImpl graph, InternalProcedure<IntSet> procedure) throws DatabaseException {
+ computeForEach(graph, id, this, procedure);
}
- public static Object computeForEach(ReadGraphImpl graph, int id, final DirectPredicates entry, final InternalProcedure<IntSet> procedure) throws DatabaseException {
+ public static Object computeForEach(ReadGraphImpl graph, int id, final DirectPredicates entry, final InternalProcedure<IntSet> procedure_) throws DatabaseException {
+ InternalProcedure<IntSet> procedure = entry != null ? entry : procedure_;
+
graph.processor.querySupport.ensureLoaded(graph, id);
final IntSet list = new IntSet(graph.processor.querySupport);
}
});
-
- if(entry != null) {
- entry.setResult(list);
- entry.setReady();
- }
procedure.execute(graph, list);
+
+ if(entry != null) entry.performFromCache(graph, procedure_);
return list;
return "DirectPredicates[" + id + "]";
}
- @Override
- public void setReady() {
- statusOrException = READY;
- }
-
- @Override
- public Object performFromCache(ReadGraphImpl graph, InternalProcedure<IntSet> procedure) throws DatabaseException {
-
- assert(isReady());
-
- if(handleException(graph, procedure)) return EXCEPTED;
-
- IntSet result = getResult();
-
- procedure.execute(graph, result);
-
- return result;
-
- }
-
- @Override
- public void recompute(ReadGraphImpl graph) throws DatabaseException {
-
- compute(graph, new InternalProcedure<IntSet>() {
-
- @Override
- public void execute(ReadGraphImpl graph, IntSet set) {
- }
-
- @Override
- public void exception(ReadGraphImpl graph, Throwable t) {
- new Error("Error in recompute.", t).printStackTrace();
- }
-
- });
-
- }
-
-
- @Override
- boolean isImmutable(ReadGraphImpl graph) {
- return graph.processor.isImmutable(id);
- }
-
}
*******************************************************************************/
package org.simantics.db.impl.query;
-import java.util.concurrent.Semaphore;
-
import org.simantics.db.common.utils.Logger;
import org.simantics.db.exception.DatabaseException;
import org.simantics.db.impl.graph.ReadGraphImpl;
import org.simantics.db.RelationInfo;
import org.simantics.db.Resource;
import org.simantics.db.common.exception.DebugException;
-import org.simantics.db.common.utils.Logger;
import org.simantics.db.exception.DatabaseException;
import org.simantics.db.exception.ManyObjectsForFunctionalRelationException;
import org.simantics.db.impl.graph.ReadGraphImpl;
import org.simantics.db.procedure.AsyncMultiProcedure;
import org.simantics.db.request.RequestFlags;
-import gnu.trove.procedure.TIntProcedure;
-
/*
* Size analysis:
* java 8 byte
*
*/
-final public class Objects extends CollectionBinaryQuery<IntProcedure> {
+final public class Objects extends CollectionBinaryQuery<IntProcedure> implements IntProcedure {
public Objects(final int r1, final int r2) {
super(r1, r2);
}
- final static private void forSingleAssertion(ReadGraphImpl graph, final int r1, final int r2, final Objects entry, final IntProcedure procedure) throws DatabaseException {
+ final static private void forSingleAssertion(ReadGraphImpl graph, final int r1, final int r2, final Objects parent, final IntProcedure procedure) throws DatabaseException {
- IntArray map = getAssertionMap(graph, r1, r2, entry);
+ IntArray map = getAssertionMap(graph, r1, r2, parent);
if(map == null) {
- if(entry != null) entry.finish(graph, procedure);
- else procedure.finished(graph);
+ procedure.finished(graph);
return;
}
int size = map.size();
if(size == 3) {
-
- int value = map.data[2];
-
- if(entry != null) {
- entry.addOrSetFunctional(value);
- entry.finish(graph, procedure);
- } else {
- procedure.execute(graph, value);
- procedure.finished(graph);
- }
-
+ int value = map.data[2];
+ procedure.execute(graph, value);
+ procedure.finished(graph);
} else if(size == 0) {
-
- if(entry != null) entry.finish(graph, procedure);
- else procedure.finished(graph);
-
+ procedure.finished(graph);
} else {
int candidateS = map.data[0];
IntSet candidateIs = null;
try {
- candidateIs = QueryCache.resultSuperTypes(graph, candidateS, entry, null);
+ candidateIs = QueryCache.resultSuperTypes(graph, candidateS, parent, null);
} catch (DatabaseException e) {
- if(entry != null) entry.except(e);
procedure.exception(graph, e);
return;
}
IntSet nextIs = null;
try {
- nextIs = QueryCache.resultSuperTypes(graph, nextS, entry, null);
+ nextIs = QueryCache.resultSuperTypes(graph, nextS, parent, null);
} catch (DatabaseException e) {
- if(entry != null) entry.except(e);
procedure.exception(graph, e);
return;
}
// candidate and next are unrelated => error
ManyObjectsForFunctionalRelationException exception = new ManyObjectsForFunctionalRelationException("Functional relation has conflicting assertions " + r1 + ", " + r2 + " " + map , r1);
-
- if(entry != null) entry.except(exception);
procedure.exception(graph, exception);
return;
}
- if(entry != null) {
- entry.addOrSetFunctional(candidateO);
- entry.finish(graph, procedure);
- } else {
- procedure.execute(graph, candidateO);
- procedure.finished(graph);
- }
+ procedure.execute(graph, candidateO);
+ procedure.finished(graph);
}
}
// Search for one statement
- final static public void computeFunctionalIndex(ReadGraphImpl graph, final int r1, final int r2, final Objects entry, final RelationInfo ri, final IntProcedure procedure) throws DatabaseException {
+ final static public void computeFunctionalIndex(ReadGraphImpl graph, final int r1, final int r2, final Objects parent, final RelationInfo ri, final IntProcedure procedure) throws DatabaseException {
if(ri.isFinal) {
if(result == 0) {
// Check for assertions
- forSingleAssertion(graph, r1, r2, entry, procedure);
+ forSingleAssertion(graph, r1, r2, parent, procedure);
} else if (result == -1) {
@Override
public void execute(ReadGraphImpl graph, int i) throws DatabaseException {
- if(entry != null) entry.addOrSetFunctional(i);
- else procedure.execute(graph, i);
+ procedure.execute(graph, i);
}
@Override
});
// Check for assertions
- forSingleAssertion(graph, r1, r2, entry, procedure);
+ forSingleAssertion(graph, r1, r2, parent, procedure);
} else {
// If functional relation was found there is no need to check assertions
- if(entry != null) {
- entry.addOrSetFunctional(result);
- entry.finish(graph, procedure);
- } else {
- procedure.execute(graph, result);
- procedure.finished(graph);
- }
+ procedure.execute(graph, result);
+ procedure.finished(graph);
}
public void run(ReadGraphImpl graph) throws DatabaseException {
if(found) {
- if(entry != null) entry.finish(graph, procedure);
- else procedure.finished(graph);
+ procedure.finished(graph);
} else {
// Check for assertions
- forSingleAssertion(graph, r1, r2, entry, procedure);
+ forSingleAssertion(graph, r1, r2, parent, procedure);
}
if(!found) {
- if(entry != null) entry.addOrSetFunctional(i);
- else procedure.execute(graph, i);
-
+ procedure.execute(graph, i);
found = true;
} else {
ManyObjectsForFunctionalRelationException exception = new ManyObjectsForFunctionalRelationException("Functional relation has more than one statement (r1=" + r1 + ", r2=" + r2 + ").", r1);
- if(entry != null) entry.except(exception);
procedure.exception(graph, exception);
}
} else {
- QueryCache.runnerSuperRelations(graph, pred, entry, null, new InternalProcedure<IntSet>() {
+ QueryCache.runnerSuperRelations(graph, pred, parent, null, new InternalProcedure<IntSet>() {
@Override
public void execute(ReadGraphImpl graph, IntSet result) throws DatabaseException {
if(!found) {
- if(entry != null) entry.addOrSetFunctional(i);
- else procedure.execute(graph, i);
-
+ procedure.execute(graph, i);
found = true;
} else {
ManyObjectsForFunctionalRelationException exception = new ManyObjectsForFunctionalRelationException("Functional relation has more than one statement (r1=" + r1 + ", r2=" + r2 + ").", r1);
- if(entry != null) entry.except(exception);
procedure.exception(graph, exception);
}
}
- final static private void forAssertions(ReadGraphImpl graph, final int r1, final int r2, final Objects entry, final IntProcedure procedure) throws DatabaseException {
+ final static private void forAssertions(ReadGraphImpl graph, final int r1, final int r2, final Objects parent, final IntProcedure procedure) throws DatabaseException {
// Note! The dependency is intentionally cut!
QueryCache.runnerPrincipalTypes(graph, r1, null, null, new SyncIntProcedure() {
@Override
public void run(ReadGraphImpl graph) throws DatabaseException {
-
- if(entry != null) entry.finish(graph, procedure);
- else procedure.finished(graph);
-
+ procedure.finished(graph);
}
TripleIntProcedure proc = new TripleIntProcedure() {
@Override
public void execute(ReadGraphImpl graph, int s, int p, int o) throws DatabaseException {
- if(entry != null) entry.addOrSet(o);
- else procedure.execute(graph, o);
+ procedure.execute(graph, o);
}
@Override
public void execute(ReadGraphImpl graph, int type) throws DatabaseException {
inc();
- QueryCache.runnerAssertedStatements(graph, type, r2, entry, null, proc);
+ QueryCache.runnerAssertedStatements(graph, type, r2, parent, null, proc);
}
}
final public static void computeNotFunctionalFinalIndex(ReadGraphImpl graph, final int r1, final int r2, final QueryProcessor provider, RelationInfo ri, AsyncMultiProcedure<Resource> procedure) {
-
throw new Error();
-
}
final public void computeNotFunctionalIndex(ReadGraphImpl graph, RelationInfo ri, final IntProcedure procedure) throws DatabaseException {
computeNotFunctionalIndex(graph, r1(), r2(), this, ri, procedure);
}
- final static public void computeNotFunctionalIndex(ReadGraphImpl graph, final int r1, final int r2, final Objects entry, RelationInfo ri, final IntProcedure procedure) throws DatabaseException {
+ final static public void computeNotFunctionalIndex(ReadGraphImpl graph, final int r1, final int r2, final Objects parent, RelationInfo ri, final IntProcedure procedure) throws DatabaseException {
if(ri.isFinal) {
@Override
public void execute(ReadGraphImpl graph, int i) throws DatabaseException {
- if(entry != null) entry.addOrSet(i);
- else procedure.execute(graph, i);
+ procedure.execute(graph, i);
}
@Override
});
if(ri.isAsserted) {
- forAssertions(graph, r1, r2, entry, procedure);
+ forAssertions(graph, r1, r2, parent, procedure);
} else {
- if(entry != null) entry.finish(graph, procedure);
- else procedure.finished(graph);
+ procedure.finished(graph);
}
} else {
@Override
public void run(ReadGraphImpl graph) throws DatabaseException {
-
- forAssertions(graph, r1, r2, entry, procedure);
-
+ forAssertions(graph, r1, r2, parent, procedure);
}
@Override
@Override
public void execute(ReadGraphImpl graph, int i) throws DatabaseException {
- if(entry != null) entry.addOrSet(i);
- else procedure.execute(graph, i);
+ procedure.execute(graph, i);
}
@Override
inc();
- QueryCache.runnerSuperRelations(graph, pred, entry, null, new InternalProcedure<IntSet>() {
+ QueryCache.runnerSuperRelations(graph, pred, parent, null, new InternalProcedure<IntSet>() {
@Override
public void execute(ReadGraphImpl graph, IntSet result) throws DatabaseException {
@Override
public void execute(ReadGraphImpl graph, int i) throws DatabaseException {
- if(entry != null) entry.addOrSet(i);
- else procedure.execute(graph, i);
+ procedure.execute(graph, i);
}
@Override
return getResult();
}
- public static void computeForEach(ReadGraphImpl graph, final int r1, final int r2, final Objects entry, final IntProcedure procedure) throws DatabaseException {
-
- RelationInfo ri = QueryCache.resultRelationInfoQuery(graph, r2, entry, null);
- graph.ensureLoaded(r1, r2);
- if(ri.isFunctional) {
- computeFunctionalIndex(graph, r1, r2, entry, ri, procedure);
- } else {
- computeNotFunctionalIndex(graph, r1, r2, entry, ri, procedure);
- }
+ public static void computeForEach(ReadGraphImpl graph, final int r1, final int r2, final Objects entry, final IntProcedure procedure_) throws DatabaseException {
+
+ IntProcedure procedure = entry != null ? entry : procedure_;
+
+ RelationInfo ri = QueryCache.resultRelationInfoQuery(graph, r2, entry, null);
+ graph.ensureLoaded(r1, r2);
+ if(ri.isFunctional) {
+ computeFunctionalIndex(graph, r1, r2, entry, ri, procedure);
+ } else {
+ computeNotFunctionalIndex(graph, r1, r2, entry, ri, procedure);
+ }
+
+ if(entry != null) entry.performFromCache(graph, procedure_);
}
return "Objects[" + r1() + " - " + r2() + "]";
}
- final private void finish(ReadGraphImpl graph, IntProcedure procedure) throws DatabaseException {
-
- assert(assertPending());
-
- synchronized(this) {
- setReady();
- }
-
- IntArray v = (IntArray)getResult();
-
- if(v.data == null) {
- if(v.sizeOrData != IntArray.NO_DATA) {
- procedure.execute(graph, v.sizeOrData);
- }
- } else {
- for(int i = 0;i < v.sizeOrData ; i++) {
- procedure.execute(graph, v.data[i]);
- }
- }
-
- procedure.finished(graph);
-
- }
-
- final public void addOrSet(int add) {
-
- assert(assertPending());
-
- IntArray value = (IntArray)getResult();
- synchronized(value) {
- value.add(add);
- }
-
- }
-
- final public void addOrSetFunctional(int add) {
-
- assert(isPending());
-
- IntArray value = (IntArray)getResult();
- value.add(add);
-
- }
+// final private void finish(ReadGraphImpl graph, IntProcedure procedure) throws DatabaseException {
+//
+// assert(assertPending());
+//
+// synchronized(this) {
+// setReady();
+// }
+//
+// IntArray v = (IntArray)getResult();
+//
+// if(v.data == null) {
+// if(v.sizeOrData != IntArray.NO_DATA) {
+// procedure.execute(graph, v.sizeOrData);
+// }
+// } else {
+// for(int i = 0;i < v.sizeOrData ; i++) {
+// procedure.execute(graph, v.data[i]);
+// }
+// }
+//
+// procedure.finished(graph);
+//
+// }
+
+// final public void addOrSet(int add) {
+//
+// assert(assertPending());
+//
+// IntArray value = (IntArray)getResult();
+// synchronized(value) {
+// value.add(add);
+// }
+//
+// }
+
+// final public void addOrSetFunctional(int add) {
+//
+// assert(isPending());
+//
+// IntArray value = (IntArray)getResult();
+// value.add(add);
+//
+// }
@Override
public Object performFromCache(ReadGraphImpl graph, final IntProcedure procedure) throws DatabaseException {
return graph.processor.isImmutable(r1());
}
+ @Override
+ public void execute(ReadGraphImpl graph, int i) throws DatabaseException {
+ IntArray value = (IntArray)getResult();
+ synchronized(value) {
+ value.add(i);
+ }
+ }
+
+ @Override
+ public void finished(ReadGraphImpl graph) throws DatabaseException {
+ setReady();
+ }
+
+ @Override
+ public void exception(ReadGraphImpl graph, Throwable throwable) throws DatabaseException {
+ except(throwable);
+ }
+
}
import org.simantics.db.exception.DatabaseException;
import org.simantics.db.impl.graph.ReadGraphImpl;
import org.simantics.db.impl.procedure.IntProcedureAdapter;
-import org.simantics.db.impl.procedure.InternalProcedure;
-import org.simantics.db.procedure.ListenerBase;
-final public class OrderedSet extends CollectionUnaryQuery<IntProcedure> {
+final public class OrderedSet extends CollectionUnaryQuery {
public OrderedSet(final int r) {
super(r);
provider.cache.remove(this);
}
- private static int nextElement(ReadGraphImpl graph, int current, int orderedSet, OrderedSet entry, final IntProcedure procedure) throws DatabaseException {
+ private static int nextElement(ReadGraphImpl graph, int current, int orderedSet, OrderedSet parent, final IntProcedure procedure) throws DatabaseException {
QueryProcessor processor = graph.processor;
AtomicInteger res = new AtomicInteger(0);
- boolean found = processor.querySupport.getObjects(graph, current, orderedSet, new IntProcedure() {
+ processor.querySupport.getObjects(graph, current, orderedSet, new IntProcedure() {
@Override
public void execute(ReadGraphImpl graph, int i) throws DatabaseException {
if(i != orderedSet) {
- if(entry != null) entry.addOrSet(i);
procedure.execute(graph, i);
}
res.set(i);
});
if(res.get() == orderedSet) {
- if(entry != null) entry.finish(graph, processor);
procedure.finished(graph);
}
}
@Override
- public void clearResult(QuerySupport support) {
- setResult(new IntArray());
- }
-
- //@Override
- public Object compute(ReadGraphImpl graph, final IntProcedure procedure) throws DatabaseException {
- computeForEach(graph, id, this, procedure);
- return getResult();
+ public void compute(ReadGraphImpl graph, final IntProcedure procedure) throws DatabaseException {
+ computeForEach(graph, id, this, procedure);
}
- static void computeForEach(ReadGraphImpl graph, int orderedSet, final OrderedSet entry, final IntProcedure procedure) throws DatabaseException {
+ static void computeForEach(ReadGraphImpl graph, int orderedSet, final OrderedSet entry, final IntProcedure procedure_) throws DatabaseException {
+
+ IntProcedure procedure = entry != null ? entry : procedure_;
int current = nextElement(graph, orderedSet, orderedSet, entry, procedure);
while(current != orderedSet) {
current = nextElement(graph, current, orderedSet, entry, procedure);
}
+ if(entry != null) entry.performFromCache(graph, procedure_);
+
}
@Override
public String toString() {
return "OrderedSet[" + id + "]";
}
-
- final private void finish(ReadGraphImpl graph, QueryProcessor provider) {
-
- assert(isPending());
-
- synchronized(this) {
- setReady();
- }
-
- }
-
- final public void addOrSet(int add) {
-
- assert(isPending());
-
- IntArray value = (IntArray)getResult();
- value.add(add);
-
- }
-
- @Override
- public Object performFromCache(ReadGraphImpl graph, final IntProcedure procedure) throws DatabaseException {
-
- assert(isReady());
-
- if(handleException(graph, procedure)) return EXCEPTED;
-
- final IntArray value = (IntArray)getResult();
- if(value.data == null) {
- if(value.sizeOrData != IntArray.NO_DATA) procedure.execute(graph, value.sizeOrData);
- } else {
- for(int i = 0;i < value.sizeOrData ; i++) procedure.execute(graph, value.data[i]);
- }
-
- procedure.finished(graph);
-
- return value;
-
- }
-
- @Override
- public void recompute(ReadGraphImpl graph) throws DatabaseException {
-
- compute(graph, new IntProcedureAdapter() {
-
- @Override
- public void finished(ReadGraphImpl graph) {
- }
-
- @Override
- public void exception(ReadGraphImpl graph, Throwable t) {
- throw new Error("Error in recompute.", t);
- }
-
- });
-
- }
}
package org.simantics.db.impl.query;
import org.simantics.db.common.exception.DebugException;
-import org.simantics.db.common.utils.Logger;
import org.simantics.db.exception.DatabaseException;
import org.simantics.db.impl.graph.ReadGraphImpl;
import org.simantics.db.impl.procedure.InternalProcedure;
-import org.simantics.db.procedure.ListenerBase;
import org.simantics.db.request.RequestFlags;
import gnu.trove.procedure.TIntProcedure;
-final public class Predicates extends UnaryQuery<InternalProcedure<IntSet>> {
+final public class Predicates extends UnaryQueryP<IntSet> {
Predicates(final int r) {
super(r);
provider.cache.remove(this);
}
- final static private void forAssertions(ReadGraphImpl graph, int r, Predicates entry, final IntSet set) throws DatabaseException {
+ final static private void forAssertions(ReadGraphImpl graph, int r, Predicates parent, final IntSet set) throws DatabaseException {
- QueryCache.runnerPrincipalTypes(graph, r, entry, null, new SyncIntProcedure() {
+ QueryCache.runnerPrincipalTypes(graph, r, parent, null, new SyncIntProcedure() {
@Override
public void run(ReadGraphImpl graph) throws DatabaseException {
public void execute(ReadGraphImpl graph, int type) throws DatabaseException {
inc();
- QueryCache.runnerAssertedPredicates(graph, type, entry, null, proc);
+ QueryCache.runnerAssertedPredicates(graph, type, parent, null, proc);
}
}
- //@Override
- public Object compute(ReadGraphImpl graph, final InternalProcedure<IntSet> procedure) throws DatabaseException {
+ @Override
+ public void compute(ReadGraphImpl graph, final InternalProcedure<IntSet> procedure) throws DatabaseException {
computeForEach(graph, id, this, procedure);
- return getResult();
}
- public static void computeForEach(ReadGraphImpl graph, final int r, final Predicates entry, final InternalProcedure<IntSet> procedure) throws DatabaseException {
+ public static void computeForEach(ReadGraphImpl graph, final int r, final Predicates entry, final InternalProcedure<IntSet> procedure_) throws DatabaseException {
+
+ InternalProcedure<IntSet> procedure = entry != null ? entry : procedure_;
IntSet direct = QueryCache.resultDirectPredicates(graph, r, entry, null);
forAssertions(graph, r, entry, result);
if(result.isEmpty()) {
-
- if(entry != null) {
- entry.setResult(direct);
- entry.setReady();
- }
-
procedure.execute(graph, direct);
-
} else {
-
direct.forEach(new TIntProcedure() {
@Override
public boolean execute(int value) {
return true;
}
});
-
- if(entry != null) {
- entry.setResult(result);
- entry.setReady();
- }
-
procedure.execute(graph, result);
-
}
-
+
+ if(entry != null) entry.performFromCache(graph, procedure_);
}
return "Predicates[" + id + "]";
}
- final public void finish(final ReadGraphImpl graph, QueryProcessor provider) {
-
- synchronized(this) {
- setReady();
- }
-
- }
-
@Override
public void clearResult(QuerySupport support) {
setResult(new IntSet(support));
}
- @Override
- public Object performFromCache(final ReadGraphImpl graph, final InternalProcedure<IntSet> procedure) throws DatabaseException {
-
- assert(isReady());
-
- if(handleException(graph, procedure)) return EXCEPTED;
-
- IntSet result = getResult();
-
- procedure.execute(graph, result);
-
- return result;
-
- }
-
- @Override
- public void recompute(ReadGraphImpl graph) throws DatabaseException {
-
- compute(graph, new InternalProcedure<IntSet>() {
-
- @Override
- public void exception(ReadGraphImpl graph, Throwable t) {
- throw new Error("Error in recompute.", t);
- }
-
- @Override
- public void execute(ReadGraphImpl graph, IntSet i) {
- }
-
- });
-
- }
-
@Override
public int type() {
return RequestFlags.IMMEDIATE_UPDATE;
}
-
-
- @Override
- boolean isImmutable(ReadGraphImpl graph) {
- return graph.processor.isImmutable(id);
- }
}
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.concurrent.Semaphore;
import org.simantics.db.common.utils.Logger;
import org.simantics.db.exception.DatabaseException;
import org.simantics.db.impl.graph.ReadGraphImpl;
import org.simantics.db.impl.procedure.IntProcedureAdapter;
import org.simantics.db.impl.procedure.InternalProcedure;
-import org.simantics.db.procedure.ListenerBase;
import gnu.trove.procedure.TIntProcedure;
import gnu.trove.set.hash.TIntHashSet;
-final public class PrincipalTypes extends CollectionUnaryQuery<IntProcedure> {
+final public class PrincipalTypes extends CollectionUnaryQuery {
PrincipalTypes(final int resource) {
super(resource);
}
- //@Override
- public Object compute(final ReadGraphImpl graph, final IntProcedure proc) throws DatabaseException {
- return computeForEach(graph, id, this, proc);
+ @Override
+ public void compute(final ReadGraphImpl graph, final IntProcedure proc) throws DatabaseException {
+ computeForEach(graph, id, this, proc);
}
- public static Object computeForEach(final ReadGraphImpl graph, final int id, final PrincipalTypes entry, final IntProcedure proc) throws DatabaseException {
+ public static Object computeForEach(final ReadGraphImpl graph, final int id, final PrincipalTypes entry, final IntProcedure procedure_) throws DatabaseException {
+
+ IntProcedure procedure = entry != null ? entry : procedure_;
+
+ Object result = computeForEach2(graph, id, entry, procedure);
+
+ if(entry != null) entry.performFromCache(graph, procedure_);
+
+ return result;
+
+ }
+
+ public static Object computeForEach2(final ReadGraphImpl graph, final int id, final PrincipalTypes parent, final IntProcedure procedure) throws DatabaseException {
- QueryProcessor provider = graph.processor;
+ QueryProcessor provider = graph.processor;
provider.querySupport.ensureLoaded(graph, id);
assert(id != 0);
int ret = provider.querySupport.getSingleInstance(id);
if(ret > 0) {
- if(entry != null) {
- entry.add(ret);
- entry.finish(graph, provider);
- }
- proc.execute(graph, ret);
- proc.finished(graph);
+ procedure.execute(graph, ret);
+ procedure.finished(graph);
return ret;
}
@Override
public void exception(ReadGraphImpl graph, Throwable t) throws DatabaseException {
- proc.exception(graph, t);
+ procedure.exception(graph, t);
}
@Override
@Override
public void exception(ReadGraphImpl graph, Throwable t) throws DatabaseException {
- proc.exception(graph, t);
+ procedure.exception(graph, t);
}
@Override
if(indirect.size() == 0) {
int size = material.size();
if(size == 0) {
- if(entry != null) entry.finish(graph, provider);
- proc.finished(graph);
+ procedure.finished(graph);
return null;
} else if(size == 1) {
int single = material.single;
- if(entry != null) {
- entry.add(single);
- entry.finish(graph, provider);
- }
- proc.execute(graph, single);
- proc.finished(graph);
+ procedure.execute(graph, single);
+ procedure.finished(graph);
return single;
} else {
- addPrincipalType(graph, new TIntHashSet(4), material.toArray(), 0, provider, entry, proc);
+ addPrincipalType(graph, new TIntHashSet(4), material.toArray(), 0, provider, parent, procedure);
return null;
}
}
-// final AtomicInteger finishes = new AtomicInteger(0);
-
indirect.forEach(new TIntProcedure() {
int finishes = 0;
if(current == indirect.size()) {
int size = material.size();
if(size == 0) {
- if(entry != null) entry.finish(graph, provider);
- proc.finished(graph);
+ procedure.finished(graph);
return true;
} else if(size == 1) {
int single = material.single;
- if(entry != null) {
- entry.add(single);
- entry.finish(graph, provider);
- }
- proc.execute(graph, single);
- proc.finished(graph);
+ procedure.execute(graph, single);
+ procedure.finished(graph);
return true;
} else {
- addPrincipalType(graph, new TIntHashSet(4), material.toArray(), 0, provider, entry, proc);
+ addPrincipalType(graph, new TIntHashSet(4), material.toArray(), 0, provider, parent, procedure);
return true;
}
}
return true;
}
- QueryCache.runnerPrincipalTypes(graph, arg0, entry, null, new IntProcedure() {
+ QueryCache.runnerPrincipalTypes(graph, arg0, parent, null, new IntProcedure() {
@Override
public void execute(ReadGraphImpl graph, int i) {
if(current == indirect.size()) {
int size = material.size();
if(size == 0) {
- if(entry != null) entry.finish(graph, provider);
- proc.finished(graph);
+ procedure.finished(graph);
return;
} else if(size == 1) {
int single = material.single;
- if(entry != null) {
- entry.add(single);
- entry.finish(graph, provider);
- }
- proc.execute(graph, single);
- proc.finished(graph);
+ procedure.execute(graph, single);
+ procedure.finished(graph);
return;
} else {
- addPrincipalType(graph, new TIntHashSet(4), material.toArray(), 0, provider, entry, proc);
+ addPrincipalType(graph, new TIntHashSet(4), material.toArray(), 0, provider, parent, procedure);
return;
}
}
@Override
public void exception(ReadGraphImpl graph, Throwable t) throws DatabaseException {
- proc.exception(graph, t);
+ procedure.exception(graph, t);
}
});
}
- private static void finish(ReadGraphImpl graph, final TIntHashSet rejects, final int[] material, final PrincipalTypes entry, final QueryProcessor provider, final IntProcedure proc) throws DatabaseException {
-
- if(entry != null) {
- for(int i : material) {
- if(!rejects.contains(i)) {
- entry.add(i);
- }
- }
- entry.finish(graph, provider);
- }
+ private static void finish(ReadGraphImpl graph, final TIntHashSet rejects, final int[] material, final IntProcedure proc) throws DatabaseException {
for(int i : material) {
if(!rejects.contains(i)) {
}
- private static void addPrincipalType(final ReadGraphImpl graph, final TIntHashSet rejects, final int[] material, int index, final QueryProcessor provider, final PrincipalTypes entry, final IntProcedure proc) throws DatabaseException {
-
- // if((counter++ % 500) == 0) System.out.println("PT " + counter + " mat = " + material.length);
+ private static void addPrincipalType(final ReadGraphImpl graph, final TIntHashSet rejects, final int[] material, int index, final QueryProcessor provider, final PrincipalTypes parent, final IntProcedure proc) throws DatabaseException {
if(index == material.length) {
- finish(graph, rejects, material, entry, provider, proc);
+ finish(graph, rejects, material, proc);
return;
}
int type = material[index++];
while(rejects.contains(type)) {
if(index == material.length) {
- finish(graph, rejects, material, entry, provider, proc);
+ finish(graph, rejects, material, proc);
return;
}
type = material[index++];
}
+
final int nextIndex = index;
- QueryCache.runnerSuperTypes(graph, type, entry, null, new InternalProcedure<IntSet>() {
+ QueryCache.runnerSuperTypes(graph, type, parent, null, new InternalProcedure<IntSet>() {
@Override
public void execute(ReadGraphImpl graph, IntSet supers) throws DatabaseException {
}
- addPrincipalType(graph, rejects, material, nextIndex, provider, entry, proc);
+ addPrincipalType(graph, rejects, material, nextIndex, provider, parent, proc);
}
public String toString() {
return "PrincipalTypes[" + id + "]";
}
-
- final private void add(int val) {
- assert(isPending());
- IntArray v = (IntArray)getResult();
- v.add(val);
- }
-
- final private void finish(ReadGraphImpl graph, QueryProcessor provider) {
-
- assert(isPending());
- synchronized(this) {
- setReady();
- }
-
- }
-
- @Override
- public Object performFromCache(ReadGraphImpl graph, final IntProcedure procedure) throws DatabaseException {
-
- assert(isReady());
-
- if(handleException(graph, procedure)) return EXCEPTED;
-
- final IntArray value = (IntArray)getResult();
- if(value.data == null) {
- if(value.sizeOrData != IntArray.NO_DATA) procedure.execute(graph, value.sizeOrData);
- } else {
- for(int i = 0;i < value.sizeOrData ; i++) procedure.execute(graph, value.data[i]);
- }
-
- procedure.finished(graph);
-
- return getResult();
-
- }
-
- @Override
- public void recompute(ReadGraphImpl graph) throws DatabaseException {
-
- compute(graph, new IntProcedureAdapter() {
-
- @Override
- public void finished(ReadGraphImpl graph) {
- }
-
- @Override
- public void exception(ReadGraphImpl graph, Throwable t) {
- new Error("Error in recompute.", t).printStackTrace();
- }
-
- });
-
- }
-
-
- @Override
- boolean isImmutable(ReadGraphImpl graph) {
- return graph.processor.isImmutable(id);
- }
@Override
protected void fillImpliedParents(QueryProcessor processor, ArrayList<CacheEntry<?>> result) {
import org.simantics.db.request.MultiRead;
import org.simantics.db.request.Read;
-import gnu.trove.map.hash.TObjectIntHashMap;
-
public class QueryCache extends QueryCacheBase {
public QueryCache(QuerySupport querySupport, int threads) {
}
}
- AssertedStatements getOrCreateAssertedStatements(QueryProcessor processor, int r1, int r2) throws DatabaseException {
- AssertedStatements existing = null;
- synchronized(assertedStatementsMap) {
- existing = (AssertedStatements)assertedStatementsMap.get(r1,r2);
+ TypeHierarchy getOrCreateTypeHierarchy(QueryProcessor processor, int r) throws DatabaseException {
+ TypeHierarchy existing = null;
+ synchronized(typeHierarchyMap) {
+ existing = (TypeHierarchy)typeHierarchyMap.get(r);
if(existing == null) {
- existing = new AssertedStatements(r1,r2);
+ existing = new TypeHierarchy(r);
existing.clearResult(querySupport);
existing.setPending();
- assertedStatementsMap.put(keyR2(r1,r2), existing);
+ typeHierarchyMap.put(keyR(r), existing);
size++;
return existing;
}
return existing;
}
- void remove(AssertedStatements entry) {
- synchronized(assertedStatementsMap) {
- assertedStatementsMap.remove(entry.id);
+ void remove(TypeHierarchy entry) {
+ synchronized(typeHierarchyMap) {
+ typeHierarchyMap.remove(entry.id);
}
}
- public static void runnerAssertedStatements(ReadGraphImpl graph, int r1, int r2, CacheEntry parent, ListenerBase listener, final TripleIntProcedure procedure) throws DatabaseException {
+ public static void runnerTypeHierarchy(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, final InternalProcedure<IntSet> procedure) throws DatabaseException {
QueryCache cache = graph.processor.cache;
- AssertedStatements entry = (AssertedStatements)cache.getOrCreateAssertedStatements(graph.processor, r1,r2);
- TripleIntProcedure procedure_ = procedure != null ? procedure : emptyProcedureAssertedStatements;
+ if(parent == null && listener == null && !cache.shouldCache(graph.processor, r)) {
+ TypeHierarchy.computeForEach(graph, r, null, procedure);
+ return;
+ }
+ TypeHierarchy entry = (TypeHierarchy)cache.getOrCreateTypeHierarchy(graph.processor, r);
+ InternalProcedure<IntSet> procedure_ = procedure != null ? procedure : emptyProcedureTypeHierarchy;
ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);
if(entry.isReady()) entry.performFromCache(graph, procedure_);
else {
assert(entry.isPending());
- entry.compute(graph, procedure_);
+ TypeHierarchy.computeForEach(graph, r, entry, procedure_);
if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());
}
}
- AssertedPredicates getOrCreateAssertedPredicates(QueryProcessor processor, int r) throws DatabaseException {
- AssertedPredicates existing = null;
- synchronized(assertedPredicatesMap) {
- existing = (AssertedPredicates)assertedPredicatesMap.get(r);
+ SuperTypes getOrCreateSuperTypes(QueryProcessor processor, int r) throws DatabaseException {
+ SuperTypes existing = null;
+ synchronized(superTypesMap) {
+ existing = (SuperTypes)superTypesMap.get(r);
if(existing == null) {
- existing = new AssertedPredicates(r);
+ existing = new SuperTypes(r);
existing.clearResult(querySupport);
existing.setPending();
- assertedPredicatesMap.put(keyR(r), existing);
+ superTypesMap.put(keyR(r), existing);
size++;
return existing;
}
return existing;
}
- void remove(AssertedPredicates entry) {
- synchronized(assertedPredicatesMap) {
- assertedPredicatesMap.remove(entry.id);
+ void remove(SuperTypes entry) {
+ synchronized(superTypesMap) {
+ superTypesMap.remove(entry.id);
}
}
- public static void runnerAssertedPredicates(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, final IntProcedure procedure) throws DatabaseException {
+ public static void runnerSuperTypes(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, final InternalProcedure<IntSet> procedure) throws DatabaseException {
QueryCache cache = graph.processor.cache;
- AssertedPredicates entry = (AssertedPredicates)cache.getOrCreateAssertedPredicates(graph.processor, r);
- IntProcedure procedure_ = procedure != null ? procedure : emptyProcedureAssertedPredicates;
+ if(parent == null && listener == null && !cache.shouldCache(graph.processor, r)) {
+ SuperTypes.computeForEach(graph, r, null, procedure);
+ return;
+ }
+ SuperTypes entry = (SuperTypes)cache.getOrCreateSuperTypes(graph.processor, r);
+ InternalProcedure<IntSet> procedure_ = procedure != null ? procedure : emptyProcedureSuperTypes;
ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);
if(entry.isReady()) entry.performFromCache(graph, procedure_);
else {
assert(entry.isPending());
- entry.compute(graph, procedure_);
+ SuperTypes.computeForEach(graph, r, entry, procedure_);
if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());
}
}
- DirectSuperRelations getOrCreateDirectSuperRelations(QueryProcessor processor, int r) throws DatabaseException {
- DirectSuperRelations existing = null;
- synchronized(directSuperRelationsMap) {
- existing = (DirectSuperRelations)directSuperRelationsMap.get(r);
+ SuperRelations getOrCreateSuperRelations(QueryProcessor processor, int r) throws DatabaseException {
+ SuperRelations existing = null;
+ synchronized(superRelationsMap) {
+ existing = (SuperRelations)superRelationsMap.get(r);
if(existing == null) {
- existing = new DirectSuperRelations(r);
+ existing = new SuperRelations(r);
existing.clearResult(querySupport);
existing.setPending();
- directSuperRelationsMap.put(keyR(r), existing);
+ superRelationsMap.put(keyR(r), existing);
size++;
return existing;
}
return existing;
}
- void remove(DirectSuperRelations entry) {
- synchronized(directSuperRelationsMap) {
- directSuperRelationsMap.remove(entry.id);
+ void remove(SuperRelations entry) {
+ synchronized(superRelationsMap) {
+ superRelationsMap.remove(entry.id);
}
}
- public static void runnerDirectSuperRelations(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, final IntProcedure procedure) throws DatabaseException {
+ public static void runnerSuperRelations(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, final InternalProcedure<IntSet> procedure) throws DatabaseException {
QueryCache cache = graph.processor.cache;
- DirectSuperRelations entry = (DirectSuperRelations)cache.getOrCreateDirectSuperRelations(graph.processor, r);
- IntProcedure procedure_ = procedure != null ? procedure : emptyProcedureDirectSuperRelations;
+ if(parent == null && listener == null && !cache.shouldCache(graph.processor, r)) {
+ SuperRelations.computeForEach(graph, r, null, procedure);
+ return;
+ }
+ SuperRelations entry = (SuperRelations)cache.getOrCreateSuperRelations(graph.processor, r);
+ InternalProcedure<IntSet> procedure_ = procedure != null ? procedure : emptyProcedureSuperRelations;
ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);
if(entry.isReady()) entry.performFromCache(graph, procedure_);
else {
assert(entry.isPending());
- entry.compute(graph, procedure_);
+ SuperRelations.computeForEach(graph, r, entry, procedure_);
if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());
}
}
- SuperTypes getOrCreateSuperTypes(QueryProcessor processor, int r) throws DatabaseException {
- SuperTypes existing = null;
- synchronized(superTypesMap) {
- existing = (SuperTypes)superTypesMap.get(r);
+ AssertedPredicates getOrCreateAssertedPredicates(QueryProcessor processor, int r) throws DatabaseException {
+ AssertedPredicates existing = null;
+ synchronized(assertedPredicatesMap) {
+ existing = (AssertedPredicates)assertedPredicatesMap.get(r);
if(existing == null) {
- existing = new SuperTypes(r);
+ existing = new AssertedPredicates(r);
existing.clearResult(querySupport);
existing.setPending();
- superTypesMap.put(keyR(r), existing);
+ assertedPredicatesMap.put(keyR(r), existing);
size++;
return existing;
}
return existing;
}
- void remove(SuperTypes entry) {
- synchronized(superTypesMap) {
- superTypesMap.remove(entry.id);
+ void remove(AssertedPredicates entry) {
+ synchronized(assertedPredicatesMap) {
+ assertedPredicatesMap.remove(entry.id);
}
}
- public static void runnerSuperTypes(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, final InternalProcedure<IntSet> procedure) throws DatabaseException {
+ public static void runnerAssertedPredicates(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, final IntProcedure procedure) throws DatabaseException {
QueryCache cache = graph.processor.cache;
- SuperTypes entry = (SuperTypes)cache.getOrCreateSuperTypes(graph.processor, r);
- InternalProcedure<IntSet> procedure_ = procedure != null ? procedure : emptyProcedureSuperTypes;
+ AssertedPredicates entry = (AssertedPredicates)cache.getOrCreateAssertedPredicates(graph.processor, r);
+ IntProcedure procedure_ = procedure != null ? procedure : emptyProcedureAssertedPredicates;
ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);
if(entry.isReady()) entry.performFromCache(graph, procedure_);
else {
}
}
- TypeHierarchy getOrCreateTypeHierarchy(QueryProcessor processor, int r) throws DatabaseException {
- TypeHierarchy existing = null;
- synchronized(typeHierarchyMap) {
- existing = (TypeHierarchy)typeHierarchyMap.get(r);
+ AssertedStatements getOrCreateAssertedStatements(QueryProcessor processor, int r1, int r2) throws DatabaseException {
+ AssertedStatements existing = null;
+ synchronized(assertedStatementsMap) {
+ existing = (AssertedStatements)assertedStatementsMap.get(r1,r2);
if(existing == null) {
- existing = new TypeHierarchy(r);
+ existing = new AssertedStatements(r1,r2);
existing.clearResult(querySupport);
existing.setPending();
- typeHierarchyMap.put(keyR(r), existing);
+ assertedStatementsMap.put(keyR2(r1,r2), existing);
size++;
return existing;
}
return existing;
}
- void remove(TypeHierarchy entry) {
- synchronized(typeHierarchyMap) {
- typeHierarchyMap.remove(entry.id);
+ void remove(AssertedStatements entry) {
+ synchronized(assertedStatementsMap) {
+ assertedStatementsMap.remove(entry.id);
}
}
- public static void runnerTypeHierarchy(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, final InternalProcedure<IntSet> procedure) throws DatabaseException {
+ public static void runnerAssertedStatements(ReadGraphImpl graph, int r1, int r2, CacheEntry parent, ListenerBase listener, final TripleIntProcedure procedure) throws DatabaseException {
QueryCache cache = graph.processor.cache;
- TypeHierarchy entry = (TypeHierarchy)cache.getOrCreateTypeHierarchy(graph.processor, r);
- InternalProcedure<IntSet> procedure_ = procedure != null ? procedure : emptyProcedureTypeHierarchy;
+ AssertedStatements entry = (AssertedStatements)cache.getOrCreateAssertedStatements(graph.processor, r1,r2);
+ TripleIntProcedure procedure_ = procedure != null ? procedure : emptyProcedureAssertedStatements;
ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);
if(entry.isReady()) entry.performFromCache(graph, procedure_);
else {
}
}
- SuperRelations getOrCreateSuperRelations(QueryProcessor processor, int r) throws DatabaseException {
- SuperRelations existing = null;
- synchronized(superRelationsMap) {
- existing = (SuperRelations)superRelationsMap.get(r);
+ DirectSuperRelations getOrCreateDirectSuperRelations(QueryProcessor processor, int r) throws DatabaseException {
+ DirectSuperRelations existing = null;
+ synchronized(directSuperRelationsMap) {
+ existing = (DirectSuperRelations)directSuperRelationsMap.get(r);
if(existing == null) {
- existing = new SuperRelations(r);
+ existing = new DirectSuperRelations(r);
existing.clearResult(querySupport);
existing.setPending();
- superRelationsMap.put(keyR(r), existing);
+ directSuperRelationsMap.put(keyR(r), existing);
size++;
return existing;
}
return existing;
}
- void remove(SuperRelations entry) {
- synchronized(superRelationsMap) {
- superRelationsMap.remove(entry.id);
+ void remove(DirectSuperRelations entry) {
+ synchronized(directSuperRelationsMap) {
+ directSuperRelationsMap.remove(entry.id);
}
}
- public static void runnerSuperRelations(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, final InternalProcedure<IntSet> procedure) throws DatabaseException {
+ public static void runnerDirectSuperRelations(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, final IntProcedure procedure) throws DatabaseException {
QueryCache cache = graph.processor.cache;
- SuperRelations entry = (SuperRelations)cache.getOrCreateSuperRelations(graph.processor, r);
- InternalProcedure<IntSet> procedure_ = procedure != null ? procedure : emptyProcedureSuperRelations;
+ DirectSuperRelations entry = (DirectSuperRelations)cache.getOrCreateDirectSuperRelations(graph.processor, r);
+ IntProcedure procedure_ = procedure != null ? procedure : emptyProcedureDirectSuperRelations;
ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);
if(entry.isReady()) entry.performFromCache(graph, procedure_);
else {
int counter = 0;
while(entry.isPending()) {
try {
- SessionTask task = processor.getOwnTask(processor.thread.get());
+ SessionTask task = null;//processor.getOwnTask(processor.thread.get());
if(task != null) {
task.run(processor.thread.get());
} else {
import org.simantics.db.AsyncReadGraph;
import org.simantics.db.exception.DatabaseException;
import org.simantics.db.impl.graph.ReadGraphImpl;
-import org.simantics.db.impl.graph.WriteGraphImpl;
import org.simantics.db.procedure.AsyncProcedure;
import org.simantics.db.request.Read;
import org.simantics.db.request.ReadExt;
import org.simantics.db.request.RequestFlags;
-final public class ReadEntry<T> extends CacheEntryBase<AsyncProcedure<T>> {
+final public class ReadEntry<T> extends CacheEntryBase<AsyncProcedure<T>> implements AsyncProcedure<T> {
- protected Read<T> request;
+ protected Read<T> request;
- public ReadEntry(Read<T> request) {
- this.request = request;
+ public ReadEntry(Read<T> request) {
+ this.request = request;
}
-
+
@Override
int makeHash() {
- return request.hashCode();
+ return request.hashCode();
}
-
+
@Override
public Object getOriginalRequest() {
return request;
}
-
+
@Override
public void discard() {
- super.discard();
- setResult(null);
- }
-
- final public Object addOrSet(AsyncReadGraph graph, Object result) {
-
-// System.err.println("addOrSet " + request + " " + Thread.currentThread() + " " + result);
-
- assert(assertPending());
-
- setResult(result);
- setReady();
-
- return result;
-
+ super.discard();
+ setResult(null);
}
@Override
final public Query getQuery() {
-
+
return new Query() {
- @Override
- public void recompute(ReadGraphImpl graph) {
-
- try {
+ @Override
+ public void recompute(ReadGraphImpl graph) {
+
+ try {
+
+ T result = request.perform(graph);
+ setResult(result);
+ setReady();
+
+ } catch (Throwable t) {
+
+ except(t);
- T result = request.perform(graph);
- addOrSet(graph, result);
+ }
+
+ }
- } catch (Throwable t) {
+ @Override
+ public void removeEntry(QueryProcessor processor) {
+ processor.cache.remove(ReadEntry.this);
+ }
- except(t);
-
+ @Override
+ public int type() {
+ if (request instanceof ReadExt) {
+ return ((ReadExt) request).getType();
+ } else {
+ return RequestFlags.INVALIDATE;
}
-
- }
-
- @Override
- public void removeEntry(QueryProcessor processor) {
- processor.cache.remove(ReadEntry.this);
- }
-
- @Override
- public int type() {
- if(request instanceof ReadExt) {
- return ((ReadExt)request).getType();
- } else {
- return RequestFlags.INVALIDATE;
- }
- }
-
- @Override
- public String toString() {
- if(request == null) return "DISCARDED";
- else return request.toString() + statusOrException;
- }
-
+ }
+
+ @Override
+ public String toString() {
+ if (request == null)
+ return "DISCARDED";
+ else
+ return request.toString() + statusOrException;
+ }
+
};
-
+
}
-
- //@Override
- public Object compute(ReadGraphImpl graph, AsyncProcedure<T> procedure) throws DatabaseException {
- ReadGraphImpl queryGraph = graph.withParent(this);
+ public static <T> void computeForEach(ReadGraphImpl graph, Read<T> request, ReadEntry<T> entry,
+ AsyncProcedure<T> procedure_) throws DatabaseException {
- try {
+ AsyncProcedure<T> procedure = entry != null ? entry : procedure_;
- addOrSet(queryGraph, request.perform(queryGraph));
- return get(queryGraph, procedure);
+ ReadGraphImpl queryGraph = entry != null ? graph.withParent(entry) : graph;
- } catch (DatabaseException e) {
+ try {
- except(e);
- return get(graph, procedure);
+ T result = request.perform(queryGraph);
+ procedure.execute(graph, result);
- } catch (Throwable t) {
+ } catch (DatabaseException e) {
- except(new DatabaseException(t));
- return get(graph, procedure);
+ procedure.exception(graph, e);
- }
-
- }
+ } catch (Throwable t) {
- public static <T> void computeForEach(ReadGraphImpl graph, Read<T> request, ReadEntry<T> entry, AsyncProcedure<T> procedure) throws DatabaseException {
-
- ReadGraphImpl queryGraph = entry != null ? graph.withParent(entry) : graph;
+ DatabaseException dbe = new DatabaseException(t);
+ procedure.exception(graph, dbe);
- try {
+ }
- T result = request.perform(queryGraph);
- if(entry != null) entry.addOrSet(queryGraph, result);
- procedure.execute(graph, result);
+ if (entry != null)
+ entry.performFromCache(queryGraph, procedure_);
- } catch (DatabaseException e) {
+ }
- if(entry != null) entry.except(e);
- procedure.exception(graph, e);
+ public Object performFromCache(ReadGraphImpl graph, AsyncProcedure<T> procedure) {
- } catch (Throwable t) {
+ AsyncProcedure<T> proc = (AsyncProcedure<T>) procedure;
- DatabaseException dbe = new DatabaseException(t);
- if(entry != null) entry.except(dbe);
- procedure.exception(graph, dbe);
+ if (proc != null) {
+ if (isExcepted()) {
+ try {
+ proc.exception(graph, (Throwable) getResult());
+ } catch (Throwable t) {
+ t.printStackTrace();
+ }
+ } else {
+ try {
+ proc.execute(graph, (T) getResult());
+ } catch (Throwable t) {
+ t.printStackTrace();
+ }
+ }
+ }
+
+ return (T) getResult();
- }
-
}
-
- public Object performFromCache(ReadGraphImpl graph, AsyncProcedure<T> procedure) {
-
- AsyncProcedure<T> proc = (AsyncProcedure<T>)procedure;
-
- if(proc != null) {
- if(isExcepted()) {
- try {
- proc.exception(graph, (Throwable)getResult());
- } catch (Throwable t) {
- t.printStackTrace();
- }
- } else {
- try {
- proc.execute(graph, (T)getResult());
- } catch (Throwable t) {
- t.printStackTrace();
- }
- }
+
+ @Override
+ public String toString() {
+ if (request == null)
+ return "DISCARDED";
+ else
+ return request.toString() + " - " + statusOrException;
+ }
+
+ public Object get(ReadGraphImpl graph, AsyncProcedure<T> procedure) throws DatabaseException {
+ if (procedure != null)
+ performFromCache(graph, procedure);
+ checkAndThrow();
+ return getResult();
+ }
+
+ @Override
+ boolean isImmutable(ReadGraphImpl graph) throws DatabaseException {
+ if (request instanceof ReadExt) {
+ return ((ReadExt) request).isImmutable(graph);
}
-
- return (T)getResult();
-
- }
-
- @Override
- public String toString() {
- if(request == null) return "DISCARDED";
- else return request.toString() + " - " + statusOrException;
- }
-
- public Object get(ReadGraphImpl graph, AsyncProcedure<T> procedure) throws DatabaseException {
- if(procedure != null) performFromCache(graph, procedure);
- checkAndThrow();
- return getResult();
- }
-
- @Override
- boolean isImmutable(ReadGraphImpl graph) throws DatabaseException {
- if(request instanceof ReadExt) {
- return ((ReadExt)request).isImmutable(graph);
- }
- return false;
- }
+ return false;
+ }
+
+ @Override
+ public void execute(AsyncReadGraph graph, T result) {
+ setResult(result);
+ setReady();
+ }
+
+ @Override
+ public void exception(AsyncReadGraph graph, Throwable throwable) {
+ except(throwable);
+ }
}
import org.simantics.db.impl.procedure.InternalProcedure;
import org.simantics.db.request.RequestFlags;
-final public class RelationInfoQuery extends UnaryQuery<InternalProcedure<RelationInfo>> {
+final public class RelationInfoQuery extends UnaryQueryP<RelationInfo> {
RelationInfoQuery(final int resource) {
super(resource);
provider.cache.remove(this);
}
- private static void computeAssertions(ReadGraphImpl graph, int r, final boolean isFinal, final boolean isFunctional, RelationInfoQuery entry, final InternalProcedure<RelationInfo> proc) throws DatabaseException {
+ private static void computeAssertions(ReadGraphImpl graph, int r, final boolean isFinal, final boolean isFunctional, RelationInfoQuery parent, final InternalProcedure<RelationInfo> procedure) throws DatabaseException {
QueryProcessor processor = graph.processor;
final int isUsedInAssertion = processor.getHasPredicateInverse();
assert(isUsedInAssertion != 0);
- QueryCache.runnerDirectObjects(graph, r, isUsedInAssertion, entry, null, new IntProcedure() {
+ QueryCache.runnerDirectObjects(graph, r, isUsedInAssertion, parent, null, new IntProcedure() {
boolean done = false;
if(done) return;
done = true;
RelationInfo result = new RelationInfo(r, isFunctional, isFinal, true);
- if(entry != null) entry.setResult(result);
- proc.execute(graph, result);
+ procedure.execute(graph, result);
}
@Override
if(done) return;
done = true;
RelationInfo result = new RelationInfo(r, isFunctional, isFinal, false);
- if(entry != null) entry.setResult(result);
- proc.execute(graph, result);
+ procedure.execute(graph, result);
}
@Override
if(done) return;
done = true;
DatabaseException e = new DatabaseException("Internal error in RelationInfoQuery");
- if(entry != null) entry.except(e);
- proc.exception(graph, e);
+ procedure.exception(graph, e);
}
});
}
- public static void computeForEach(ReadGraphImpl graph, int r, RelationInfoQuery entry, InternalProcedure<RelationInfo> procedure) throws DatabaseException {
+ public static void computeForEach(ReadGraphImpl graph, int r, RelationInfoQuery entry, InternalProcedure<RelationInfo> procedure_) throws DatabaseException {
+
+ InternalProcedure<RelationInfo> procedure = entry != null ? entry : procedure_;
QueryProcessor provider = graph.processor;
IntSet types = QueryCache.resultTypes(graph, r, entry, null);
computeAssertions(graph, r, !direct.contains(superRelationOf), types.contains(graph.processor.getFunctionalRelation()), entry, procedure);
+
+ if(entry != null) entry.performFromCache(graph, procedure_);
}
- //@Override
- public Object compute(ReadGraphImpl graph, final InternalProcedure<RelationInfo> procedure) throws DatabaseException {
+ @Override
+ public void compute(ReadGraphImpl graph, final InternalProcedure<RelationInfo> procedure) throws DatabaseException {
computeForEach(graph, id, this, procedure);
- return getResult();
}
@Override
public String toString() {
return "RelationInfoQuery[" + id + "]";
}
-
-// public void addOrSet(ReadGraphImpl graph, final RelationInfo result, final QueryProcessor provider) {
-//
-// assert(isPending());
-//
-// synchronized(this) {
-//
-// setResult(result);
-// setReady();
-//
-// }
-//
-// }
@Override
public void setResult(Object result) {
super.setResult(result);
- if(!(result instanceof RelationInfo) && !(result == NO_RESULT))
- System.err.println("foo");
setReady();
}
-
- @Override
- public Object performFromCache(ReadGraphImpl graph, InternalProcedure<RelationInfo> procedure) throws DatabaseException {
-
- assert(isReady());
-
- if(handleException(graph, procedure)) return EXCEPTED;
-
- RelationInfo result = getResult();
-
- procedure.execute(graph, result);
-
- return result;
-
- }
@Override
public int type() {
return RequestFlags.IMMEDIATE_UPDATE;
}
-
- @Override
- public void recompute(ReadGraphImpl graph) throws DatabaseException {
-
- compute(graph, new InternalProcedure<RelationInfo>() {
-
- @Override
- public void execute(ReadGraphImpl graph, RelationInfo result) {
- }
-
- @Override
- public void exception(ReadGraphImpl graph, Throwable t) {
- throw new Error("Error in recompute.", t);
- }
-
- });
-
- }
}
import org.simantics.db.procedure.ListenerBase;
import org.simantics.db.request.RequestFlags;
-final public class Statements extends CollectionBinaryQuery<TripleIntProcedure> {
+final public class Statements extends CollectionBinaryQuery<TripleIntProcedure> implements TripleIntProcedure {
public Statements(final int r1, final int r2) {
super(r1, r2);
}
- final static private void forSingleAssertion(ReadGraphImpl graph, final int r1, final int r2, final Statements entry, final TripleIntProcedure procedure) throws DatabaseException {
-
- if(entry != null) {
- assert(entry.isPending());
- }
+ final static private void forSingleAssertion(ReadGraphImpl graph, final int r1, final int r2, final Statements parent, final TripleIntProcedure procedure) throws DatabaseException {
- IntArray map = getAssertionMap(graph, r1, r2, entry);
+ IntArray map = getAssertionMap(graph, r1, r2, parent);
if(map == null) {
- if(entry != null) entry.finish(graph, procedure);
- else procedure.finished(graph);
+ procedure.finished(graph);
return;
}
int p = map.data[1];
int o = map.data[2];
- if(entry != null) {
- entry.addOrSetFunctional(s,p,o);
- entry.finish(graph, procedure);
- } else {
procedure.execute(graph, s,p,o);
procedure.finished(graph);
- }
} else if(size == 0) {
- if(entry != null) entry.finish(graph, procedure);
- else procedure.finished(graph);
+ procedure.finished(graph);
} else {
IntSet candidateIs = null;
try {
- candidateIs = QueryCache.resultSuperTypes(graph, candidateS, entry, null);
+ candidateIs = QueryCache.resultSuperTypes(graph, candidateS, parent, null);
} catch (DatabaseException e) {
- if(entry != null) entry.except(e);
procedure.exception(graph, e);
return;
}
-
-// SuperTypes candidate = SuperTypes.queryEach(graph, candidateS, graph.processor, entry, null, NOP);
-// if(candidate.isExcepted()) {
-// if(entry != null) entry.except((Throwable)candidate.getResult());
-// procedure.exception(graph, (Throwable)candidate.getResult());
-// return;
-// }
-// IntSet candidateIs = candidate.getResult();
-
for(int i=3;i<map.size();i+=3) {
int nextS = map.data[i];
IntSet nextIs = null;
try {
- nextIs = QueryCache.resultSuperTypes(graph, nextS, entry, null);
+ nextIs = QueryCache.resultSuperTypes(graph, nextS, parent, null);
} catch (DatabaseException e) {
- if(entry != null) entry.except(e);
procedure.exception(graph, e);
return;
}
-
-// SuperTypes next = SuperTypes.queryEach(graph, nextS, graph.processor, entry, null, NOP);
-// if(next.isExcepted()) {
-// if(entry != null) entry.except((Throwable)next.getResult());
-// procedure.exception(graph, (Throwable)next.getResult());
-// return;
-// }
-// IntSet nextIs = next.getResult();
if(nextIs.contains(candidateS)) {
candidateIs = nextIs;
} else {
-
// candidate and next are unrelated => error
ManyObjectsForFunctionalRelationException exception = new ManyObjectsForFunctionalRelationException("Functional relation has conflicting assertions.", r1);
-
- if(entry != null) entry.except(exception);
procedure.exception(graph, exception);
return;
-
}
}
}
- if(entry != null) {
- entry.addOrSetFunctional(candidateS, candidateP, candidateO);
- entry.finish(graph, procedure);
- } else {
- procedure.execute(graph, candidateS, candidateP, candidateO);
- procedure.finished(graph);
- }
+ procedure.execute(graph, candidateS, candidateP, candidateO);
+ procedure.finished(graph);
}
};
// Search for one statement
- final static public void computeFunctionalIndex(ReadGraphImpl graph, final int r1, final int r2, final Statements entry, final RelationInfo ri, final TripleIntProcedure procedure) throws DatabaseException {
+ final static public void computeFunctionalIndex(ReadGraphImpl graph, final int r1, final int r2, final Statements parent, final RelationInfo ri, final TripleIntProcedure procedure) throws DatabaseException {
if(ri.isFinal) {
if(result == 0) {
// Check for assertions
- forSingleAssertion(graph, r1, r2, entry, procedure);
+ forSingleAssertion(graph, r1, r2, parent, procedure);
} else if(result == -1) {
@Override
public void execute(ReadGraphImpl graph, int i) throws DatabaseException {
- if(entry != null) entry.addOrSetFunctional(r1, r2, i);
- else procedure.execute(graph, r1, r2, i);
+ procedure.execute(graph, r1, r2, i);
}
@Override
});
// Check for assertions
- forSingleAssertion(graph, r1, r2, entry, procedure);
+ forSingleAssertion(graph, r1, r2, parent, procedure);
} else {
// If functional relation was found there is no need to check assertions
- if(entry != null) {
- entry.addOrSetFunctional(r1, r2, result);
- entry.finish(graph, procedure);
- } else {
- procedure.execute(graph, r1, r2, result);
- procedure.finished(graph);
- }
+ procedure.execute(graph, r1, r2, result);
+ procedure.finished(graph);
}
public void run(ReadGraphImpl graph) throws DatabaseException {
if(found.get()) {
- if(entry != null) entry.finish(graph, procedure);
- else procedure.finished(graph);
+ procedure.finished(graph);
} else {
-
- // Check for assertions
- forSingleAssertion(graph, r1, r2, entry, procedure);
-
+ // Check for assertions
+ forSingleAssertion(graph, r1, r2, parent, procedure);
}
}
public void execute(ReadGraphImpl graph, int i) throws DatabaseException {
if(found.compareAndSet(false, true)) {
-
- if(entry != null) entry.addOrSetFunctional(r1, pred, i);
- else procedure.execute(graph, r1, pred, i);
-
+ procedure.execute(graph, r1, pred, i);
} else {
-
ManyObjectsForFunctionalRelationException exception = new ManyObjectsForFunctionalRelationException("Functional relation has more than one statement.", r1);
- if(entry != null) entry.except(exception);
procedure.exception(graph, exception);
-
}
}
inc();
- QueryCache.runnerSuperRelations(graph, pred, entry, null, new InternalProcedure<IntSet>() {
+ QueryCache.runnerSuperRelations(graph, pred, parent, null, new InternalProcedure<IntSet>() {
@Override
public void execute(ReadGraphImpl graph, IntSet result) throws DatabaseException {
public void execute(ReadGraphImpl graph, int i) throws DatabaseException {
if(found.compareAndSet(false, true)) {
-
- if(entry != null) entry.addOrSetFunctional(r1, pred, i);
- else procedure.execute(graph, r1, pred, i);
-
+ procedure.execute(graph, r1, pred, i);
} else {
-
ManyObjectsForFunctionalRelationException exception = new ManyObjectsForFunctionalRelationException("Functional relation has more than one statement.", r1);
- if(entry != null) entry.except(exception);
procedure.exception(graph, exception);
-
}
}
}
- final static private void forAssertions(ReadGraphImpl graph, final int r1, final int r2, final Statements entry, final TripleIntProcedure procedure) throws DatabaseException {
+ final static private void forAssertions(ReadGraphImpl graph, final int r1, final int r2, final Statements parent, final TripleIntProcedure procedure) throws DatabaseException {
- QueryCache.runnerPrincipalTypes(graph, r1, entry, null, new SyncIntProcedure() {
+ QueryCache.runnerPrincipalTypes(graph, r1, parent, null, new SyncIntProcedure() {
@Override
public void run(ReadGraphImpl graph) throws DatabaseException {
-
- if(entry != null) entry.finish(graph, procedure);
- else procedure.finished(graph);
-
+ procedure.finished(graph);
}
TripleIntProcedure proc = new TripleIntProcedureAdapter() {
@Override
public void execute(ReadGraphImpl graph, int s, int p, int o) throws DatabaseException {
- if(entry != null) entry.addOrSet(s, p, o);
- else procedure.execute(graph, s, p, o);
+ procedure.execute(graph, s, p, o);
}
@Override
@Override
public void execute(ReadGraphImpl graph, int type) throws DatabaseException {
-
inc();
- QueryCache.runnerAssertedStatements(graph, type, r2, entry, null, proc);
-
+ QueryCache.runnerAssertedStatements(graph, type, r2, parent, null, proc);
}
@Override
}
- final static public void computeNotFunctionalIndex(ReadGraphImpl graph, final int r1, final int r2, final Statements entry, final RelationInfo ri, final TripleIntProcedure procedure) throws DatabaseException {
+ final static public void computeNotFunctionalIndex(ReadGraphImpl graph, final int r1, final int r2, final Statements parent, final RelationInfo ri, final TripleIntProcedure procedure) throws DatabaseException {
if(ri.isFinal) {
@Override
public void execute(ReadGraphImpl graph, int i) throws DatabaseException {
- if(entry != null) entry.addOrSet(r1, r2, i);
- else procedure.execute(graph, r1, r2, i);
+ procedure.execute(graph, r1, r2, i);
}
@Override
});
if(ri.isAsserted) {
- forAssertions(graph, r1, r2, entry, procedure);
+ forAssertions(graph, r1, r2, parent, procedure);
} else {
- if(entry != null) entry.finish(graph, procedure);
- else procedure.finished(graph);
+ procedure.finished(graph);
}
} else {
@Override
public void run(ReadGraphImpl graph) throws DatabaseException {
-
- forAssertions(graph, r1, r2, entry, procedure);
-
+ forAssertions(graph, r1, r2, parent, procedure);
}
@Override
@Override
public void execute(ReadGraphImpl graph, int i) throws DatabaseException {
- if(entry != null) entry.addOrSet(r1, pred2, i);
- else procedure.execute(graph, r1, pred2, i);
+ procedure.execute(graph, r1, pred2, i);
}
@Override
try {
- IntSet result = QueryCache.resultSuperRelations(graph, pred2, entry, null);
+ IntSet result = QueryCache.resultSuperRelations(graph, pred2, parent, null);
if(result.contains(r2)) {
inc();
@Override
public void execute(ReadGraphImpl graph, int i) throws DatabaseException {
- if(entry != null) entry.addOrSet(r1, pred2, i);
- else procedure.execute(graph, r1, pred2, i);
+ procedure.execute(graph, r1, pred2, i);
}
}
- public static void computeForEach(ReadGraphImpl graph, final int r1, final int r2, final Statements entry, final TripleIntProcedure procedure) throws DatabaseException {
-
- if(entry != null) {
- assert(entry.isPending());
- }
+ public static void computeForEach(ReadGraphImpl graph, final int r1, final int r2, final Statements entry, final TripleIntProcedure procedure_) throws DatabaseException {
+
+ TripleIntProcedure procedure = entry != null ? entry : procedure_;
- QueryCache.runnerRelationInfoQuery(graph, r2, entry, null, new InternalProcedure<RelationInfo>() {
-
- @Override
- public void execute(ReadGraphImpl graph, final RelationInfo ri) throws DatabaseException {
-
- graph.ensureLoaded(r1, r2);
- if(ri.isFunctional) {
- computeFunctionalIndex(graph, r1, r2, entry, ri, procedure);
- } else {
- computeNotFunctionalIndex(graph, r1, r2, entry, ri, procedure);
- }
-
- }
-
- @Override
- public void exception(ReadGraphImpl graph, Throwable t) throws DatabaseException {
- procedure.exception(graph, t);
- }
+ RelationInfo ri = QueryCache.resultRelationInfoQuery(graph, r2, entry, null);
+ graph.ensureLoaded(r1, r2);
+ if(ri.isFunctional) {
+ computeFunctionalIndex(graph, r1, r2, entry, ri, procedure);
+ } else {
+ computeNotFunctionalIndex(graph, r1, r2, entry, ri, procedure);
+ }
- });
+ if(entry != null) entry.performFromCache(graph, procedure_);
}
boolean isImmutable(ReadGraphImpl graph) {
return graph.processor.isImmutable(r1());
}
+
+ @Override
+ public void execute(ReadGraphImpl graph, int s, int p, int o) throws DatabaseException {
+ addOrSet(s, p, o);
+ }
+
+ @Override
+ public void finished(ReadGraphImpl graph) throws DatabaseException {
+ setReady();
+ }
+
+ @Override
+ public void exception(ReadGraphImpl graph, Throwable throwable) throws DatabaseException {
+ except(throwable);
+ }
}
import gnu.trove.procedure.TIntProcedure;
import gnu.trove.set.hash.TIntHashSet;
-final public class SuperRelations extends UnaryQuery<InternalProcedure<IntSet>> {
+final public class SuperRelations extends UnaryQueryP<IntSet> {
SuperRelations(final int resource) {
super(resource);
provider.cache.remove(this);
}
- static int histoCounter = 0;
- static int counter = 0;
-
- class Koss {
+ static class Koss {
private TIntHashSet set = null;
public int single = 0;
}
- //@Override
- public Object compute(final ReadGraphImpl graph, final InternalProcedure<IntSet> procedure) throws DatabaseException {
+ public void compute(final ReadGraphImpl graph, final InternalProcedure<IntSet> procedure) throws DatabaseException {
+ computeForEach(graph, id, this, procedure);
+ }
+
+ static class DirectProcedure extends Koss implements IntProcedure, TIntProcedure, InternalProcedure<IntSet> {
+
+ IntSet result;
+ InternalProcedure<IntSet> proc;
+
+ public DirectProcedure(IntSet result, InternalProcedure<IntSet> proc) {
+ this.result = result;
+ this.proc = proc;
+ }
+
+ @Override
+ final public boolean execute(int r) {
+ result.add(r);
+ return true;
+ }
+ @Override
+ final public void execute(ReadGraphImpl graph, int r) {
+ if(single == 0) {
+ single = r;
+ return;
+ }
+ add(r);
+ }
+ @Override
+ final public void execute(ReadGraphImpl graph, IntSet set) throws DatabaseException {
+ set.forEach(this);
+ proc.execute(graph, result);
+ }
+ @Override
+ public void finished(ReadGraphImpl graph) {
+ }
+ @Override
+ public void exception(ReadGraphImpl graph, Throwable t) {
+ throw new Error("Errors are not supported.", t);
+ }
- QueryProcessor processor = graph.processor;
+ }
+
+ public static Object computeForEach(final ReadGraphImpl graph, int id, SuperRelations entry, final InternalProcedure<IntSet> procedure_) throws DatabaseException {
+
+ InternalProcedure<IntSet> procedure = entry != null ? entry : procedure_;
+
+ QueryProcessor processor = graph.processor;
processor.querySupport.ensureLoaded(graph, id);
final IntSet result = new IntSet(processor.querySupport);
- final class DirectProcedure extends Koss implements IntProcedure, TIntProcedure, InternalProcedure<IntSet> {
- @Override
- final public boolean execute(int r) {
- result.add(r);
- return true;
- }
- @Override
- final public void execute(ReadGraphImpl graph, int r) {
- if(single == 0) {
- single = r;
- return;
- }
- add(r);
- }
- @Override
- final public void execute(ReadGraphImpl graph, IntSet set) throws DatabaseException {
- set.forEach(this);
- addOrSet(graph, result, processor);
- proc.execute(graph, result);
- }
- @Override
- public void finished(ReadGraphImpl graph) {
- }
- @Override
- public void exception(ReadGraphImpl graph, Throwable t) {
- throw new Error("Errors are not supported.", t);
- }
-
- }
-
- final DirectProcedure directProc = new DirectProcedure();
+ final DirectProcedure directProc = new DirectProcedure(result, proc);
processor.querySupport.getObjects(graph, id, subrelationOf, directProc);
int size = directProc.size();
if(size == 0) {
-
- addOrSet(graph, IntSet.EMPTY, processor);
proc.execute(graph, IntSet.EMPTY);
-
} else if (size == 1) {
-
result.add(directProc.single);
- QueryCache.runnerSuperRelations(graph, directProc.single, SuperRelations.this, null, directProc);
-
+ QueryCache.runnerSuperRelations(graph, directProc.single, entry, null, directProc);
} else {
- // if((counter++ % 500) == 0) System.out.println("SR " + counter);
-
final TIntProcedure addToResult = new TIntProcedure() {
@Override
public boolean execute(int r) {
result.add(arg0);
}
- QueryCache.runnerSuperRelations(graph, arg0, SuperRelations.this, null, new InternalProcedure<IntSet>() {
+ QueryCache.runnerSuperRelations(graph, arg0, entry, null, new InternalProcedure<IntSet>() {
@Override
public void execute(ReadGraphImpl graph, IntSet set) throws DatabaseException {
set.forEach(addToResult);
int current = finishes.addAndGet(1);
if(current == directProc.size()) {
- addOrSet(graph, result, processor);
proc.execute(graph, result);
return;
}
}
+ if(entry != null) entry.performFromCache(graph, procedure_);
+
return result;
}
public String toString() {
return "SuperRelations[" + id + "]";
}
-
- private void addOrSet(ReadGraphImpl graph, final IntSet value, QueryProcessor provider) {
-
- assert(!isReady());
-
- synchronized(this) {
-
- value.trim();
- setResult(value);
- setReady();
-
- }
-
- }
-
- @Override
- public Object performFromCache(ReadGraphImpl graph, InternalProcedure<IntSet> procedure) throws DatabaseException {
-
- assert(isReady());
-
- if(handleException(graph, procedure)) return null;
-
- IntSet result = getResult();
-
- procedure.execute(graph, result);
-
- return result;
-
- }
-
- @Override
- public void recompute(ReadGraphImpl graph) throws DatabaseException {
-
- compute(graph, new InternalProcedure<IntSet>() {
-
- @Override
- public void execute(ReadGraphImpl graph, IntSet result) {
- }
-
- @Override
- public void exception(ReadGraphImpl graph, Throwable t) {
- new Error("Error in recompute.", t).printStackTrace();
- }
-
- });
-
- }
-
- @Override
- boolean isImmutable(ReadGraphImpl graph) {
- return graph.processor.isImmutable(id);
- }
}
import org.simantics.db.exception.DatabaseException;
import org.simantics.db.impl.graph.ReadGraphImpl;
import org.simantics.db.impl.procedure.InternalProcedure;
-import org.simantics.db.procedure.ListenerBase;
import gnu.trove.procedure.TIntProcedure;
-final public class SuperTypes extends UnaryQuery<InternalProcedure<IntSet>> {
+final public class SuperTypes extends UnaryQueryP<IntSet> {
SuperTypes(final int resource) {
super(resource);
}
-
-// final public static SuperTypes queryEach(ReadGraphImpl graph, final int r, final QueryProcessor provider, final CacheEntry parent, final ListenerBase listener, final InternalProcedure<IntSet> procedure) throws DatabaseException {
-// return QueryCache.runnerSuperTypes(graph, r, parent, listener, procedure);
-// }
@Override
final public void removeEntry(QueryProcessor provider) {
provider.cache.remove(this);
}
- //@Override
- public Object compute(ReadGraphImpl graph, final InternalProcedure<IntSet> procedure) throws DatabaseException {
- return computeForEach(graph, id, this, procedure);
- }
-
- private static void addOrSet(ReadGraphImpl graph, SuperTypes entry, IntSet value) {
- if(entry != null) {
- entry.addOrSet(graph, value, graph.processor);
- }
+ @Override
+ public void compute(ReadGraphImpl graph, final InternalProcedure<IntSet> procedure) throws DatabaseException {
+ computeForEach(graph, id, this, procedure);
}
- public static Object computeForEach(ReadGraphImpl graph, int r, SuperTypes entry, final InternalProcedure<IntSet> procedure) throws DatabaseException {
+ public static Object computeForEach(ReadGraphImpl graph, int r, SuperTypes entry, final InternalProcedure<IntSet> procedure_) throws DatabaseException {
+ InternalProcedure<IntSet> procedure = entry != null ? entry : procedure_;
+
QueryProcessor provider = graph.processor;
final int inherits = provider.getInherits();
@Override
public void run(ReadGraphImpl graph) throws DatabaseException {
-
- addOrSet(graph, entry, result);
procedure.execute(graph, result);
-
}
@Override
public void execute(ReadGraphImpl graph, final int i) throws DatabaseException {
-// assert(graph.parent == parent);
-
synchronized(result) {
result.add(i);
}
});
- return result;
-
- }
-
- @Override
- public String toString() {
- return "SuperTypes2[" + id + "]";
- }
-
- private void addOrSet(ReadGraphImpl graph, final IntSet value, QueryProcessor provider) {
-
- assert(!isReady());
-
- synchronized(this) {
-
- value.trim();
- setResult(value);
- setReady();
-
- }
-
- }
-
- @Override
- public Object performFromCache(ReadGraphImpl graph, InternalProcedure<IntSet> procedure) throws DatabaseException {
-
- assert(isReady());
-
- if(handleException(graph, procedure)) return null;
-
- IntSet result = getResult();
-
- procedure.execute(graph, result);
+ if(entry != null) entry.performFromCache(graph, procedure_);
return result;
}
@Override
- public void recompute(ReadGraphImpl graph) throws DatabaseException {
-
- compute(graph, new InternalProcedure<IntSet>() {
-
- @Override
- public void execute(ReadGraphImpl graph, IntSet result) {
- }
-
- @Override
- public void exception(ReadGraphImpl graph, Throwable t) {
- new Error("Error in recompute.", t).printStackTrace();
- }
-
- });
-
+ public String toString() {
+ return "SuperTypes[" + id + "]";
}
- @Override
- boolean isImmutable(ReadGraphImpl graph) {
- return graph.processor.isImmutable(id);
- }
}
import gnu.trove.procedure.TIntProcedure;
-final public class TypeHierarchy extends UnaryQuery<InternalProcedure<IntSet>> {
+final public class TypeHierarchy extends UnaryQueryP<IntSet> {
TypeHierarchy(final int resource) {
super(resource);
provider.cache.remove(this);
}
- //@Override
- public IntSet compute(ReadGraphImpl graph, final InternalProcedure<IntSet> procedure) throws DatabaseException {
+ @Override
+ public void compute(final ReadGraphImpl graph, final InternalProcedure<IntSet> procedure) throws DatabaseException {
+ computeForEach(graph, id, this, procedure);
+ }
+
+ public static IntSet computeForEach(ReadGraphImpl graph, int id, TypeHierarchy entry, final InternalProcedure<IntSet> procedure_) throws DatabaseException {
+
+ InternalProcedure<IntSet> procedure = entry != null ? entry : procedure_;
QueryProcessor processor = graph.processor;
}
};
- QueryCache.runnerSuperTypes(graph, id, TypeHierarchy.this, null, new InternalProcedure<IntSet>() {
+ QueryCache.runnerSuperTypes(graph, id, entry, null, new InternalProcedure<IntSet>() {
@Override
public void execute(ReadGraphImpl graph, IntSet types) throws DatabaseException {
-
types.forEach(addToResult);
- addOrSet(graph, result, processor);
procedure.execute(graph, result);
-
}
@Override
});
- return result;
-
- }
-
- @Override
- public String toString() {
- return "TypeHierarchy[" + id + "]";
- }
-
- private void addOrSet(ReadGraphImpl graph, final IntSet value, QueryProcessor provider) {
-
- assert(!isReady());
-
- synchronized(this) {
-
- value.trim();
- setResult(value);
- setReady();
-
- }
-
- }
-
- @Override
- public Object performFromCache(ReadGraphImpl graph, InternalProcedure<IntSet> procedure) throws DatabaseException {
-
- assert(isReady());
-
- if(handleException(graph, procedure)) return null;
-
- IntSet result = getResult();
-
- procedure.execute(graph, result);
+ if(entry != null) entry.performFromCache(graph, procedure_);
return result;
-
- }
-
- @Override
- public void recompute(ReadGraphImpl graph) throws DatabaseException {
-
- compute(graph, new InternalProcedure<IntSet>() {
-
- @Override
- public void execute(ReadGraphImpl graph, IntSet result) {
- }
-
- @Override
- public void exception(ReadGraphImpl graph, Throwable t) {
- new Error("Error in recompute.", t).printStackTrace();
- }
- });
-
}
@Override
- boolean isImmutable(ReadGraphImpl graph) {
- return graph.processor.isImmutable(id);
+ public String toString() {
+ return "TypeHierarchy[" + id + "]";
}
}
import gnu.trove.procedure.TIntProcedure;
-final public class Types extends UnaryQuery<InternalProcedure<IntSet>> {
-
+final public class Types extends UnaryQueryP<IntSet> {
+
Types(final int resource) {
super(resource);
}
- @Override
- final public void removeEntry(QueryProcessor provider) {
- provider.cache.remove(this);
- }
+ @Override
+ final public void removeEntry(QueryProcessor provider) {
+ provider.cache.remove(this);
+ }
- //@Override
- public Object compute(final ReadGraphImpl graph, final InternalProcedure<IntSet> procedure) throws DatabaseException {
- computeForEach(graph, id, this, procedure);
- return getResult();
- }
+ @Override
+ public void compute(final ReadGraphImpl graph, final InternalProcedure<IntSet> procedure) throws DatabaseException {
+ computeForEach(graph, id, this, procedure);
+ }
- public static void computeForEach(final ReadGraphImpl graph, int id, Types entry, final InternalProcedure<IntSet> procedure) throws DatabaseException {
+ public static void computeForEach(final ReadGraphImpl graph, int id, Types entry,
+ final InternalProcedure<IntSet> procedure_) throws DatabaseException {
- assert(procedure != null);
+ InternalProcedure<IntSet> procedure = entry != null ? entry : procedure_;
+
+ computeForEach2(graph, id, entry, procedure);
+
+ if (entry != null)
+ entry.performFromCache(graph, procedure_);
+
+ }
- QueryProcessor processor = graph.processor;
+ public static void computeForEach2(final ReadGraphImpl graph, int id, Types parent,
+ final InternalProcedure<IntSet> procedure) throws DatabaseException {
- processor.querySupport.ensureLoaded(graph, id);
-
- int ret = processor.querySupport.getSingleInstance(id);
- if(ret > 0) {
+ QueryProcessor processor = graph.processor;
- TypeHierarchy.queryEach(graph, ret, processor, entry, null, new InternalProcedure<IntSet>() {
+ processor.querySupport.ensureLoaded(graph, id);
- @Override
- public void execute(ReadGraphImpl graph, IntSet types) throws DatabaseException {
+ int ret = processor.querySupport.getSingleInstance(id);
+ if (ret > 0) {
- if(entry != null) {
- entry.addOrSet(graph, types, processor);
- entry.finish();
- }
- procedure.execute(graph, types);
+ TypeHierarchy.queryEach(graph, ret, processor, parent, null, new InternalProcedure<IntSet>() {
- }
+ @Override
+ public void execute(ReadGraphImpl graph, IntSet types) throws DatabaseException {
+ procedure.execute(graph, types);
+ }
- @Override
- public void exception(ReadGraphImpl graph, Throwable t) throws DatabaseException {
- procedure.exception(graph, t);
- }
+ @Override
+ public void exception(ReadGraphImpl graph, Throwable t) throws DatabaseException {
+ procedure.exception(graph, t);
+ }
- });
-
- return;
+ });
- }
-
- final int instanceOf = processor.getInstanceOf();
+ return;
+
+ }
+
+ final int instanceOf = processor.getInstanceOf();
final int inherits = processor.getInherits();
final int subrelationOf = processor.getSubrelationOf();
final IntSet result = new IntSet(processor.querySupport);
-
+
final TIntProcedure addToResult = new TIntProcedure() {
@Override
public boolean execute(int r) {
- synchronized(result) {
- result.add(r);
- }
+ synchronized (result) {
+ result.add(r);
+ }
return true;
}
};
-
+
final AtomicInteger finishes = new AtomicInteger(0);
-
+
SyncIntProcedure instanceOfProcedure = new SyncIntProcedure() {
-
+
@Override
public void run(ReadGraphImpl graph) throws DatabaseException {
-
- if(finishes.addAndGet(1) == 3) {
- if(entry != null) entry.addOrSet(graph, result, processor);
+
+ if (finishes.addAndGet(1) == 3) {
procedure.execute(graph, result);
- }
-
+ }
+
}
-
+
@Override
public void execute(ReadGraphImpl graph, int i) throws DatabaseException {
-
- result.add(i);
-
+
+ result.add(i);
+
inc();
- QueryCache.runnerSuperTypes(graph, i, entry, null, new InternalProcedure<IntSet>() {
+ QueryCache.runnerSuperTypes(graph, i, parent, null, new InternalProcedure<IntSet>() {
@Override
public void execute(ReadGraphImpl graph, IntSet types) throws DatabaseException {
types.forEach(addToResult);
dec(graph);
}
-
- @Override
- public void exception(ReadGraphImpl graph, Throwable t) throws DatabaseException {
- procedure.exception(graph, t);
+
+ @Override
+ public void exception(ReadGraphImpl graph, Throwable t) throws DatabaseException {
+ procedure.exception(graph, t);
dec(graph);
- }
+ }
});
-
+
}
@Override
public void finished(ReadGraphImpl graph) throws DatabaseException {
dec(graph);
}
-
- };
-
+
+ };
+
SyncIntProcedure inheritsProcedure = new SyncIntProcedure() {
-
+
@Override
public void run(ReadGraphImpl graph) throws DatabaseException {
- int current = finishes.addAndGet(1);
- if(current == 3) {
- if(entry != null) entry.addOrSet(graph, result, processor);
+ int current = finishes.addAndGet(1);
+ if (current == 3) {
procedure.execute(graph, result);
- }
-
+ }
+
}
-
+
@Override
public void execute(ReadGraphImpl graph, int i) throws DatabaseException {
-
+
inc();
- QueryCache.runnerTypes(graph, i, entry, null, new InternalProcedure<IntSet>() {
+ QueryCache.runnerTypes(graph, i, parent, null, new InternalProcedure<IntSet>() {
@Override
public void execute(ReadGraphImpl graph, IntSet types) throws DatabaseException {
types.forEach(addToResult);
dec(graph);
}
-
- @Override
- public void exception(ReadGraphImpl graph, Throwable t) throws DatabaseException {
- procedure.exception(graph, t);
+
+ @Override
+ public void exception(ReadGraphImpl graph, Throwable t) throws DatabaseException {
+ procedure.exception(graph, t);
dec(graph);
- }
+ }
});
-
+
}
@Override
dec(graph);
}
-
- };
+
+ };
SyncIntProcedure subrelationOfProcedure = new SyncIntProcedure() {
@Override
public void run(ReadGraphImpl graph) throws DatabaseException {
- int current = finishes.addAndGet(1);
- if(current == 3) {
- if(entry != null) entry.addOrSet(graph, result, processor);
+ int current = finishes.addAndGet(1);
+ if (current == 3) {
procedure.execute(graph, result);
- }
-
+ }
+
}
-
+
@Override
public void execute(ReadGraphImpl graph, int i) throws DatabaseException {
-
+
inc();
-
- QueryCache.runnerTypes(graph, i, entry, null, new InternalProcedure<IntSet>() {
+
+ QueryCache.runnerTypes(graph, i, parent, null, new InternalProcedure<IntSet>() {
@Override
public void execute(ReadGraphImpl graph, IntSet types) throws DatabaseException {
types.forEach(addToResult);
dec(graph);
-
+
}
-
- @Override
- public void exception(ReadGraphImpl graph, Throwable t) throws DatabaseException {
- procedure.exception(graph, t);
+
+ @Override
+ public void exception(ReadGraphImpl graph, Throwable t) throws DatabaseException {
+ procedure.exception(graph, t);
dec(graph);
- }
+ }
});
-
+
}
@Override
public void finished(ReadGraphImpl graph) throws DatabaseException {
-
+
dec(graph);
}
-
- };
-
+
+ };
+
processor.querySupport.getObjects(graph, id, instanceOf, instanceOfProcedure);
instanceOfProcedure.finished(graph);
processor.querySupport.getObjects(graph, id, inherits, inheritsProcedure);
inheritsProcedure.finished(graph);
processor.querySupport.getObjects(graph, id, subrelationOf, subrelationOfProcedure);
subrelationOfProcedure.finished(graph);
-
- if(entry != null) entry.finish();
-
- }
-
- @Override
- public String toString() {
- return "Types[" + id + "]";
- }
-
- private void addOrSet(ReadGraphImpl graph, final IntSet value, QueryProcessor provider) {
-
- assert(!isReady());
- setResult(value);
-
}
-
- void finish() {
- IntSet result = getResult();
- result.trim();
- setReady();
-
- }
-
- @Override
- final public Object performFromCache(ReadGraphImpl graph, InternalProcedure<IntSet> procedure) throws DatabaseException {
-
- assert(isReady());
-
- if(handleException(graph, procedure)) return EXCEPTED;
-
- IntSet result = getResult();
-
- procedure.execute(graph, result);
-
- return result;
-
- }
-
@Override
- public void recompute(ReadGraphImpl graph) throws DatabaseException {
-
- compute(graph, new InternalProcedure<IntSet>() {
-
- @Override
- public void execute(ReadGraphImpl graph, IntSet result) {
- }
-
- @Override
- public void exception(ReadGraphImpl graph, Throwable t) {
- new Error("Error in recompute.", t).printStackTrace();
- }
-
- });
-
+ public String toString() {
+ return "Types[" + id + "]";
}
- @Override
- boolean isImmutable(ReadGraphImpl graph) {
- return graph.processor.isImmutable(id);
- }
-
}
import org.simantics.db.impl.graph.ReadGraphImpl;
import org.simantics.db.impl.procedure.InternalProcedure;
-public class URIToResource extends StringQuery<InternalProcedure<Integer>> {
+public class URIToResource extends StringQuery<InternalProcedure<Integer>> implements InternalProcedure<Integer> {
URIToResource(final String id) {
super(id);
return getResult();
}
- static void computeForEach(ReadGraphImpl graph, String id, final URIToResource entry, final InternalProcedure<Integer> procedure) throws DatabaseException {
+ static void computeForEach(ReadGraphImpl graph, String id, final URIToResource entry, final InternalProcedure<Integer> procedure_) throws DatabaseException {
+
+ InternalProcedure<Integer> procedure = entry != null ? entry : procedure_;
if("http://".equals(id) || "http:/".equals(id)) {
QueryProcessor processor = graph.processor;
- if(entry != null) entry.addOrSet(graph, processor, processor.getRootLibrary());
procedure.execute(graph, processor.getRootLibrary());
} else {
final String[] parts = URIStringUtils.splitURI(id);
if (parts != null) {
- //Integer parentId = QueryCache.resultURIToResource(graph, parts[0], entry, null);
-
QueryCache.runnerURIToResource(graph, parts[0], entry, null, new InternalProcedure<Integer>() {
@Override
ObjectResourceIdMap<String> map = QueryCache.resultChildMap(graph, parentId, entry, null);
assert(map != null);
-// if(map == null) {
-// throw new DatabaseException("Internal Error, contact application support.");
-// if(entry != null) entry.except(e);
-// procedure.exception(graph, e);
-//// procedure.execute(graph, 0);
-//// if(entry != null) entry.addOrSet(graph, graph.processor, 0);
-// } else {
- int result = map.getId(URIStringUtils.unescape(parts[1]));
- if(result == 0) {
- ResourceNotFoundException e = new ResourceNotFoundException("No resource for URI: " + id);
- if(entry != null) entry.except(e);
- procedure.exception(graph, e);
- } else {
- if(entry != null) entry.addOrSet(graph, graph.processor, result);
- procedure.execute(graph, result);
- }
-// }
-
- // TODO Auto-generated method stub
-
+ int result = map.getId(URIStringUtils.unescape(parts[1]));
+ if (result == 0) {
+ ResourceNotFoundException e = new ResourceNotFoundException("No resource for URI: " + id);
+ procedure.exception(graph, e);
+ } else {
+ procedure.execute(graph, result);
+ }
}
@Override
public void exception(ReadGraphImpl graph, Throwable throwable) throws DatabaseException {
- if(entry != null) entry.except(throwable);
procedure.exception(graph, throwable);
}
} else {
-
ResourceNotFoundException e = new ResourceNotFoundException("No resource for URI: " + id);
- if(entry != null) entry.except(e);
- procedure.exception(graph, e);
-
+ procedure.exception(graph, e);
}
}
+ if(entry != null) entry.performFromCache(graph, procedure_);
+
}
- public void addOrSet(ReadGraphImpl graph, QueryProcessor provider, Integer result) {
+ public void addOrSet(Integer result) {
assert(isPending());
});
}
+
+ @Override
+ public void execute(ReadGraphImpl graph, Integer result) throws DatabaseException {
+ synchronized(this) {
+ setResult(result);
+ setReady();
+ }
+ }
+
+ @Override
+ public void exception(ReadGraphImpl graph, Throwable throwable) throws DatabaseException {
+ except(throwable);
+ }
}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.db.impl.query;
+
+import org.simantics.db.common.exception.DebugException;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.impl.graph.ReadGraphImpl;
+import org.simantics.db.impl.procedure.InternalProcedure;
+
+abstract public class UnaryQueryP<R> extends UnaryQuery<InternalProcedure<R>> implements InternalProcedure<R> {
+
+ public UnaryQueryP(int r) {
+ super(r);
+ }
+
+ abstract public void compute(ReadGraphImpl graph, InternalProcedure<R> procedure) throws DatabaseException;
+
+ @Override
+ final public void recompute(ReadGraphImpl graph) throws DatabaseException {
+
+ compute(graph, new InternalProcedure<R>() {
+
+ @Override
+ public void execute(ReadGraphImpl graph, R result) {
+ }
+
+ @Override
+ public void exception(ReadGraphImpl graph, Throwable t) {
+ if (DebugException.DEBUG)
+ new DebugException(t).printStackTrace();
+ throw new Error("Error in recompute.", t);
+ }
+
+ });
+
+ }
+
+ @Override
+ final public Object performFromCache(ReadGraphImpl graph, InternalProcedure<R> procedure)
+ throws DatabaseException {
+
+ if (handleException(graph, procedure))
+ return (Throwable) statusOrException;
+
+ procedure.execute(graph, (R)getResult());
+
+ return result;
+
+ }
+
+ @Override
+ final public void execute(ReadGraphImpl graph, R result) throws DatabaseException {
+ setResult(result);
+ setReady();
+ }
+
+ @Override
+ final public void exception(ReadGraphImpl graph, Throwable throwable) throws DatabaseException {
+ except(throwable);
+ }
+
+ @Override
+ final boolean isImmutable(ReadGraphImpl graph) {
+ return graph.processor.isImmutable(id);
+ }
+
+}
import org.simantics.db.impl.graph.ReadGraphImpl;
import org.simantics.db.impl.procedure.InternalProcedure;
-final public class ValueQuery extends UnaryQuery<InternalProcedure<byte[]>> {
+final public class ValueQuery extends UnaryQueryP<byte[]> {
ValueQuery(final int resource) {
super(resource);
final public void removeEntry(QueryProcessor provider) {
provider.cache.remove(this);
}
+
+ @Override
+ public void compute(ReadGraphImpl graph, InternalProcedure<byte[]> procedure) throws DatabaseException {
+ computeForEach(graph, id, this, procedure);
+ }
- public static byte[] computeForEach(ReadGraphImpl graph, final int r, final ValueQuery entry, final InternalProcedure<byte[]> procedure) throws DatabaseException {
+ public static byte[] computeForEach(ReadGraphImpl graph, final int r, final ValueQuery entry, final InternalProcedure<byte[]> procedure_) throws DatabaseException {
+
+ InternalProcedure<byte[]> procedure = entry != null ? entry : procedure_;
graph.ensureLoaded(r);
byte[] value = graph.getValue(r);
- if(entry != null) {
- entry.setResult(value);
- entry.setReady();
- }
- if(procedure != null) {
- procedure.execute(graph, value);
- }
+ if(procedure != null) procedure.execute(graph, value);
+
+ if(entry != null && procedure_ != null) entry.performFromCache(graph, procedure_);
return value;
}
-
-// public Object compute(ReadGraphImpl graph, final InternalProcedure<byte[]> procedure) throws DatabaseException {
-// return computeForEach(graph, id, this, procedure);
-// }
@Override
public String toString() {
return "Value[" + id + "]";
}
-
- @Override
- public Object performFromCache(ReadGraphImpl graph, InternalProcedure<byte[]> procedure) throws DatabaseException {
- return computeForEach(graph, id, this, procedure);
- }
-
- @Override
- public void recompute(ReadGraphImpl graph) throws DatabaseException {
-
- computeForEach(graph, id, this, new InternalProcedure<byte[]>() {
-
- @Override
- public void execute(ReadGraphImpl graph, byte[] result) {
- }
-
- @Override
- public void exception(ReadGraphImpl graph, Throwable t) {
- throw new Error("Error in recompute.", t);
- }
-
- });
-
- }
-
- @Override
- boolean isImmutable(ReadGraphImpl graph) {
- return graph.processor.isImmutable(id);
- }
}
System.err.println("value " + cc.getValueIndex()[i] + " changed.");
}
}
- final void refreshImportance(ClusterImpl c) {
+ final synchronized void refreshImportance(ClusterImpl c) {
if (c.isWriteOnly())
return;