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