]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/ExternalReadEntry.java
Fixed multiple issues causing dangling references to discarded queries
[simantics/platform.git] / bundles / org.simantics.db.impl / src / org / simantics / db / impl / query / ExternalReadEntry.java
index ac07ad7eda1acb4e3f51884b35b4b5ff99ad8445..2980b9b15f72e9a54b00a96fe06a397ef60b59b6 100644 (file)
@@ -27,18 +27,18 @@ final public class ExternalReadEntry<T> extends CacheEntryBase<AsyncProcedure<T>
 
     final LinkedList<T> items = new LinkedList<T>();
 
-    protected ExternalRead<T> request;
-    protected ReadGraphImpl graph;
+    protected ExternalRead<T> id;
+    protected QueryProcessor processor;
     protected boolean registered = false;
 
     @Override
     int makeHash() {
-       return request.hashCode();
+       return id.hashCode();
     }
     
     @Override
     public Object getOriginalRequest() {
-        return request;
+        return id;
     }
     
     @Override
@@ -47,14 +47,14 @@ final public class ExternalReadEntry<T> extends CacheEntryBase<AsyncProcedure<T>
     
     @Override
     public void discard() {
-        request.unregistered();
-        request = null;
-        graph = null;
+        id.unregistered();
+        id = null;
+        processor = null;
         super.discard();
     }
 
     @Override
-    public void setPending() {
+    public void setPending(QuerySupport querySupport) {
         //if(result != NO_RESULT) {
             //new Exception("result = " + result).printStackTrace();
         //}
@@ -64,8 +64,8 @@ final public class ExternalReadEntry<T> extends CacheEntryBase<AsyncProcedure<T>
     
     public ExternalReadEntry(ExternalRead<T> request, ReadGraphImpl graph) {
         assert request != null;
-        this.request = request;
-        this.graph = graph;
+        this.id = request;
+        this.processor = graph.processor;
     }
     
     @Override
@@ -119,7 +119,7 @@ final public class ExternalReadEntry<T> extends CacheEntryBase<AsyncProcedure<T>
                                        }
                                        // Reschedule
                                        if(!items.isEmpty()) {
-                                               graph.processor.updatePrimitive(request);
+                                               graph.processor.updatePrimitive(id);
                                        }
 
                                }
@@ -138,8 +138,8 @@ final public class ExternalReadEntry<T> extends CacheEntryBase<AsyncProcedure<T>
                        
                        @Override
                        public String toString() {
-                               if(request == null) return "DISCARDED ExternalRead";
-                               else return request.toString();
+                               if(id == null) return "DISCARDED ExternalRead";
+                               else return id.toString();
                        }
                
         };
@@ -148,8 +148,8 @@ final public class ExternalReadEntry<T> extends CacheEntryBase<AsyncProcedure<T>
 
        @Override
        public String toString() {
-               if(request == null) return "DISCARDED ExternalRead " + System.identityHashCode(this);
-               else return request.toString() + " " + + System.identityHashCode(this);
+               if(id == null) return "DISCARDED ExternalRead " + System.identityHashCode(this);
+               else return id.toString() + " " + + System.identityHashCode(this);
        }
 
     @Override
@@ -180,14 +180,14 @@ final public class ExternalReadEntry<T> extends CacheEntryBase<AsyncProcedure<T>
        
                try {
                        
-                       ReadGraphImpl queryGraph = graph.withParent(this);
+                       ReadGraphImpl queryGraph = graph.withParent(this, null, true);
 
                        if(!registered) {
-                               request.register(graph, this);
+                               id.register(graph, this);
                                registered = true;
                        }
                        
-                       queryGraph.asyncBarrier.waitBarrier(request, graph);
+                       queryGraph.asyncBarrier.waitBarrier(id, graph);
 
                } catch (Throwable t) {
 
@@ -213,7 +213,7 @@ final public class ExternalReadEntry<T> extends CacheEntryBase<AsyncProcedure<T>
 
                synchronized(items) {
                        items.addLast(result);
-                               graph.processor.updatePrimitive(request);
+                               processor.updatePrimitive(id);
                        // TODO: implement flags/logic in ExternalRead to state that all but the latest request result can be evaporated
                        // In some cases where data is produced really fast this might be necessary but currently this queueing will do.
                }
@@ -229,7 +229,12 @@ final public class ExternalReadEntry<T> extends CacheEntryBase<AsyncProcedure<T>
 
        @Override
        public boolean isDisposed() {
-               return registered && (isDiscarded() || !graph.processor.isBound(this));
+               return registered && (isDiscarded() || !processor.isBound(this));
        }
-    
+
+    @Override
+    public String classId() {
+        return null;
+    }
+
 }