]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/Predicates.java
Trying to remove synchronization problems
[simantics/platform.git] / bundles / org.simantics.db.impl / src / org / simantics / db / impl / query / Predicates.java
index 03b17bba5cfba708064f2a9ed84b115348af8f4d..9445db03b4e048ca1488cb22f45eeaa56da9bdd1 100644 (file)
 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);
@@ -32,9 +30,9 @@ final public class Predicates extends UnaryQuery<InternalProcedure<IntSet>> {
         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 {
@@ -63,7 +61,7 @@ final public class Predicates extends UnaryQuery<InternalProcedure<IntSet>> {
             public void execute(ReadGraphImpl graph, int type) throws DatabaseException {
 
                inc();
-                QueryCache.runnerAssertedPredicates(graph, type, entry, null, proc);
+                QueryCache.runnerAssertedPredicates(graph, type, parent, null, proc);
                 
             }
             
@@ -77,13 +75,14 @@ final public class Predicates extends UnaryQuery<InternalProcedure<IntSet>> {
 
     }
 
-       //@Override
-       public Object compute(ReadGraphImpl graph, final InternalProcedure<IntSet> procedure) throws DatabaseException {
+       @Override
+       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);
                
@@ -91,16 +90,8 @@ final public class Predicates extends UnaryQuery<InternalProcedure<IntSet>> {
        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) {
@@ -108,16 +99,10 @@ final public class Predicates extends UnaryQuery<InternalProcedure<IntSet>> {
                                return true;
                        }
                });
-
-               if(entry != null) {
-                       entry.setResult(result);
-                       entry.setReady();
-               }
-               
                procedure.execute(graph, result);
-               
        }
-               
+       
+       if(entry != null) entry.performFromCache(graph, procedure_);
         
     }
     
@@ -126,61 +111,14 @@ final public class Predicates extends UnaryQuery<InternalProcedure<IntSet>> {
        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);
-    }
     
 }