]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/CodeGen.java
Separate query dependency management from QueryProcessor
[simantics/platform.git] / bundles / org.simantics.db.impl / src / org / simantics / db / impl / query / CodeGen.java
index 66ee865a6ed3355ee7eefd0571d7739235fde231..feac07ea284625f9f20a7d775faa08dba62598af 100644 (file)
@@ -94,14 +94,29 @@ public class CodeGen {
             line(content, "    " + clazz + " entry = (" + clazz + ")cache.getOrCreate" + clazz + "(graph, " + signature.keyName + ");");
         }
         line(content, "    " + signature.procedure + " procedure_ = procedure != null ? procedure : emptyProcedure" + clazz + ";");
-        line(content, "    ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);");
-        line(content, "    if(entry.isReady()) " + (genReturn ? "return " : "") + "entry.performFromCache(graph, procedure_);");
+        line(content, "    if(entry.isReady()) {");
+        line(content, "      graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);");
+        if(genReturn) {
+            line(content, "      Object result = entry.performFromCache(graph, procedure_);");
+            line(content, "      graph.processor.listening.registerFirstKnown(listener, result);");
+            line(content, "      return result;");
+        } else {
+            line(content, "      entry.performFromCache(graph, procedure_);");
+        }
+        line(content, "    }");
         line(content, "    else {");
         line(content, "      assert(entry.isPending());");
-        if(shortcut) line(content, "      " + (genReturn ? "Object result = " : "") + clazz + ".computeForEach(graph, " + signature.keyName + ", entry, procedure_" + (signature.useNeedsToBlock ? ", needsToBlock" : "") + ");");
-        else line(content, "      entry.compute(graph, procedure_);"); 
-        line(content, "      if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());");
-        if(genReturn) line(content, "      return result;");
+        if(genReturn) {
+            line(content, "      graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);");
+            if(shortcut) line(content, "      Object result = " + clazz + ".computeForEach(graph, " + signature.keyName + ", entry, procedure_" + (signature.useNeedsToBlock ? ", needsToBlock" : "") + ");");
+            else line(content, "      entry.compute(graph, procedure_);"); 
+            line(content, "      graph.processor.listening.registerFirstKnown(listener, result);");
+            line(content, "      return result;");
+        } else {
+            line(content, "      graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);");
+            if(shortcut) line(content, "      " + clazz + ".computeForEach(graph, " + signature.keyName + ", entry, procedure_" + (signature.useNeedsToBlock ? ", needsToBlock" : "") + ");");
+            else line(content, "      entry.compute(graph, procedure_);"); 
+        }
         line(content, "    }");
         line(content, "}");
         line(content, "");
@@ -203,7 +218,7 @@ public class CodeGen {
                     content.append("public class QueryCache extends QueryCacheBase {\n");
                     content.append("\n");
 
-                    line(content, "private static final boolean SINGLE = false;");
+                    line(content, "private static final boolean SINGLE = true;");
                     content.append("\n");
 
                     line(content,"public QueryCache(QuerySupport querySupport, int threads) {");