]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/TypeHierarchy.java
Trying to remove synchronization problems
[simantics/platform.git] / bundles / org.simantics.db.impl / src / org / simantics / db / impl / query / TypeHierarchy.java
index ad4581bb6a3e6045c877193dd9aecf8e6c316fd7..cc8ee07ded8fc2937bfa43926c6cb9e4c2b0b254 100644 (file)
@@ -18,7 +18,7 @@ import org.simantics.db.procedure.ListenerBase;
 
 import gnu.trove.procedure.TIntProcedure;
 
-final public class TypeHierarchy extends UnaryQuery<InternalProcedure<IntSet>> {
+final public class TypeHierarchy extends UnaryQueryP<IntSet> {
     
     TypeHierarchy(final int resource) {
         super(resource);
@@ -33,8 +33,14 @@ final public class TypeHierarchy extends UnaryQuery<InternalProcedure<IntSet>> {
                provider.cache.remove(this);
        }
 
-       //@Override
-       public IntSet compute(ReadGraphImpl graph, final InternalProcedure<IntSet> procedure) throws DatabaseException {
+       @Override
+       public void compute(final ReadGraphImpl graph, final InternalProcedure<IntSet> procedure) throws DatabaseException {
+           computeForEach(graph, id, this, procedure);
+       }
+
+       public static IntSet computeForEach(ReadGraphImpl graph, int id, TypeHierarchy entry, final InternalProcedure<IntSet> procedure_) throws DatabaseException {
+           
+          InternalProcedure<IntSet> procedure = entry != null ? entry : procedure_;
 
                QueryProcessor processor = graph.processor;
                
@@ -48,15 +54,12 @@ final public class TypeHierarchy extends UnaryQuery<InternalProcedure<IntSet>> {
             }
         };
         
-        QueryCache.runnerSuperTypes(graph, id, TypeHierarchy.this, null, new InternalProcedure<IntSet>() {
+        QueryCache.runnerSuperTypes(graph, id, entry, null, new InternalProcedure<IntSet>() {
 
                @Override
                public void execute(ReadGraphImpl graph, IntSet types) throws DatabaseException {
-
                        types.forEach(addToResult);
-                       addOrSet(graph, result, processor);
                        procedure.execute(graph, result); 
-
                }
 
                @Override
@@ -66,65 +69,15 @@ final public class TypeHierarchy extends UnaryQuery<InternalProcedure<IntSet>> {
 
         });
         
-        return result;
-                        
-    }
-    
-    @Override
-    public String toString() {
-       return "TypeHierarchy[" + id + "]";
-    }
-
-    private void addOrSet(ReadGraphImpl graph, final IntSet value, QueryProcessor provider) {
-       
-        assert(!isReady());
-
-        synchronized(this) {
-        
-            value.trim();
-            setResult(value);
-            setReady();
-        
-        }
-        
-    }
-
-    @Override
-    public Object performFromCache(ReadGraphImpl graph, InternalProcedure<IntSet> procedure) throws DatabaseException {
-       
-       assert(isReady());
-
-       if(handleException(graph, procedure)) return null;
-       
-       IntSet result = getResult();
-       
-        procedure.execute(graph, result);
+        if(entry != null) entry.performFromCache(graph, procedure_);
         
         return result;
-        
-    }
-    
-    @Override
-    public void recompute(ReadGraphImpl graph) throws DatabaseException {
-    
-        compute(graph, new InternalProcedure<IntSet>() {
-
-               @Override
-               public void execute(ReadGraphImpl graph, IntSet result) {
-               }
-
-            @Override
-            public void exception(ReadGraphImpl graph, Throwable t) {
-                new Error("Error in recompute.", t).printStackTrace();
-            }
 
-        });
-        
     }
     
     @Override
-    boolean isImmutable(ReadGraphImpl graph) {
-       return graph.processor.isImmutable(id);
+    public String toString() {
+       return "TypeHierarchy[" + id + "]";
     }
 
 }