]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/OrderedSet.java
Trying to remove synchronization problems
[simantics/platform.git] / bundles / org.simantics.db.impl / src / org / simantics / db / impl / query / OrderedSet.java
index 9e7bb5c92ee39778b877f428a0aa336fe629db61..69ac07edd5a927700ea8354dca6725ca3e90d6e2 100644 (file)
@@ -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<IntProcedure> {
+final public class OrderedSet extends CollectionUnaryQuery {
        
        public OrderedSet(final int r) {
         super(r);
@@ -31,7 +29,7 @@ final public class OrderedSet extends CollectionUnaryQuery<IntProcedure> {
         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<IntProcedure> {
                
                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<IntProcedure> {
                });
 
                if(res.get() == orderedSet) {
-                       if(entry != null) entry.finish(graph, processor);
                        procedure.finished(graph);
                }
                
@@ -72,85 +68,26 @@ final public class OrderedSet extends CollectionUnaryQuery<IntProcedure> {
        }
        
     @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);
-            }
-
-        });
-        
-    }
     
 }