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 {
+ 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);
- }
}