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=115a4a5a1509db803a88140b038d9f475b1e3305;hb=68ce0966a57f5153b133c6283fdbae10f683b745;hp=edc32454929542ab76a0f4a51155559a52b22324;hpb=a1dd54cd8e3595e66c83ad0e2d935470a3567481;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 edc324549..115a4a5a1 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 @@ -20,7 +20,7 @@ import org.simantics.db.request.Read; import org.simantics.db.request.ReadExt; import org.simantics.db.request.RequestFlags; -final public class ReadEntry extends CacheEntryBase { +final public class ReadEntry extends CacheEntryBase> { protected Read request; @@ -44,26 +44,16 @@ final public class ReadEntry extends CacheEntryBase { setResult(null); } - final public void addOrSet(AsyncReadGraph graph, Object item) { + final public Object addOrSet(AsyncReadGraph graph, Object result) { + +// System.err.println("addOrSet " + request + " " + Thread.currentThread() + " " + result); assert(assertPending()); -// ArrayList, AsyncBarrier>> p = null; - - synchronized(this) { - - setResult(item); - setReady(); -// p = procs; -// procs = null; - - } - -// if(p != null) -// for(Pair, AsyncBarrier> proc : p) { -// proc.first.execute(graph, (T)item); -// proc.second.dec(); -// } + setResult(result); + setReady(); + + return result; } @@ -73,17 +63,10 @@ final public class ReadEntry extends CacheEntryBase { return new Query() { @Override - public void recompute(ReadGraphImpl graph_, Object provider, CacheEntry entry) { - - QueryProcessor qp = (QueryProcessor)provider; - - WriteGraphImpl write = qp.getCore().getSession().getService(WriteGraphImpl.class); + public void recompute(ReadGraphImpl graph) { - ReadGraphImpl graph = write.newSync(entry); - try { - entry.setPending(); T result = request.perform(graph); addOrSet(graph, result); @@ -97,7 +80,7 @@ final public class ReadEntry extends CacheEntryBase { @Override public void removeEntry(QueryProcessor processor) { - processor.cache.readMap.remove(request); + processor.cache.remove(ReadEntry.this); } @Override @@ -119,7 +102,56 @@ final public class ReadEntry extends CacheEntryBase { } - public Object performFromCache(ReadGraphImpl graph, Object provider, Object procedure) { + //@Override + public Object compute(ReadGraphImpl graph, AsyncProcedure procedure) throws DatabaseException { + + ReadGraphImpl queryGraph = graph.withParent(this); + + try { + + addOrSet(queryGraph, request.perform(queryGraph)); + return get(queryGraph, procedure); + + } catch (DatabaseException e) { + + except(e); + return get(graph, procedure); + + } catch (Throwable t) { + + except(new DatabaseException(t)); + return get(graph, procedure); + + } + + } + + public static void computeForEach(ReadGraphImpl graph, Read request, ReadEntry entry, AsyncProcedure procedure) throws DatabaseException { + + ReadGraphImpl queryGraph = entry != null ? graph.withParent(entry) : graph; + + try { + + T result = request.perform(queryGraph); + if(entry != null) entry.addOrSet(queryGraph, result); + procedure.execute(graph, result); + + } catch (DatabaseException e) { + + if(entry != null) entry.except(e); + procedure.exception(graph, e); + + } catch (Throwable t) { + + DatabaseException dbe = new DatabaseException(t); + if(entry != null) entry.except(dbe); + procedure.exception(graph, dbe); + + } + + } + + public Object performFromCache(ReadGraphImpl graph, AsyncProcedure procedure) { AsyncProcedure proc = (AsyncProcedure)procedure; @@ -149,8 +181,8 @@ final public class ReadEntry extends CacheEntryBase { else return request.toString() + " - " + statusOrException; } - public Object get(ReadGraphImpl graph, QueryProcessor processor, Object procedure) throws DatabaseException { - if(procedure != null) performFromCache(graph, processor, procedure); + public Object get(ReadGraphImpl graph, AsyncProcedure procedure) throws DatabaseException { + if(procedure != null) performFromCache(graph, procedure); checkAndThrow(); return getResult(); }