X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.db.impl%2Fsrc%2Forg%2Fsimantics%2Fdb%2Fimpl%2Fquery%2FReadEntry.java;h=1ceca45a5a0cec7371f632941a13b3c1610fc60a;hb=e5a79f44f9d6ce5f38fb61c5db0d9af0a1db35a9;hp=c95242defc77a45ae859f49042a2fc1e13df4f20;hpb=0d9b90834ce56b292c00b1a39850ed842c3e4d42;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/ReadEntry.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/ReadEntry.java index c95242def..1ceca45a5 100644 --- a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/ReadEntry.java +++ b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/ReadEntry.java @@ -95,56 +95,88 @@ public final class ReadEntry extends CacheEntryBase> implem } - public static void computeForEach(ReadGraphImpl graph, Read request, ReadEntry entry, + public static T computeForEach(ReadGraphImpl graph, Read request, ReadEntry entry, AsyncProcedure procedure_) throws DatabaseException { AsyncProcedure procedure = entry != null ? entry : procedure_; - ReadGraphImpl queryGraph = entry != null ? graph.withParent(entry) : graph; + 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); - procedure.execute(graph, result); + + if(procedure != null) procedure.execute(executeGraph, result); + return (T)result; } catch (DatabaseException e) { - procedure.exception(graph, e); + if(procedure != null) procedure.exception(executeGraph, e); + throw e; } catch (Throwable t) { DatabaseException dbe = new DatabaseException(t); - procedure.exception(graph, dbe); + if(procedure != null) procedure.exception(executeGraph, dbe); + throw dbe; - } + } finally { + + 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); - if (entry != null) - entry.performFromCache(queryGraph, procedure_); + } + + + } } - public Object performFromCache(ReadGraphImpl graph, AsyncProcedure procedure) { + public Object performFromCache(ReadGraphImpl graph, AsyncProcedure procedure) throws DatabaseException { AsyncProcedure proc = (AsyncProcedure) 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