]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/DirectPredicates.java
Trying to remove synchronization problems
[simantics/platform.git] / bundles / org.simantics.db.impl / src / org / simantics / db / impl / query / DirectPredicates.java
index 63c54effe47f2e405320abe19e7a431af686bc70..bb2e1530e224f3b00626cfdea188b97b591beb64 100644 (file)
@@ -16,30 +16,26 @@ import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.impl.graph.ReadGraphImpl;
 import org.simantics.db.impl.procedure.InternalProcedure;
 
-final public class DirectPredicates extends CollectionUnaryQuery<InternalProcedure<IntSet>> {
+final public class DirectPredicates extends UnaryQueryP<IntSet> {
 
        DirectPredicates(final int resource) {
                super(resource);
        }
        
-       @Override
-       public void clearResult(QuerySupport support) {
-               // The cached result is never used
-               setResult(INVALID_RESULT);
-       }
-       
        @Override
        final public void removeEntry(QueryProcessor provider) {
                provider.cache.remove(this);
        }
 
-       //@Override
-       public Object compute(ReadGraphImpl graph, InternalProcedure<IntSet> procedure) throws DatabaseException {
-           return computeForEach(graph, id, this, procedure);
+       @Override
+       public void compute(ReadGraphImpl graph, InternalProcedure<IntSet> procedure) throws DatabaseException {
+           computeForEach(graph, id, this, procedure);
        }
        
-       public static Object computeForEach(ReadGraphImpl graph, int id, final DirectPredicates entry, final InternalProcedure<IntSet> procedure) throws DatabaseException {
+       public static Object computeForEach(ReadGraphImpl graph, int id, final DirectPredicates entry, final InternalProcedure<IntSet> procedure_) throws DatabaseException {
 
+           InternalProcedure<IntSet> procedure = entry != null ? entry : procedure_;
+           
                graph.processor.querySupport.ensureLoaded(graph, id);
                
                final IntSet list = new IntSet(graph.processor.querySupport);
@@ -61,13 +57,10 @@ final public class DirectPredicates extends CollectionUnaryQuery<InternalProcedu
                        }
 
                });
-
-               if(entry != null) {
-                   entry.setResult(list);
-                   entry.setReady();
-               }
                
                procedure.execute(graph, list);
+
+               if(entry != null) entry.performFromCache(graph, procedure_);
                
                return list;
 
@@ -78,48 +71,4 @@ final public class DirectPredicates extends CollectionUnaryQuery<InternalProcedu
                return "DirectPredicates[" + id + "]";
        }
 
-       @Override
-       public void setReady() {
-               statusOrException = READY;
-       }
-
-       @Override
-       public Object performFromCache(ReadGraphImpl graph, 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 execute(ReadGraphImpl graph, IntSet set) {
-                       }
-
-                       @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);
-    }
-
 }