]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/ReadEntry.java
Attempt to fix regressions in new code base
[simantics/platform.git] / bundles / org.simantics.db.impl / src / org / simantics / db / impl / query / ReadEntry.java
index c95242defc77a45ae859f49042a2fc1e13df4f20..61e934fe9cc59f7458aa8f247e8652c280006a89 100644 (file)
@@ -95,56 +95,68 @@ public final class ReadEntry<T> extends CacheEntryBase<AsyncProcedure<T>> implem
 
     }
 
-    public static <T> void computeForEach(ReadGraphImpl graph, Read<T> request, ReadEntry<T> entry,
+    public static <T> T computeForEach(ReadGraphImpl graph, Read<T> request, ReadEntry<T> entry,
             AsyncProcedure<T> procedure_) throws DatabaseException {
 
         AsyncProcedure<T> procedure = entry != null ? entry : procedure_;
 
-        ReadGraphImpl queryGraph = entry != null ? graph.withParent(entry) : graph;
+        ReadGraphImpl queryGraph = graph.withParent(entry);
 
         try {
 
             T result = request.perform(queryGraph);
-            procedure.execute(graph, result);
+            if(procedure != null) procedure.execute(graph, result);
+            return (T)result;
 
         } catch (DatabaseException e) {
 
-            procedure.exception(graph, e);
+            if(procedure != null) procedure.exception(graph, e);
+            throw e;
 
         } catch (Throwable t) {
 
             DatabaseException dbe = new DatabaseException(t);
-            procedure.exception(graph, dbe);
+            if(procedure != null) procedure.exception(graph, dbe);
+            throw dbe;
 
-        }
+        } finally {
+
+            if (entry != null)
+                entry.performFromCache(queryGraph, procedure_);
 
-        if (entry != null)
-            entry.performFromCache(queryGraph, procedure_);
+        }
 
     }
 
-    public Object performFromCache(ReadGraphImpl graph, AsyncProcedure<T> procedure) {
+    public Object performFromCache(ReadGraphImpl graph, AsyncProcedure<T> procedure) throws DatabaseException {
 
         AsyncProcedure<T> proc = (AsyncProcedure<T>) procedure;
 
-        if (proc != null) {
-            if (isExcepted()) {
-                try {
-                    proc.exception(graph, (Throwable) getResult());
-                } catch (Throwable t) {
-                    LOGGER.error("performFromCache proc.exception failed", t);
+        if (isExcepted()) {
+                if(proc != null) {
+                    try {
+                        proc.exception(graph, (Throwable) getResult());
+                    } catch (Throwable t) {
+                        LOGGER.error("performFromCache proc.exception failed", t);
+                    }
                 }
-            } else {
-                try {
-                    proc.execute(graph, (T) getResult());
-                } catch (Throwable t) {
-                    LOGGER.error("performFromCache proc.execute failed", t);
+                Throwable t = (Throwable) getResult();
+                if(t instanceof DatabaseException) {
+                    throw (DatabaseException)t;
+                } else {
+                    throw new DatabaseException(t);
                 }
-            }
+        } else {
+                if(proc != null) {
+                    try {
+                        proc.execute(graph, (T) getResult());
+                    } catch (Throwable t) {
+                        LOGGER.error("performFromCache proc.execute failed", t);
+                    }
+                }
+                return (T)getResult();
         }
 
-        return (T) getResult();
-
     }
 
     @Override