X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.db.impl%2Fsrc%2Forg%2Fsimantics%2Fdb%2Fimpl%2Fquery%2FCodeGen.java;h=8661428cb6b94349a034a095bb6e33c56365dc40;hp=2f14b98a54cf6725adc148cc49d623973711bb20;hb=45548cb3447414845d4672b70e22181eeb3a3487;hpb=612d21fb8afa6532906fe58122da16a14a28238c diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/CodeGen.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/CodeGen.java index 2f14b98a5..8661428cb 100644 --- a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/CodeGen.java +++ b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/CodeGen.java @@ -47,6 +47,13 @@ public class CodeGen { line(content, " QueryCache cache = graph.processor.cache;"); if(shortcut) { line(content, " if(parent == null && listener == null && !cache.shouldCache(graph.processor, " + signature[1] + ")) {"); + line(content, " if (SINGLE) {"); + line(content, " " + clazz + " e = cache.peek" + clazz + "(" + signature[1] + ");"); + line(content, " if (e != null && e.isReady()) {"); + line(content, " " + (genReturn ? "return " : "") + "e.performFromCache(graph, procedure);"); + if(!genReturn) line(content, " return;"); + line(content, " }"); + line(content, " }"); line(content, " " + (genReturn ? "return " : "") + clazz + ".computeForEach(graph, " + signature[1] + ", null, procedure);"); if(!genReturn) line(content, " return;"); line(content, " }"); @@ -65,6 +72,14 @@ public class CodeGen { line(content, "}"); line(content, ""); + String lower = Character.toLowerCase(clazz.charAt(0)) + clazz.substring(1); + + line(content, "private " + clazz + " peek" + clazz + "(" + signature[0] + ") {"); + line(content, " synchronized(" + lower +"Map) {"); + line(content, " return (" + clazz + ") " + lower + "Map.get(" + signature[1] + ");"); + line(content, " }"); + line(content, "}"); + line(content, ""); } public void generateRemove(StringBuilder content, String clazz, String[] signature) { @@ -144,6 +159,10 @@ public class CodeGen { content.append("public class QueryCache extends QueryCacheBase {\n"); content.append("\n"); + + line(content, "private static final boolean SINGLE = true;"); + content.append("\n"); + line(content,"public QueryCache(QuerySupport querySupport, int threads) {"); line(content," super(querySupport, threads);"); line(content,"}");