]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/DirectObjects.java
Trying to remove synchronization problems
[simantics/platform.git] / bundles / org.simantics.db.impl / src / org / simantics / db / impl / query / DirectObjects.java
index 117056410bfacbbe1492ea3407ba56472a3ff369..8f2c7e0d8bb1ea814e6454b58dd726f57d26ef59 100644 (file)
  *******************************************************************************/
 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);
     }
-       
-}
 
+}