]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/AsyncReadEntry.java
Multiple readers and variable optimization
[simantics/platform.git] / bundles / org.simantics.db.impl / src / org / simantics / db / impl / query / AsyncReadEntry.java
index 767a82bd5644e8759a282b8820c49b570a8fdd60..8e6cbd145a78d9a1aacf3b99f20c396a789beaae 100644 (file)
@@ -144,9 +144,85 @@ final public class AsyncReadEntry<T> extends CacheEntryBase<AsyncProcedure<T>> {
 
     @Override
     public Object compute(ReadGraphImpl graph, AsyncProcedure<T> procedure) throws DatabaseException {
-       return graph.processor.cache.performQuery(graph, request, this, procedure);
+
+       ReadGraphImpl queryGraph = graph.withParent(this);
+
+       request.perform(queryGraph, new AsyncProcedure<T>() {
+
+               @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 <T> void computeForEach(ReadGraphImpl parentGraph, AsyncRead<T> request, AsyncReadEntry<T> entry, AsyncProcedure<T> procedure) throws DatabaseException {
+
+               ReadGraphImpl queryGraph = parentGraph.withParent(entry);
+
+               request.perform(queryGraph, new AsyncProcedure<T>() {
+
+                       @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();