]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/SuperTypes.java
Trying to remove synchronization problems
[simantics/platform.git] / bundles / org.simantics.db.impl / src / org / simantics / db / impl / query / SuperTypes.java
index a01c84699ce3181febae84ac376f7f93bf62e234..c7efade251d1f184968a368490d6a6938cbac031 100644 (file)
@@ -14,38 +14,29 @@ package org.simantics.db.impl.query;
 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 gnu.trove.procedure.TIntProcedure;
 
-final public class SuperTypes extends UnaryQuery<InternalProcedure<IntSet>> {
+final public class SuperTypes extends UnaryQueryP<IntSet> {
        
     SuperTypes(final int resource) {
         super(resource);
     }
-    
-//    final public static SuperTypes queryEach(ReadGraphImpl graph, final int r, final QueryProcessor provider, final CacheEntry parent, final ListenerBase listener, final InternalProcedure<IntSet> procedure) throws DatabaseException {
-//        return QueryCache.runnerSuperTypes(graph, r, parent, listener, procedure);
-//    }
        
        @Override
        final public void removeEntry(QueryProcessor provider) {
                provider.cache.remove(this);
        }
 
-       //@Override
-       public Object compute(ReadGraphImpl graph, final InternalProcedure<IntSet> procedure) throws DatabaseException {
-               return computeForEach(graph, id, this, procedure);
-       }
-       
-       private static void addOrSet(ReadGraphImpl graph, SuperTypes entry, IntSet value) {
-               if(entry != null) {
-                       entry.addOrSet(graph, value, graph.processor);
-               }
+       @Override
+       public void compute(ReadGraphImpl graph, final InternalProcedure<IntSet> procedure) throws DatabaseException {
+               computeForEach(graph, id, this, procedure);
        }
        
-       public static Object computeForEach(ReadGraphImpl graph, int r, SuperTypes entry, final InternalProcedure<IntSet> procedure) throws DatabaseException {
+       public static Object computeForEach(ReadGraphImpl graph, int r, SuperTypes entry, final InternalProcedure<IntSet> procedure_) throws DatabaseException {
 
+           InternalProcedure<IntSet> procedure = entry != null ? entry : procedure_;
+           
                QueryProcessor provider = graph.processor;
 
         final int inherits = provider.getInherits();
@@ -66,17 +57,12 @@ final public class SuperTypes extends UnaryQuery<InternalProcedure<IntSet>> {
             
             @Override
             public void run(ReadGraphImpl graph) throws DatabaseException {
-
-                addOrSet(graph, entry, result);
                 procedure.execute(graph, result);
-                
             }
             
             @Override
             public void execute(ReadGraphImpl graph, final int i) throws DatabaseException {
                 
-//             assert(graph.parent == parent);
-               
                synchronized(result) {
                        result.add(i);
                }
@@ -109,65 +95,16 @@ final public class SuperTypes extends UnaryQuery<InternalProcedure<IntSet>> {
             
         });
         
-        return result;
-        
-    }
-    
-    @Override
-    public String toString() {
-       return "SuperTypes2[" + 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();
-            }
-
-        });
-        
+    public String toString() {
+       return "SuperTypes[" + id + "]";
     }
     
-    @Override
-    boolean isImmutable(ReadGraphImpl graph) {
-       return graph.processor.isImmutable(id);
-    }
     
 }