X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.db.impl%2Fsrc%2Forg%2Fsimantics%2Fdb%2Fimpl%2Fquery%2FOrderedSet.java;h=69ac07edd5a927700ea8354dca6725ca3e90d6e2;hb=de8b6e194da6d56c410101d9c72763078b0e8717;hp=9e7bb5c92ee39778b877f428a0aa336fe629db61;hpb=880a8a4927805afbbf47005a807cef3f39406866;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/OrderedSet.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/OrderedSet.java index 9e7bb5c92..69ac07edd 100644 --- a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/OrderedSet.java +++ b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/OrderedSet.java @@ -17,10 +17,8 @@ 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.IntProcedureAdapter; -import org.simantics.db.impl.procedure.InternalProcedure; -import org.simantics.db.procedure.ListenerBase; -final public class OrderedSet extends CollectionUnaryQuery { +final public class OrderedSet extends CollectionUnaryQuery { public OrderedSet(final int r) { super(r); @@ -31,7 +29,7 @@ final public class OrderedSet extends CollectionUnaryQuery { 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; @@ -39,12 +37,11 @@ final public class OrderedSet extends CollectionUnaryQuery { 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); @@ -63,7 +60,6 @@ final public class OrderedSet extends CollectionUnaryQuery { }); if(res.get() == orderedSet) { - if(entry != null) entry.finish(graph, processor); procedure.finished(graph); } @@ -72,85 +68,26 @@ final public class OrderedSet extends CollectionUnaryQuery { } @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); - } - - }); - - } }