]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/ReadEntry.java
Trying to wait for procedures
[simantics/platform.git] / bundles / org.simantics.db.impl / src / org / simantics / db / impl / query / ReadEntry.java
index 61e934fe9cc59f7458aa8f247e8652c280006a89..1ceca45a5a0cec7371f632941a13b3c1610fc60a 100644 (file)
@@ -101,29 +101,49 @@ public final class ReadEntry<T> extends CacheEntryBase<AsyncProcedure<T>> implem
         AsyncProcedure<T> procedure = entry != null ? entry : procedure_;
 
         ReadGraphImpl queryGraph = graph.withParent(entry);
+        queryGraph.asyncBarrier.inc();
 
+        ReadGraphImpl executeGraph = graph.withParent(graph.parent);
+        executeGraph.asyncBarrier.inc();
+        
         try {
 
+            // This throws
             T result = request.perform(queryGraph);
-            if(procedure != null) procedure.execute(graph, result);
+
+            if(procedure != null) procedure.execute(executeGraph, result);
             return (T)result;
 
         } catch (DatabaseException e) {
 
-            if(procedure != null) procedure.exception(graph, e);
+            if(procedure != null) procedure.exception(executeGraph, e);
             throw e;
 
         } catch (Throwable t) {
 
             DatabaseException dbe = new DatabaseException(t);
-            if(procedure != null) procedure.exception(graph, dbe);
+            if(procedure != null) procedure.exception(executeGraph, dbe);
             throw dbe;
 
         } finally {
 
-            if (entry != null)
-                entry.performFromCache(queryGraph, procedure_);
+            queryGraph.asyncBarrier.dec();
+
+            try {
+            
+                if (entry != null) {
+                    // This also throws so must dec barrier finally
+                    entry.performFromCache(executeGraph, procedure_);
+                }
+            
+            } finally {
+                executeGraph.asyncBarrier.dec();
+                executeGraph.asyncBarrier.waitBarrier(procedure, executeGraph);
 
+            }
+                
         }
 
     }