X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.db.impl%2Fsrc%2Forg%2Fsimantics%2Fdb%2Fimpl%2Fquery%2FAsyncReadEntry.java;h=08f0ad8b5f689e189348b1af64a46e2d2a97c8b7;hb=d0e8f57df83c175bac2098412ee71646fb9ff0e9;hp=767a82bd5644e8759a282b8820c49b570a8fdd60;hpb=ad18bf76b19bec530bc68c6041ab5fb245b8ee4d;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/AsyncReadEntry.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/AsyncReadEntry.java index 767a82bd5..08f0ad8b5 100644 --- a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/AsyncReadEntry.java +++ b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/AsyncReadEntry.java @@ -45,6 +45,8 @@ final public class AsyncReadEntry extends CacheEntryBase> { final public void addOrSet(AsyncReadGraph graph, Object item) { +// System.err.println("addOrSet " + request + " " + Thread.currentThread() + " " + item); + assert(isPending()); synchronized(this) { @@ -142,11 +144,87 @@ final public class AsyncReadEntry extends CacheEntryBase> { } - @Override + //@Override public Object compute(ReadGraphImpl graph, AsyncProcedure procedure) throws DatabaseException { - return graph.processor.cache.performQuery(graph, request, this, procedure); + + ReadGraphImpl queryGraph = graph.withParent(this); + + request.perform(queryGraph, new AsyncProcedure() { + + @Override + public void execute(AsyncReadGraph returnGraph, T result) { + ReadGraphImpl impl = (ReadGraphImpl)returnGraph; + AsyncReadEntry.this.addOrSet(graph, result); + try { + procedure.execute(graph, result); + } catch (Throwable t) { + t.printStackTrace(); + } + // parentBarrier.dec(query); + } + + @Override + public void exception(AsyncReadGraph returnGraph, Throwable t) { + ReadGraphImpl impl = (ReadGraphImpl)returnGraph; + // AsyncReadGraph resumeGraph = finalParentGraph.newAsync(); + AsyncReadEntry.this.except(graph, t); + try { + procedure.exception(graph, t); + } catch (Throwable t2) { + t2.printStackTrace(); + } + // parentBarrier.dec(query); + } + + @Override + public String toString() { + return procedure.toString(); + } + + }); + + return getResult(); + + } + + public static void computeForEach(ReadGraphImpl parentGraph, AsyncRead request, AsyncReadEntry entry, AsyncProcedure procedure) throws DatabaseException { + + ReadGraphImpl queryGraph = parentGraph.withParent(entry); + + request.perform(queryGraph, new AsyncProcedure() { + + @Override + public void execute(AsyncReadGraph returnGraph, T result) { + ReadGraphImpl impl = (ReadGraphImpl)returnGraph; + if(entry != null) entry.addOrSet(parentGraph, result); + try { + procedure.execute(parentGraph, result); + } catch (Throwable t) { + t.printStackTrace(); + } + } + + @Override + public void exception(AsyncReadGraph returnGraph, Throwable t) { + ReadGraphImpl impl = (ReadGraphImpl)returnGraph; + if(entry != null) entry.except(parentGraph, t); + try { + procedure.exception(parentGraph, t); + } catch (Throwable t2) { + t2.printStackTrace(); + } + } + + @Override + public String toString() { + return procedure.toString(); + } + + }); + } + @Override public String toString() { if(isDiscarded()) return "DISCARDED " + request.toString();