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=8e6cbd145a78d9a1aacf3b99f20c396a789beaae;hb=ded784594eb0e1fb318fbb931135288152691cf2;hp=a9726a75d6ac4eb5df323625ffd19da9369bcb9b;hpb=4aa615b51b887cd75b558a823f0d87b3174e5f5e;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 a9726a75d..8e6cbd145 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 @@ -12,16 +12,17 @@ package org.simantics.db.impl.query; import org.simantics.db.AsyncReadGraph; +import org.simantics.db.exception.DatabaseException; import org.simantics.db.impl.DebugPolicy; import org.simantics.db.impl.graph.ReadGraphImpl; import org.simantics.db.procedure.AsyncProcedure; import org.simantics.db.request.AsyncRead; -final public class AsyncReadEntry extends CacheEntryBase { +final public class AsyncReadEntry extends CacheEntryBase> { protected AsyncRead request; - public AsyncReadEntry(AsyncRead request) { + AsyncReadEntry(AsyncRead request) { this.request = request; if(DebugPolicy.QUERY_STATE) System.out.println("[QUERY STATE]: created " + this); } @@ -39,31 +40,17 @@ final public class AsyncReadEntry extends CacheEntryBase { @Override public void discard() { super.discard(); - //request = null; setResult(null); } final public void addOrSet(AsyncReadGraph graph, Object item) { assert(isPending()); - -// ArrayList> p = null; synchronized(this) { - setResult(item); setReady(); -// p = procs; -// procs = null; - } - -// if(p != null) -// for(AsyncProcedure proc : p) { -// proc.execute(graph, (T)item); -//// proc.first.execute(graph, (T)item); -//// proc.second.dec(); -// } } @@ -71,21 +58,10 @@ final public class AsyncReadEntry extends CacheEntryBase { public void except(AsyncReadGraph graph, Throwable t) { assert(isPending()); - -// ArrayList> p = null; synchronized(this) { - except(t); -//// p = procs; -// procs = null; - } - -// if(p != null) -// for(AsyncProcedure proc : p) { -// proc.exception(graph, t); -// } } @@ -96,15 +72,11 @@ final public class AsyncReadEntry extends CacheEntryBase { return new Query() { @Override - public void recompute(ReadGraphImpl graph, Object provider, CacheEntry entry) { - - QueryProcessor qp = (QueryProcessor)provider; - - final ReadGraphImpl parentGraph = ReadGraphImpl.forRecompute(entry, qp); + public void recompute(ReadGraphImpl graph) { try { - request.perform(parentGraph , new AsyncProcedure() { + request.perform(graph , new AsyncProcedure() { @Override public void execute(AsyncReadGraph graph, T result) { @@ -126,7 +98,7 @@ final public class AsyncReadEntry extends CacheEntryBase { @Override public void removeEntry(QueryProcessor qp) { - qp.asyncReadMap.remove(request); + qp.cache.remove(AsyncReadEntry.this); } @Override @@ -145,11 +117,9 @@ final public class AsyncReadEntry extends CacheEntryBase { } - @SuppressWarnings("unchecked") - public void performFromCache(ReadGraphImpl graph, Object provider, Object procedure) { + @Override + public Object performFromCache(ReadGraphImpl graph, AsyncProcedure proc) { - AsyncProcedure proc = (AsyncProcedure)procedure; - if(isExcepted()) { try { @@ -168,8 +138,91 @@ final public class AsyncReadEntry extends CacheEntryBase { } + return getResult(); + } + @Override + public Object compute(ReadGraphImpl graph, AsyncProcedure procedure) throws DatabaseException { + + 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();