]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/ValueQuery.java
Trying to remove synchronization problems
[simantics/platform.git] / bundles / org.simantics.db.impl / src / org / simantics / db / impl / query / ValueQuery.java
index b96e13d42fc14d177779ef021564dfb1fdd22fed..e533ee30f4ee4f521316b56981c8a13f68c4c6af 100644 (file)
@@ -15,7 +15,7 @@ import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.impl.graph.ReadGraphImpl;
 import org.simantics.db.impl.procedure.InternalProcedure;
 
-final public class ValueQuery extends UnaryQuery<InternalProcedure<byte[]>> {
+final public class ValueQuery extends UnaryQueryP<byte[]> {
     
     ValueQuery(final int resource) {
         super(resource);
@@ -25,59 +25,30 @@ final public class ValueQuery extends UnaryQuery<InternalProcedure<byte[]>> {
        final public void removeEntry(QueryProcessor provider) {
                provider.cache.remove(this);
        }
+       
+       @Override
+       public void compute(ReadGraphImpl graph, InternalProcedure<byte[]> procedure) throws DatabaseException {
+           computeForEach(graph, id, this, procedure);
+       }
                
-       public static byte[] computeForEach(ReadGraphImpl graph, final int r, final ValueQuery entry, final InternalProcedure<byte[]> procedure) throws DatabaseException {
+       public static byte[] computeForEach(ReadGraphImpl graph, final int r, final ValueQuery entry, final InternalProcedure<byte[]> procedure_) throws DatabaseException {
+           
+           InternalProcedure<byte[]> procedure = entry != null ? entry : procedure_;
 
                graph.ensureLoaded(r);
                
                byte[] value = graph.getValue(r);
-               if(entry != null) {
-                       entry.setResult(value);
-                       entry.setReady();
-               }
-               if(procedure != null) {
-                       procedure.execute(graph, value);
-               }
+               if(procedure != null) procedure.execute(graph, value);
+               
+               if(entry != null && procedure_ != null) entry.performFromCache(graph, procedure_);
                
                return value;
                
        }
-
-//     public Object compute(ReadGraphImpl graph, final InternalProcedure<byte[]> procedure) throws DatabaseException {
-//             return computeForEach(graph, id, this, procedure);
-//    }
     
     @Override
     public String toString() {
        return "Value[" + id + "]";
     }
-
-    @Override
-    public Object performFromCache(ReadGraphImpl graph, InternalProcedure<byte[]> procedure) throws DatabaseException {
-       return computeForEach(graph, id, this, procedure);
-    }
-    
-    @Override
-    public void recompute(ReadGraphImpl graph) throws DatabaseException {
-       
-       computeForEach(graph, id, this, new InternalProcedure<byte[]>() {
-
-            @Override
-            public void execute(ReadGraphImpl graph, byte[] result) {
-            }
-                       
-                       @Override
-                       public void exception(ReadGraphImpl graph, Throwable t) {
-                               throw new Error("Error in recompute.", t);
-            }
-
-        });
-        
-    }
-    
-    @Override
-    boolean isImmutable(ReadGraphImpl graph) {
-       return graph.processor.isImmutable(id);
-    }
     
 }