]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
First step to enable reading of cache when not writing 55/3055/1
authorAntti Villberg <antti.villberg@semantum.fi>
Fri, 19 Jul 2019 10:27:54 +0000 (13:27 +0300)
committerAntti Villberg <antti.villberg@semantum.fi>
Sat, 3 Aug 2019 09:34:08 +0000 (12:34 +0300)
gitlab #320

Change-Id: If12e55796207f0d08f46fc0670760c2937593e89

bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/AsyncMultiReadEntry.java
bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/AsyncReadEntry.java
bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/CacheEntry.java
bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/CacheEntryBase.java
bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/CodeGen.java
bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/ExternalReadEntry.java
bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/MultiReadEntry.java
bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryCache.java
bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryIdentityHash.java
bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryProcessor.java
bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/ReadEntry.java

index bc3cf0a4f52b7e2c37fbc101ceba389b0ae54f2b..ea88d179107c920f9f10193f727907a56d39356e 100644 (file)
@@ -27,26 +27,26 @@ final public class AsyncMultiReadEntry<T> extends CacheEntryBase<AsyncMultiProce
 
     private static final Logger LOGGER = LoggerFactory.getLogger(AsyncMultiReadEntry.class);
 
-    protected AsyncMultiRead<T> request;
+    protected AsyncMultiRead<T> id;
     
     AsyncMultiReadEntry(AsyncMultiRead<T> request) {
-       this.request = request;
+       this.id = request;
     }
     
     @Override
     int makeHash() {
-       return request.hashCode();
+       return id.hashCode();
     }
     
     @Override
     public Object getOriginalRequest() {
-        return request;
+        return id;
     }
     
     @Override
     public void discard() {
        super.discard();
-       request = null;
+       id = null;
        setResult(null);
     }
     
@@ -111,9 +111,9 @@ final public class AsyncMultiReadEntry<T> extends CacheEntryBase<AsyncMultiProce
                                                        except(t);
                                                }
 
-                                       }, request);
+                                       }, id);
 
-                                       request.perform(graph , proc);
+                                       id.perform(graph , proc);
 
                                        proc.get();
 
@@ -137,8 +137,8 @@ final public class AsyncMultiReadEntry<T> extends CacheEntryBase<AsyncMultiProce
                        
                        @Override
                        public String toString() {
-                               if(request == null) return "DISCARDED";
-                               else return request.toString() + statusOrException;
+                               if(id == null) return "DISCARDED";
+                               else return id.toString() + statusOrException;
                        }
                
         };
@@ -182,12 +182,12 @@ final public class AsyncMultiReadEntry<T> extends CacheEntryBase<AsyncMultiProce
        
        @Override
        public String toString() {
-               if(request == null) return "DISCARDED";
-               else return request.toString() + statusOrException;
+               if(id == null) return "DISCARDED";
+               else return id.toString() + statusOrException;
        }
 
        public Object compute(ReadGraphImpl graph, AsyncMultiProcedure<T> procedure) throws DatabaseException {
-               return graph.processor.cache.performQuery(graph, request, this, procedure);
+               return graph.processor.cache.performQuery(graph, id, this, procedure);
        }
 
 }
index cd5420656400917f5926fa6491b30f27089af6bc..72582ee605802bfe32fac38d10119f6200602586 100644 (file)
@@ -30,10 +30,10 @@ final public class AsyncReadEntry<T> extends CacheEntryBase<AsyncProcedure<T>> i
 
     private static final Logger LOGGER = LoggerFactory.getLogger(AsyncReadEntry.class);
 
-    protected AsyncRead<T> request;
+    protected AsyncRead<T> id;
 
     AsyncReadEntry(AsyncRead<T> request) {
-        this.request = request;
+        this.id = request;
                if (Development.DEVELOPMENT) {
                        if(Development.<Boolean>getProperty(DevelopmentKeys.CACHE_ENTRY_STATE, Bindings.BOOLEAN)) {
                        System.err.println("[QUERY STATE]: created " + this);
@@ -43,12 +43,12 @@ final public class AsyncReadEntry<T> extends CacheEntryBase<AsyncProcedure<T>> i
 
     @Override
     int makeHash() {
-        return request.hashCode();
+        return id.hashCode();
     }
 
     @Override
     public Object getOriginalRequest() {
-        return request;
+        return id;
     }
 
     @Override
@@ -90,9 +90,9 @@ final public class AsyncReadEntry<T> extends CacheEntryBase<AsyncProcedure<T>> i
                             except(t);
                         }
 
-                    }, request);
+                    }, id);
 
-                    request.perform(graph, proc);
+                    id.perform(graph, proc);
 
                     proc.get();
 
@@ -109,17 +109,17 @@ final public class AsyncReadEntry<T> extends CacheEntryBase<AsyncProcedure<T>> i
 
             @Override
             public int type() {
-                return request.getFlags();
+                return id.getFlags();
             }
 
             @Override
             public String toString() {
-                if (request == null)
+                if (id == null)
                     return "DISCARDED";
                 else if (isExcepted())
-                    return request.toString() + " " + getResult();
+                    return id.toString() + " " + getResult();
                 else
-                    return request.toString() + " " + statusOrException;
+                    return id.toString() + " " + statusOrException;
             }
 
         };
@@ -242,11 +242,11 @@ final public class AsyncReadEntry<T> extends CacheEntryBase<AsyncProcedure<T>> i
     @Override
     public String toString() {
         if (isDiscarded())
-            return "DISCARDED " + request.toString();
+            return "DISCARDED " + id.toString();
         else if (isExcepted())
-            return request.toString() + " " + getResult();
+            return id.toString() + " " + getResult();
         else
-            return request.toString() + " " + statusOrException;
+            return id.toString() + " " + statusOrException;
     }
 
     @Override
index 8489256225da47bfa52c2aa29940ffbba386e24b..1cdcbde9dd0b11733b224877c4a5a0c7cf41cbe7 100644 (file)
@@ -29,7 +29,7 @@ public abstract class CacheEntry<Procedure> {
 
     abstract void setReady();
     abstract void refute();
-    abstract void setPending();
+    abstract void setPending(QuerySupport querySupport);
     abstract void discard();
     abstract void except(Throwable t);
     abstract void clearResult(QuerySupport support);
index 3a94e52b6f9dd58f55031b852df02776fc044874..e79f99deae1d06ab4469e1496accd8fbcacb3e97 100644 (file)
@@ -145,8 +145,9 @@ public abstract class CacheEntryBase<Procedure> extends CacheEntry<Procedure> {
     }
 
     @Override
-    public void setPending() {
-       statusOrException = PENDING;
+    public void setPending(QuerySupport querySupport) {
+        statusOrException = PENDING;
+        clearResult(querySupport);
     }
     
     @Override
@@ -439,8 +440,7 @@ public abstract class CacheEntryBase<Procedure> extends CacheEntry<Procedure> {
     
     @Override
     void prepareRecompute(QuerySupport querySupport) {
-               setPending();
-               clearResult(querySupport);
+        setPending(querySupport);
     }
     
     @Override
index 8661428cb6b94349a034a095bb6e33c56365dc40..66ee865a6ed3355ee7eefd0571d7739235fde231 100644 (file)
@@ -11,203 +11,246 @@ import org.simantics.utils.FileUtils;
 
 public class CodeGen {
 
-       int indent = 4;
-
-       String[] signatureR1RelationInfo = { "int r", "r", "keyR", "long", "InternalProcedure<RelationInfo>", "entry.id" };
-       String[] signatureR1Bytes = { "int r", "r", "keyR", "long", "InternalProcedure<byte[]>", "entry.id" };
-       String[] signatureR1IntSet = { "int r", "r", "keyR", "long", "InternalProcedure<IntSet>", "entry.id" };
-       String[] signatureR1IP = { "int r", "r", "keyR", "long", "IntProcedure", "entry.id" };
-       String[] signatureR2IP = { "int r1, int r2", "r1,r2", "keyR2", "long", "IntProcedure", "entry.id" };
-       String[] signatureR2TIP = { "int r1, int r2", "r1,r2", "keyR2", "long", "TripleIntProcedure", "entry.id" };
-       String[] signatureID1 = { "String id", "id", "keyID", "String", "InternalProcedure<Integer>", "entry.id" };
-       String[] signatureID2 = { "String id", "id", "keyID", "String", "InternalProcedure<TObjectIntHashMap<String>>", "entry.id" };
-       String[] signatureChildMap = { "int r", "r", "keyR", "long", "InternalProcedure<ObjectResourceIdMap<String>>", "entry.id" };
-       String[] signatureRead = { "Read<?> r", "r", "id", "long", "AsyncProcedure", "entry.request" };
-       String[] signatureAsyncRead = { "AsyncRead<?> r", "r", "id", "long", "AsyncProcedure", "entry.request" };
-       String[] signatureMultiRead = { "MultiRead<?> r", "r", "id", "long", "SyncMultiProcedure", "entry.request" };
-       String[] signatureAsyncMultiRead = { "AsyncMultiRead<?> r", "r", "id", "long", "AsyncMultiProcedure", "entry.request" };
-       String[] signatureExternalRead = { "ExternalRead<?> r", "r", "id", "long", "AsyncProcedure", "entry.request" };
-
-       private void line(StringBuilder content, String line) {
-               for(int i=0;i<indent;i++)
-                       content.append(" ");
-               content.append(line);
-               content.append("\n");
-       }
-
-    public void generateQuery(StringBuilder content, String clazz, String[] signature, boolean runnerShortcut, boolean genReturn) {
-               generateGetOrCreate(content, clazz, signature);
-               generateRemove(content, clazz, signature);
-               generateRunner(content, clazz, signature, runnerShortcut, genReturn);
-       }
-
-       public void generateRunner(StringBuilder content, String clazz, String[] signature, boolean shortcut, boolean genReturn) {
-
-               line(content, "public static " + (genReturn ? "Object" : "void") + " runner" + clazz + "(ReadGraphImpl graph, " + signature[0] + ", CacheEntry parent, ListenerBase listener, final " + signature[4] + " procedure) throws DatabaseException {");
-               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, "    }");
-               }
-               line(content, "    " + clazz + " entry = (" + clazz + ")cache.getOrCreate" + clazz + "(graph, " + signature[1] + ");");
-               line(content, "    " + signature[4] + " 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, "    else {");
-               line(content, "      assert(entry.isPending());");
-               if(shortcut) line(content, "      " + (genReturn ? "Object result = " : "") + clazz + ".computeForEach(graph, " + signature[1] + ", entry, procedure_);");
-               else line(content, "      entry.compute(graph, procedure_);"); 
-               line(content, "      if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());");
-               if(genReturn) line(content, "      return result;");
-               line(content, "    }");
-               line(content, "}");
-               line(content, "");
+    int indent = 4;
+
+    class GenerationInfo {
+        String p1;
+        String keyName;
+        String keyToId;
+        String procedure;
+        boolean useNeedsToBlock;
+        String entryCreationArguments;
+        GenerationInfo(String p1, String keyName, String keyToId, String p4, String procedure, String entryCreationArguments, boolean useNeedsToBlock) {
+            this.p1 = p1;
+            this.keyName = keyName;
+            this.keyToId = keyToId;
+            this.procedure = procedure;
+            this.useNeedsToBlock = useNeedsToBlock;
+            this.entryCreationArguments = entryCreationArguments;
+        }
+    }
+
+    GenerationInfo signatureR1RelationInfo = new GenerationInfo  ( "int r", "r", "keyR", "long", "InternalProcedure<RelationInfo>", "", false );
+    GenerationInfo signatureR1Bytes = new GenerationInfo  ( "int r", "r", "keyR", "long", "InternalProcedure<byte[]>", "", false );
+    GenerationInfo signatureR1IntSet = new GenerationInfo  ( "int r", "r", "keyR", "long", "InternalProcedure<IntSet>", "", false );
+    GenerationInfo signatureR1IP = new GenerationInfo  ( "int r", "r", "keyR", "long", "IntProcedure", "", false );
+    GenerationInfo signatureR2IP = new GenerationInfo  ( "int r1, int r2", "r1,r2", "keyR2", "long", "IntProcedure", "", false );
+    GenerationInfo signatureR2TIP = new GenerationInfo  ( "int r1, int r2", "r1,r2", "keyR2", "long", "TripleIntProcedure", "", false );
+    GenerationInfo signatureID1 = new GenerationInfo  ( "String id", "id", "keyID", "String", "InternalProcedure<Integer>", "", false );
+    GenerationInfo signatureID2 = new GenerationInfo  ( "String id", "id", "keyID", "String", "InternalProcedure<TObjectIntHashMap<String>>", "", false );
+    GenerationInfo signatureChildMap = new GenerationInfo  ( "int r", "r", "keyR", "long", "InternalProcedure<ObjectResourceIdMap<String>>", "", false );
+    GenerationInfo signatureRead = new GenerationInfo  ( "Read<?> r", "r", "id", "long", "AsyncProcedure", "", true );
+    GenerationInfo signatureAsyncRead = new GenerationInfo  ( "AsyncRead<?> r", "r", "id", "long", "AsyncProcedure", "", true );
+    GenerationInfo signatureMultiRead = new GenerationInfo  ( "MultiRead<?> r", "r", "id", "long", "SyncMultiProcedure", "", false );
+    GenerationInfo signatureAsyncMultiRead = new GenerationInfo  ( "AsyncMultiRead<?> r", "r", "id", "long", "AsyncMultiProcedure", "", false );
+    GenerationInfo signatureExternalRead = new GenerationInfo  ( "ExternalRead<?> r", "r", "id", "long", "AsyncProcedure", ", graph", false );
+
+    private void line(StringBuilder content, String line) {
+        for(int i=0;i<indent;i++)
+            content.append(" ");
+        content.append(line);
+        content.append("\n");
+    }
+
+    public void generateQuery(StringBuilder content, String clazz, GenerationInfo signature, boolean runnerShortcut, boolean genReturn) {
+        generateGetOrCreate(content, clazz, signature);
+        generateRemove(content, clazz, signature);
+        generateRunner(content, clazz, signature, runnerShortcut, genReturn);
+    }
+
+    public void generateRunner(StringBuilder content, String clazz, GenerationInfo signature, boolean shortcut, boolean genReturn) {
+
+        line(content, "public static " + (genReturn ? "Object" : "void") + " runner" + clazz + "(ReadGraphImpl graph, " + signature.p1 + ", CacheEntry parent, ListenerBase listener, final " + signature.procedure + " procedure" + (signature.useNeedsToBlock ? ", boolean needsToBlock" : "") + ") throws DatabaseException {");
+        line(content, "    QueryCache cache  = graph.processor.cache;");
+        if(shortcut) {
+            line(content, "    if(parent == null && listener == null && !cache.shouldCache(graph.processor, " + signature.keyName + ")) {");
+            line(content, "        if (SINGLE) {");
+            line(content, "            " + clazz + " e = cache.peek" + clazz + "(" + signature.keyName + ");");
+            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.keyName + ", null, procedure" + (signature.useNeedsToBlock ? ", needsToBlock" : "") + ");");
+            if(!genReturn) line(content, "        return;");
+            line(content, "    }");
+        }
+        if(signature.useNeedsToBlock) {
+            line(content, "    " + clazz + " entry = (" + clazz + ")cache.getOrCreate" + clazz + "(graph, " + signature.keyName + ", needsToBlock);");
+            line(content, "    if(entry == null) {");
+            line(content, "      graph.processor.schedule(new SessionTask(graph) {");
+            line(content, "        @Override");
+            line(content, "        public void run0(int thread) {");
+            line(content, "          try {");
+            line(content, "            runner" + clazz + "(graph, r, parent, listener, procedure, needsToBlock);");
+            line(content, "          } catch (DatabaseException e) {");
+            line(content, "            Logger.defaultLogError(e);");
+            line(content, "          }");
+            line(content, "        }");
+            line(content, "      });");
+            line(content, "      return null;");
+            line(content, "    }");
+        } else {
+            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, "    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;");
+        line(content, "    }");
+        line(content, "}");
+        line(content, "");
+
+        String lower = Character.toLowerCase(clazz.charAt(0)) + clazz.substring(1);
+
+        line(content, "private " + clazz + " peek" + clazz + "(" + signature.p1 + ") {");
+        line(content, "    synchronized(" + lower +"Map) {");
+        line(content, "        return (" + clazz + ") " + lower + "Map.get(" + signature.keyName + ");");
+        line(content, "    }");
+        line(content, "}");
+        line(content, "");
+    }
+
+    public void generateRemove(StringBuilder content, String clazz, GenerationInfo signature) {
+
+        String lower = Character.toLowerCase(clazz.charAt(0)) + clazz.substring(1);
+
+        line(content, "void remove(" + clazz + " entry) {");
+        line(content, "    synchronized(" + lower + "Map) {");
+        line(content, "        " + lower + "Map.remove(entry.id);");
+        line(content, "    }");
+        line(content, "}");
+        line(content, "");
+
+    }
+
+    public void generateGetOrCreate(StringBuilder content, String clazz, GenerationInfo signature) {
 
         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) {
-
-               String lower = Character.toLowerCase(clazz.charAt(0)) + clazz.substring(1);
-
-               line(content, "void remove(" + clazz + " entry) {");
-               line(content, "    synchronized(" + lower + "Map) {");
-               line(content, "        " + lower + "Map.remove(" + signature[5] + ");");
-               line(content, "    }");
-               line(content, "}");
-               line(content, "");
-
-       }
-
-       public void generateGetOrCreate(StringBuilder content, String clazz, String[] signature) {
-
-               String lower = Character.toLowerCase(clazz.charAt(0)) + clazz.substring(1);
-
-               line(content, "" + clazz + " getOrCreate" + clazz + "(ReadGraphImpl graph, " + signature[0] + ") throws DatabaseException {");
-               line(content, "    " + clazz + " existing = null;");
-               line(content, "    synchronized(" + lower + "Map) {");
-               line(content, "        existing = (" + clazz + ")" + lower + "Map.get(" + signature[1] + ");");
-               line(content, "        if(existing == null) {");
-               line(content, "            existing = new " + clazz + "(" + signature[1] + ");");
-               line(content, "            existing.clearResult(querySupport);");
-               line(content, "            existing.setPending();");
-               line(content, "            " + lower + "Map.put(" + signature[2] + "(" + signature[1] + "), existing);");
-               line(content, "            size++;");
-               line(content, "            return existing;");
-               line(content, "        }");
-               line(content, "        if(existing.requiresComputation()) {");
-               line(content, "            existing.setPending();");
-               line(content, "            return existing;");
-               line(content, "        }");
-               line(content, "    }");
-               line(content, "    if(existing.isPending()) waitPending(graph, existing);");
-               line(content, "    return existing;");
-               line(content, "}");
-               line(content, "");
-
-       }
-
-       public void generate() {
-
-               URL classLocation = CodeGen.class.getResource(".");
-               if (classLocation != null) {
-                       if (classLocation.getProtocol().equals("file")) {
-                               try {
-                                       URL resource = new URL(classLocation, ".");
-                                       File path = new File(URLDecoder.decode(resource.getPath(), "UTF-8"));
-                                       String target = path.getAbsolutePath().replace("\\", "/");
-                                       target = target.replace("/bin/", "/src/") + "/QueryCache.java";
-                                       System.err.println("target=" + target);
-                                       File source = new File(target);
-                                       StringBuilder content = new StringBuilder();
-                                       content.append("package org.simantics.db.impl.query;\n");
-                                       content.append("\n");
-
-                                       content.append("import org.simantics.db.ObjectResourceIdMap;\n");
-                                       content.append("import org.simantics.db.RelationInfo;\n");
-                                       content.append("import org.simantics.db.common.utils.Logger;\n");
-                                       content.append("import org.simantics.db.exception.DatabaseException;\n");
-                                       content.append("import org.simantics.db.impl.graph.ReadGraphImpl;\n");
-                                       content.append("import org.simantics.db.impl.procedure.InternalProcedure;\n");
-                                       content.append("import org.simantics.db.impl.query.QueryProcessor.SessionTask;\n");
-                                       content.append("import org.simantics.db.procedure.AsyncMultiProcedure;\n");
-                                       content.append("import org.simantics.db.procedure.AsyncProcedure;\n");
-                                       content.append("import org.simantics.db.procedure.ListenerBase;\n");
-                                       content.append("import org.simantics.db.procedure.SyncMultiProcedure;\n");
-                                       content.append("import org.simantics.db.request.AsyncMultiRead;\n");
-                                       content.append("import org.simantics.db.request.AsyncRead;\n");
-                                       content.append("import org.simantics.db.request.ExternalRead;\n");
-                                       content.append("import org.simantics.db.request.MultiRead;\n");
-                                       content.append("import org.simantics.db.request.Read;\n");
-                                       content.append("\n");
-
-                                       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,"}");
-                                       content.append("\n");
-
-                                       generateQuery(content, "Objects", signatureR2IP, true, false);
-                                       generateQuery(content, "Statements", signatureR2TIP, true, false);
-                                       generateQuery(content, "DirectObjects", signatureR2IP, true, false);
-                                       generateQuery(content, "RelationInfoQuery", signatureR1RelationInfo, true, false);
-                                       generateQuery(content, "URIToResource", signatureID1, true, false);
-                                       generateQuery(content, "ValueQuery", signatureR1Bytes, true, false);
-                                       generateQuery(content, "OrderedSet", signatureR1IP, true, false);
-                                       generateQuery(content, "PrincipalTypes", signatureR1IP, true, false);
-                                       generateQuery(content, "DirectPredicates", signatureR1IntSet, true, false);
-                                       generateQuery(content, "Predicates", signatureR1IntSet, true, false);
-                                       generateQuery(content, "ReadEntry", signatureRead, true, true);
-                                       generateQuery(content, "AsyncReadEntry", signatureAsyncRead, true, true);
-                                       generateQuery(content, "Types", signatureR1IntSet, true, false);
-                                       generateQuery(content, "ChildMap", signatureChildMap, true, false);
-                                       generateQuery(content, "TypeHierarchy", signatureR1IntSet, true, false);
-                                       generateQuery(content, "SuperTypes", signatureR1IntSet, true, false);
-                                       generateQuery(content, "SuperRelations", signatureR1IntSet, true, false);
-
-                                       generateQuery(content, "AssertedPredicates", signatureR1IP, false, false);
-                                       generateQuery(content, "AssertedStatements", signatureR2TIP, false, false);
-                                       generateQuery(content, "DirectSuperRelations", signatureR1IP, false, false);
-                                       generateQuery(content, "MultiReadEntry", signatureMultiRead, false, false);
-                                       generateQuery(content, "AsyncMultiReadEntry", signatureAsyncMultiRead, false, false);
-                                       generateQuery(content, "ExternalReadEntry", signatureExternalRead, false, false);
-                                       content.append("}\n");
-                                       FileUtils.writeFile(source, content.toString().getBytes());
-                               } catch (MalformedURLException e) {
-                                       e.printStackTrace();
-                               } catch (UnsupportedEncodingException e) {
-                                       e.printStackTrace();
-                               } catch (IOException e) {
-                                       e.printStackTrace();
-                               }
-                       }
-               }
-
-       }
-
-       public static void main(String[] args) {
-               new CodeGen().generate();
-       }
+        line(content, "" + clazz + " getOrCreate" + clazz + "(ReadGraphImpl graph, " + signature.p1 + (signature.useNeedsToBlock ? ", boolean needsToBlock" : "") +  ") throws DatabaseException {");
+        line(content, "    " + clazz + " existing = null;");
+        line(content, "    synchronized(" + lower + "Map) {");
+        line(content, "        existing = (" + clazz + ")" + lower + "Map.get(" + signature.keyName + ");");
+        line(content, "        if(existing == null) {");
+        line(content, "            existing = new " + clazz + "(" + signature.keyName + signature.entryCreationArguments + ");");
+        line(content, "            existing.setPending(querySupport);");
+        line(content, "            " + lower + "Map.put(" + signature.keyToId + "(" + signature.keyName + "), existing);");
+        line(content, "            size++;");
+        line(content, "            return existing;");
+        line(content, "        }");
+        line(content, "        if(existing.requiresComputation()) {");
+        line(content, "            existing.setPending(querySupport);");
+        line(content, "            return existing;");
+        line(content, "        }");
+        line(content, "    }");
+        line(content, "    if(existing.isPending()) {");
+        if(signature.useNeedsToBlock) {
+            line(content, "      if(needsToBlock)");
+            line(content, "        waitPending(graph, existing);");
+            line(content, "      else {");
+            line(content, "        return null;");
+            line(content, "      }");
+        } else {
+            line(content, "      waitPending(graph, existing);");
+        }
+        line(content, "    }");
+        line(content, "    return existing;");
+        line(content, "}");
+        line(content, "");
+
+    }
+
+    public void generate() {
+
+        URL classLocation = CodeGen.class.getResource(".");
+        if (classLocation != null) {
+            if (classLocation.getProtocol().equals("file")) {
+                try {
+                    URL resource = new URL(classLocation, ".");
+                    File path = new File(URLDecoder.decode(resource.getPath(), "UTF-8"));
+                    String target = path.getAbsolutePath().replace("\\", "/");
+                    target = target.replace("/bin/", "/src/") + "/QueryCache.java";
+                    System.err.println("target=" + target);
+                    File source = new File(target);
+                    StringBuilder content = new StringBuilder();
+                    content.append("package org.simantics.db.impl.query;\n");
+                    content.append("\n");
+
+                    content.append("import org.simantics.db.ObjectResourceIdMap;\n");
+                    content.append("import org.simantics.db.RelationInfo;\n");
+                    content.append("import org.simantics.db.common.utils.Logger;\n");
+                    content.append("import org.simantics.db.exception.DatabaseException;\n");
+                    content.append("import org.simantics.db.impl.graph.ReadGraphImpl;\n");
+                    content.append("import org.simantics.db.impl.procedure.InternalProcedure;\n");
+                    content.append("import org.simantics.db.impl.query.QueryProcessor.SessionTask;\n");
+                    content.append("import org.simantics.db.procedure.AsyncMultiProcedure;\n");
+                    content.append("import org.simantics.db.procedure.AsyncProcedure;\n");
+                    content.append("import org.simantics.db.procedure.ListenerBase;\n");
+                    content.append("import org.simantics.db.procedure.SyncMultiProcedure;\n");
+                    content.append("import org.simantics.db.request.AsyncMultiRead;\n");
+                    content.append("import org.simantics.db.request.AsyncRead;\n");
+                    content.append("import org.simantics.db.request.ExternalRead;\n");
+                    content.append("import org.simantics.db.request.MultiRead;\n");
+                    content.append("import org.simantics.db.request.Read;\n");
+                    content.append("\n");
+
+                    content.append("public class QueryCache extends QueryCacheBase {\n");
+                    content.append("\n");
+
+                    line(content, "private static final boolean SINGLE = false;");
+                    content.append("\n");
+
+                    line(content,"public QueryCache(QuerySupport querySupport, int threads) {");
+                    line(content,"    super(querySupport, threads);");
+                    line(content,"}");
+                    content.append("\n");
+
+                    generateQuery(content, "Objects", signatureR2IP, true, false);
+                    generateQuery(content, "Statements", signatureR2TIP, true, false);
+                    generateQuery(content, "DirectObjects", signatureR2IP, true, false);
+                    generateQuery(content, "RelationInfoQuery", signatureR1RelationInfo, true, false);
+                    generateQuery(content, "URIToResource", signatureID1, true, false);
+                    generateQuery(content, "ValueQuery", signatureR1Bytes, true, false);
+                    generateQuery(content, "OrderedSet", signatureR1IP, true, false);
+                    generateQuery(content, "PrincipalTypes", signatureR1IP, true, false);
+                    generateQuery(content, "DirectPredicates", signatureR1IntSet, true, false);
+                    generateQuery(content, "Predicates", signatureR1IntSet, true, false);
+                    generateQuery(content, "ReadEntry", signatureRead, true, true);
+                    generateQuery(content, "AsyncReadEntry", signatureAsyncRead, true, true);
+                    generateQuery(content, "Types", signatureR1IntSet, true, false);
+                    generateQuery(content, "ChildMap", signatureChildMap, true, false);
+                    generateQuery(content, "TypeHierarchy", signatureR1IntSet, true, false);
+                    generateQuery(content, "SuperTypes", signatureR1IntSet, true, false);
+                    generateQuery(content, "SuperRelations", signatureR1IntSet, true, false);
+
+                    generateQuery(content, "AssertedPredicates", signatureR1IP, false, false);
+                    generateQuery(content, "AssertedStatements", signatureR2TIP, false, false);
+                    generateQuery(content, "DirectSuperRelations", signatureR1IP, false, false);
+                    generateQuery(content, "MultiReadEntry", signatureMultiRead, false, false);
+                    generateQuery(content, "AsyncMultiReadEntry", signatureAsyncMultiRead, false, false);
+                    generateQuery(content, "ExternalReadEntry", signatureExternalRead, false, false);
+                    content.append("}\n");
+                    FileUtils.writeFile(source, content.toString().getBytes());
+                } catch (MalformedURLException e) {
+                    e.printStackTrace();
+                } catch (UnsupportedEncodingException e) {
+                    e.printStackTrace();
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            }
+        }
+
+    }
+
+    public static void main(String[] args) {
+        new CodeGen().generate();
+    }
 
 }
index ac07ad7eda1acb4e3f51884b35b4b5ff99ad8445..556d5fc3e12b8d2df0d5e42ea2efb2221a8fb65f 100644 (file)
@@ -27,18 +27,18 @@ final public class ExternalReadEntry<T> extends CacheEntryBase<AsyncProcedure<T>
 
     final LinkedList<T> items = new LinkedList<T>();
 
-    protected ExternalRead<T> request;
+    protected ExternalRead<T> id;
     protected ReadGraphImpl graph;
     protected boolean registered = false;
 
     @Override
     int makeHash() {
-       return request.hashCode();
+       return id.hashCode();
     }
     
     @Override
     public Object getOriginalRequest() {
-        return request;
+        return id;
     }
     
     @Override
@@ -47,14 +47,14 @@ final public class ExternalReadEntry<T> extends CacheEntryBase<AsyncProcedure<T>
     
     @Override
     public void discard() {
-        request.unregistered();
-        request = null;
+        id.unregistered();
+        id = null;
         graph = null;
         super.discard();
     }
 
     @Override
-    public void setPending() {
+    public void setPending(QuerySupport querySupport) {
         //if(result != NO_RESULT) {
             //new Exception("result = " + result).printStackTrace();
         //}
@@ -64,7 +64,7 @@ final public class ExternalReadEntry<T> extends CacheEntryBase<AsyncProcedure<T>
     
     public ExternalReadEntry(ExternalRead<T> request, ReadGraphImpl graph) {
         assert request != null;
-        this.request = request;
+        this.id = request;
         this.graph = graph;
     }
     
@@ -119,7 +119,7 @@ final public class ExternalReadEntry<T> extends CacheEntryBase<AsyncProcedure<T>
                                        }
                                        // Reschedule
                                        if(!items.isEmpty()) {
-                                               graph.processor.updatePrimitive(request);
+                                               graph.processor.updatePrimitive(id);
                                        }
 
                                }
@@ -138,8 +138,8 @@ final public class ExternalReadEntry<T> extends CacheEntryBase<AsyncProcedure<T>
                        
                        @Override
                        public String toString() {
-                               if(request == null) return "DISCARDED ExternalRead";
-                               else return request.toString();
+                               if(id == null) return "DISCARDED ExternalRead";
+                               else return id.toString();
                        }
                
         };
@@ -148,8 +148,8 @@ final public class ExternalReadEntry<T> extends CacheEntryBase<AsyncProcedure<T>
 
        @Override
        public String toString() {
-               if(request == null) return "DISCARDED ExternalRead " + System.identityHashCode(this);
-               else return request.toString() + " " + + System.identityHashCode(this);
+               if(id == null) return "DISCARDED ExternalRead " + System.identityHashCode(this);
+               else return id.toString() + " " + + System.identityHashCode(this);
        }
 
     @Override
@@ -183,11 +183,11 @@ final public class ExternalReadEntry<T> extends CacheEntryBase<AsyncProcedure<T>
                        ReadGraphImpl queryGraph = graph.withParent(this);
 
                        if(!registered) {
-                               request.register(graph, this);
+                               id.register(graph, this);
                                registered = true;
                        }
                        
-                       queryGraph.asyncBarrier.waitBarrier(request, graph);
+                       queryGraph.asyncBarrier.waitBarrier(id, graph);
 
                } catch (Throwable t) {
 
@@ -213,7 +213,7 @@ final public class ExternalReadEntry<T> extends CacheEntryBase<AsyncProcedure<T>
 
                synchronized(items) {
                        items.addLast(result);
-                               graph.processor.updatePrimitive(request);
+                               graph.processor.updatePrimitive(id);
                        // TODO: implement flags/logic in ExternalRead to state that all but the latest request result can be evaporated
                        // In some cases where data is produced really fast this might be necessary but currently this queueing will do.
                }
index 6b7415c9780f7a45c715068c83c4f02f1fe1fb29..77e3b8d0fc0bd592b9b85c9ea49d34b3b64bcb79 100644 (file)
@@ -29,26 +29,26 @@ public final class MultiReadEntry<T> extends CacheEntryBase<SyncMultiProcedure<T
 
     private static final Logger LOGGER = LoggerFactory.getLogger(MultiReadEntry.class);
 
-    protected MultiRead<T> request;
+    protected MultiRead<T> id;
     
     MultiReadEntry(MultiRead<T> request) {
-       this.request = request;
+       this.id = request;
     }
 
     @Override
     int makeHash() {
-       return request.hashCode();
+       return id.hashCode();
     }
     
     @Override
     public Object getOriginalRequest() {
-        return request;
+        return id;
     }
     
     @Override
     public void discard() {
        super.discard();
-       request = null;
+       id = null;
        setResult(null);
     }
     
@@ -86,7 +86,7 @@ public final class MultiReadEntry<T> extends CacheEntryBase<SyncMultiProcedure<T
                                
                                try {
 
-                                   request.perform(graph , new SyncMultiProcedure<T>() {
+                                   id.perform(graph , new SyncMultiProcedure<T>() {
 
                         @Override
                         public void execute(ReadGraph graph, T result) {
@@ -123,8 +123,8 @@ public final class MultiReadEntry<T> extends CacheEntryBase<SyncMultiProcedure<T
                        
                        @Override
                        public String toString() {
-                               if(request == null) return "DISCARDED";
-                               else return request.toString() + statusOrException;
+                               if(id == null) return "DISCARDED";
+                               else return id.toString() + statusOrException;
                        }
                
         };
@@ -202,12 +202,12 @@ public final class MultiReadEntry<T> extends CacheEntryBase<SyncMultiProcedure<T
 
        @Override
        public String toString() {
-               if(request == null) return "DISCARDED";
-               else return request.toString() + statusOrException;
+               if(id == null) return "DISCARDED";
+               else return id.toString() + statusOrException;
        }
 
        public Object compute(ReadGraphImpl graph, SyncMultiProcedure<T> procedure) throws DatabaseException {
-               return graph.processor.cache.performQuery(graph, request, this, procedure);
+               return graph.processor.cache.performQuery(graph, id, this, procedure);
        }
 
 }
index 48d5646c27eaa3aaeee3ac636f78e165d968e7c9..06882a48943e711e502d725108ee2f0e4147f213 100644 (file)
@@ -19,9 +19,8 @@ import org.simantics.db.request.Read;
 
 public class QueryCache extends QueryCacheBase {
 
-    // Using QueryChaching breaks Diagram Editor (and probably something else). 
-       private static final boolean SINGLE = false;
-    
+    private static final boolean SINGLE = false;
+
     public QueryCache(QuerySupport querySupport, int threads) {
         super(querySupport, threads);
     }
@@ -32,18 +31,19 @@ public class QueryCache extends QueryCacheBase {
             existing = (Objects)objectsMap.get(r1,r2);
             if(existing == null) {
                 existing = new Objects(r1,r2);
-                existing.clearResult(querySupport);
-                existing.setPending();
+                existing.setPending(querySupport);
                 objectsMap.put(keyR2(r1,r2), existing);
                 size++;
                 return existing;
             }
             if(existing.requiresComputation()) {
-                existing.setPending();
+                existing.setPending(querySupport);
                 return existing;
             }
         }
-        if(existing.isPending()) waitPending(graph, existing);
+        if(existing.isPending()) {
+          waitPending(graph, existing);
+        }
         return existing;
     }
     
@@ -89,18 +89,19 @@ public class QueryCache extends QueryCacheBase {
             existing = (Statements)statementsMap.get(r1,r2);
             if(existing == null) {
                 existing = new Statements(r1,r2);
-                existing.clearResult(querySupport);
-                existing.setPending();
+                existing.setPending(querySupport);
                 statementsMap.put(keyR2(r1,r2), existing);
                 size++;
                 return existing;
             }
             if(existing.requiresComputation()) {
-                existing.setPending();
+                existing.setPending(querySupport);
                 return existing;
             }
         }
-        if(existing.isPending()) waitPending(graph, existing);
+        if(existing.isPending()) {
+          waitPending(graph, existing);
+        }
         return existing;
     }
     
@@ -146,18 +147,19 @@ public class QueryCache extends QueryCacheBase {
             existing = (DirectObjects)directObjectsMap.get(r1,r2);
             if(existing == null) {
                 existing = new DirectObjects(r1,r2);
-                existing.clearResult(querySupport);
-                existing.setPending();
+                existing.setPending(querySupport);
                 directObjectsMap.put(keyR2(r1,r2), existing);
                 size++;
                 return existing;
             }
             if(existing.requiresComputation()) {
-                existing.setPending();
+                existing.setPending(querySupport);
                 return existing;
             }
         }
-        if(existing.isPending()) waitPending(graph, existing);
+        if(existing.isPending()) {
+          waitPending(graph, existing);
+        }
         return existing;
     }
     
@@ -203,18 +205,19 @@ public class QueryCache extends QueryCacheBase {
             existing = (RelationInfoQuery)relationInfoQueryMap.get(r);
             if(existing == null) {
                 existing = new RelationInfoQuery(r);
-                existing.clearResult(querySupport);
-                existing.setPending();
+                existing.setPending(querySupport);
                 relationInfoQueryMap.put(keyR(r), existing);
                 size++;
                 return existing;
             }
             if(existing.requiresComputation()) {
-                existing.setPending();
+                existing.setPending(querySupport);
                 return existing;
             }
         }
-        if(existing.isPending()) waitPending(graph, existing);
+        if(existing.isPending()) {
+          waitPending(graph, existing);
+        }
         return existing;
     }
     
@@ -260,18 +263,19 @@ public class QueryCache extends QueryCacheBase {
             existing = (URIToResource)uRIToResourceMap.get(id);
             if(existing == null) {
                 existing = new URIToResource(id);
-                existing.clearResult(querySupport);
-                existing.setPending();
+                existing.setPending(querySupport);
                 uRIToResourceMap.put(keyID(id), existing);
                 size++;
                 return existing;
             }
             if(existing.requiresComputation()) {
-                existing.setPending();
+                existing.setPending(querySupport);
                 return existing;
             }
         }
-        if(existing.isPending()) waitPending(graph, existing);
+        if(existing.isPending()) {
+          waitPending(graph, existing);
+        }
         return existing;
     }
     
@@ -317,18 +321,19 @@ public class QueryCache extends QueryCacheBase {
             existing = (ValueQuery)valueQueryMap.get(r);
             if(existing == null) {
                 existing = new ValueQuery(r);
-                existing.clearResult(querySupport);
-                existing.setPending();
+                existing.setPending(querySupport);
                 valueQueryMap.put(keyR(r), existing);
                 size++;
                 return existing;
             }
             if(existing.requiresComputation()) {
-                existing.setPending();
+                existing.setPending(querySupport);
                 return existing;
             }
         }
-        if(existing.isPending()) waitPending(graph, existing);
+        if(existing.isPending()) {
+          waitPending(graph, existing);
+        }
         return existing;
     }
     
@@ -374,18 +379,19 @@ public class QueryCache extends QueryCacheBase {
             existing = (OrderedSet)orderedSetMap.get(r);
             if(existing == null) {
                 existing = new OrderedSet(r);
-                existing.clearResult(querySupport);
-                existing.setPending();
+                existing.setPending(querySupport);
                 orderedSetMap.put(keyR(r), existing);
                 size++;
                 return existing;
             }
             if(existing.requiresComputation()) {
-                existing.setPending();
+                existing.setPending(querySupport);
                 return existing;
             }
         }
-        if(existing.isPending()) waitPending(graph, existing);
+        if(existing.isPending()) {
+          waitPending(graph, existing);
+        }
         return existing;
     }
     
@@ -431,18 +437,19 @@ public class QueryCache extends QueryCacheBase {
             existing = (PrincipalTypes)principalTypesMap.get(r);
             if(existing == null) {
                 existing = new PrincipalTypes(r);
-                existing.clearResult(querySupport);
-                existing.setPending();
+                existing.setPending(querySupport);
                 principalTypesMap.put(keyR(r), existing);
                 size++;
                 return existing;
             }
             if(existing.requiresComputation()) {
-                existing.setPending();
+                existing.setPending(querySupport);
                 return existing;
             }
         }
-        if(existing.isPending()) waitPending(graph, existing);
+        if(existing.isPending()) {
+          waitPending(graph, existing);
+        }
         return existing;
     }
     
@@ -488,18 +495,19 @@ public class QueryCache extends QueryCacheBase {
             existing = (DirectPredicates)directPredicatesMap.get(r);
             if(existing == null) {
                 existing = new DirectPredicates(r);
-                existing.clearResult(querySupport);
-                existing.setPending();
+                existing.setPending(querySupport);
                 directPredicatesMap.put(keyR(r), existing);
                 size++;
                 return existing;
             }
             if(existing.requiresComputation()) {
-                existing.setPending();
+                existing.setPending(querySupport);
                 return existing;
             }
         }
-        if(existing.isPending()) waitPending(graph, existing);
+        if(existing.isPending()) {
+          waitPending(graph, existing);
+        }
         return existing;
     }
     
@@ -545,18 +553,19 @@ public class QueryCache extends QueryCacheBase {
             existing = (Predicates)predicatesMap.get(r);
             if(existing == null) {
                 existing = new Predicates(r);
-                existing.clearResult(querySupport);
-                existing.setPending();
+                existing.setPending(querySupport);
                 predicatesMap.put(keyR(r), existing);
                 size++;
                 return existing;
             }
             if(existing.requiresComputation()) {
-                existing.setPending();
+                existing.setPending(querySupport);
                 return existing;
             }
         }
-        if(existing.isPending()) waitPending(graph, existing);
+        if(existing.isPending()) {
+          waitPending(graph, existing);
+        }
         return existing;
     }
     
@@ -602,32 +611,33 @@ public class QueryCache extends QueryCacheBase {
             existing = (ReadEntry)readEntryMap.get(r);
             if(existing == null) {
                 existing = new ReadEntry(r);
-                existing.clearResult(querySupport);
-                existing.setPending();
+                existing.setPending(querySupport);
                 readEntryMap.put(id(r), existing);
                 size++;
                 return existing;
             }
             if(existing.requiresComputation()) {
-                existing.setPending();
+                existing.setPending(querySupport);
                 return existing;
             }
         }
         if(existing.isPending()) {
-            if(needsToBlock) waitPending(graph, existing);
-            else return null;
+          if(needsToBlock)
+            waitPending(graph, existing);
+          else {
+            return null;
+          }
         }
         return existing;
     }
-
     
     void remove(ReadEntry entry) {
         synchronized(readEntryMap) {
-            readEntryMap.remove(entry.request);
+            readEntryMap.remove(entry.id);
         }
     }
     
-    public static Object runnerReadEntry(ReadGraphImpl graph, Read<?> r, CacheEntry parent, ListenerBase listener, final AsyncProcedure procedure, final boolean needsToBlock) throws DatabaseException {
+    public static Object runnerReadEntry(ReadGraphImpl graph, Read<?> r, CacheEntry parent, ListenerBase listener, final AsyncProcedure procedure, boolean needsToBlock) throws DatabaseException {
         QueryCache cache  = graph.processor.cache;
         if(parent == null && listener == null && !cache.shouldCache(graph.processor, r)) {
             if (SINGLE) {
@@ -636,33 +646,32 @@ public class QueryCache extends QueryCacheBase {
                     return e.performFromCache(graph, procedure);
                 }
             }
-            return ReadEntry.computeForEach(graph, r, null, procedure);
+            return ReadEntry.computeForEach(graph, r, null, procedure, needsToBlock);
         }
         ReadEntry entry = (ReadEntry)cache.getOrCreateReadEntry(graph, r, needsToBlock);
         if(entry == null) {
-            graph.processor.schedule(new SessionTask(graph) {
-                @Override
-                public void run0(int thread) {
-                    try {
-                        runnerReadEntry(graph, r, parent, listener, procedure, needsToBlock);
-                    } catch (DatabaseException e) {
-                        Logger.defaultLogError(e);
-                    }
-                }
-            });
-            return null;
+          graph.processor.schedule(new SessionTask(graph) {
+            @Override
+            public void run0(int thread) {
+              try {
+                runnerReadEntry(graph, r, parent, listener, procedure, needsToBlock);
+              } catch (DatabaseException e) {
+                Logger.defaultLogError(e);
+              }
+            }
+          });
+          return null;
         }
         AsyncProcedure procedure_ = procedure != null ? procedure : emptyProcedureReadEntry;
         ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);
         if(entry.isReady()) return entry.performFromCache(graph, procedure_);
         else {
           assert(entry.isPending());
-          Object result = ReadEntry.computeForEach(graph, r, entry, procedure_);
+          Object result = ReadEntry.computeForEach(graph, r, entry, procedure_, needsToBlock);
           if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());
           return result;
         }
     }
-
     
     private ReadEntry peekReadEntry(Read<?> r) {
         synchronized(readEntryMap) {
@@ -676,32 +685,33 @@ public class QueryCache extends QueryCacheBase {
             existing = (AsyncReadEntry)asyncReadEntryMap.get(r);
             if(existing == null) {
                 existing = new AsyncReadEntry(r);
-                existing.clearResult(querySupport);
-                existing.setPending();
+                existing.setPending(querySupport);
                 asyncReadEntryMap.put(id(r), existing);
                 size++;
                 return existing;
             }
             if(existing.requiresComputation()) {
-                existing.setPending();
+                existing.setPending(querySupport);
                 return existing;
             }
         }
         if(existing.isPending()) {
-            if(needsToBlock) waitPending(graph, existing);
-            else return null;
+          if(needsToBlock)
+            waitPending(graph, existing);
+          else {
+            return null;
+          }
         }
         return existing;
     }
-
     
     void remove(AsyncReadEntry entry) {
         synchronized(asyncReadEntryMap) {
-            asyncReadEntryMap.remove(entry.request);
+            asyncReadEntryMap.remove(entry.id);
         }
     }
     
-    public static Object runnerAsyncReadEntry(ReadGraphImpl graph, AsyncRead<?> r, CacheEntry parent, ListenerBase listener, final AsyncProcedure procedure, final boolean needsToBlock) throws DatabaseException {
+    public static Object runnerAsyncReadEntry(ReadGraphImpl graph, AsyncRead<?> r, CacheEntry parent, ListenerBase listener, final AsyncProcedure procedure, boolean needsToBlock) throws DatabaseException {
         QueryCache cache  = graph.processor.cache;
         if(parent == null && listener == null && !cache.shouldCache(graph.processor, r)) {
             if (SINGLE) {
@@ -714,17 +724,17 @@ public class QueryCache extends QueryCacheBase {
         }
         AsyncReadEntry entry = (AsyncReadEntry)cache.getOrCreateAsyncReadEntry(graph, r, needsToBlock);
         if(entry == null) {
-            graph.processor.schedule(new SessionTask(graph) {
-                @Override
-                public void run0(int thread) {
-                    try {
-                        runnerAsyncReadEntry(graph, r, parent, listener, procedure, needsToBlock);
-                    } catch (DatabaseException e) {
-                        Logger.defaultLogError(e);
-                    }
-                }
-            });
-            return null;
+          graph.processor.schedule(new SessionTask(graph) {
+            @Override
+            public void run0(int thread) {
+              try {
+                runnerAsyncReadEntry(graph, r, parent, listener, procedure, needsToBlock);
+              } catch (DatabaseException e) {
+                Logger.defaultLogError(e);
+              }
+            }
+          });
+          return null;
         }
         AsyncProcedure procedure_ = procedure != null ? procedure : emptyProcedureAsyncReadEntry;
         ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);
@@ -736,7 +746,6 @@ public class QueryCache extends QueryCacheBase {
           return result;
         }
     }
-
     
     private AsyncReadEntry peekAsyncReadEntry(AsyncRead<?> r) {
         synchronized(asyncReadEntryMap) {
@@ -750,18 +759,19 @@ public class QueryCache extends QueryCacheBase {
             existing = (Types)typesMap.get(r);
             if(existing == null) {
                 existing = new Types(r);
-                existing.clearResult(querySupport);
-                existing.setPending();
+                existing.setPending(querySupport);
                 typesMap.put(keyR(r), existing);
                 size++;
                 return existing;
             }
             if(existing.requiresComputation()) {
-                existing.setPending();
+                existing.setPending(querySupport);
                 return existing;
             }
         }
-        if(existing.isPending()) waitPending(graph, existing);
+        if(existing.isPending()) {
+          waitPending(graph, existing);
+        }
         return existing;
     }
     
@@ -807,18 +817,19 @@ public class QueryCache extends QueryCacheBase {
             existing = (ChildMap)childMapMap.get(r);
             if(existing == null) {
                 existing = new ChildMap(r);
-                existing.clearResult(querySupport);
-                existing.setPending();
+                existing.setPending(querySupport);
                 childMapMap.put(keyR(r), existing);
                 size++;
                 return existing;
             }
             if(existing.requiresComputation()) {
-                existing.setPending();
+                existing.setPending(querySupport);
                 return existing;
             }
         }
-        if(existing.isPending()) waitPending(graph, existing);
+        if(existing.isPending()) {
+          waitPending(graph, existing);
+        }
         return existing;
     }
     
@@ -864,18 +875,19 @@ public class QueryCache extends QueryCacheBase {
             existing = (TypeHierarchy)typeHierarchyMap.get(r);
             if(existing == null) {
                 existing = new TypeHierarchy(r);
-                existing.clearResult(querySupport);
-                existing.setPending();
+                existing.setPending(querySupport);
                 typeHierarchyMap.put(keyR(r), existing);
                 size++;
                 return existing;
             }
             if(existing.requiresComputation()) {
-                existing.setPending();
+                existing.setPending(querySupport);
                 return existing;
             }
         }
-        if(existing.isPending()) waitPending(graph, existing);
+        if(existing.isPending()) {
+          waitPending(graph, existing);
+        }
         return existing;
     }
     
@@ -921,18 +933,19 @@ public class QueryCache extends QueryCacheBase {
             existing = (SuperTypes)superTypesMap.get(r);
             if(existing == null) {
                 existing = new SuperTypes(r);
-                existing.clearResult(querySupport);
-                existing.setPending();
+                existing.setPending(querySupport);
                 superTypesMap.put(keyR(r), existing);
                 size++;
                 return existing;
             }
             if(existing.requiresComputation()) {
-                existing.setPending();
+                existing.setPending(querySupport);
                 return existing;
             }
         }
-        if(existing.isPending()) waitPending(graph, existing);
+        if(existing.isPending()) {
+          waitPending(graph, existing);
+        }
         return existing;
     }
     
@@ -978,18 +991,19 @@ public class QueryCache extends QueryCacheBase {
             existing = (SuperRelations)superRelationsMap.get(r);
             if(existing == null) {
                 existing = new SuperRelations(r);
-                existing.clearResult(querySupport);
-                existing.setPending();
+                existing.setPending(querySupport);
                 superRelationsMap.put(keyR(r), existing);
                 size++;
                 return existing;
             }
             if(existing.requiresComputation()) {
-                existing.setPending();
+                existing.setPending(querySupport);
                 return existing;
             }
         }
-        if(existing.isPending()) waitPending(graph, existing);
+        if(existing.isPending()) {
+          waitPending(graph, existing);
+        }
         return existing;
     }
     
@@ -1035,18 +1049,19 @@ public class QueryCache extends QueryCacheBase {
             existing = (AssertedPredicates)assertedPredicatesMap.get(r);
             if(existing == null) {
                 existing = new AssertedPredicates(r);
-                existing.clearResult(querySupport);
-                existing.setPending();
+                existing.setPending(querySupport);
                 assertedPredicatesMap.put(keyR(r), existing);
                 size++;
                 return existing;
             }
             if(existing.requiresComputation()) {
-                existing.setPending();
+                existing.setPending(querySupport);
                 return existing;
             }
         }
-        if(existing.isPending()) waitPending(graph, existing);
+        if(existing.isPending()) {
+          waitPending(graph, existing);
+        }
         return existing;
     }
     
@@ -1081,18 +1096,19 @@ public class QueryCache extends QueryCacheBase {
             existing = (AssertedStatements)assertedStatementsMap.get(r1,r2);
             if(existing == null) {
                 existing = new AssertedStatements(r1,r2);
-                existing.clearResult(querySupport);
-                existing.setPending();
+                existing.setPending(querySupport);
                 assertedStatementsMap.put(keyR2(r1,r2), existing);
                 size++;
                 return existing;
             }
             if(existing.requiresComputation()) {
-                existing.setPending();
+                existing.setPending(querySupport);
                 return existing;
             }
         }
-        if(existing.isPending()) waitPending(graph, existing);
+        if(existing.isPending()) {
+          waitPending(graph, existing);
+        }
         return existing;
     }
     
@@ -1127,18 +1143,19 @@ public class QueryCache extends QueryCacheBase {
             existing = (DirectSuperRelations)directSuperRelationsMap.get(r);
             if(existing == null) {
                 existing = new DirectSuperRelations(r);
-                existing.clearResult(querySupport);
-                existing.setPending();
+                existing.setPending(querySupport);
                 directSuperRelationsMap.put(keyR(r), existing);
                 size++;
                 return existing;
             }
             if(existing.requiresComputation()) {
-                existing.setPending();
+                existing.setPending(querySupport);
                 return existing;
             }
         }
-        if(existing.isPending()) waitPending(graph, existing);
+        if(existing.isPending()) {
+          waitPending(graph, existing);
+        }
         return existing;
     }
     
@@ -1173,24 +1190,25 @@ public class QueryCache extends QueryCacheBase {
             existing = (MultiReadEntry)multiReadEntryMap.get(r);
             if(existing == null) {
                 existing = new MultiReadEntry(r);
-                existing.clearResult(querySupport);
-                existing.setPending();
+                existing.setPending(querySupport);
                 multiReadEntryMap.put(id(r), existing);
                 size++;
                 return existing;
             }
             if(existing.requiresComputation()) {
-                existing.setPending();
+                existing.setPending(querySupport);
                 return existing;
             }
         }
-        if(existing.isPending()) waitPending(graph, existing);
+        if(existing.isPending()) {
+          waitPending(graph, existing);
+        }
         return existing;
     }
     
     void remove(MultiReadEntry entry) {
         synchronized(multiReadEntryMap) {
-            multiReadEntryMap.remove(entry.request);
+            multiReadEntryMap.remove(entry.id);
         }
     }
     
@@ -1219,24 +1237,25 @@ public class QueryCache extends QueryCacheBase {
             existing = (AsyncMultiReadEntry)asyncMultiReadEntryMap.get(r);
             if(existing == null) {
                 existing = new AsyncMultiReadEntry(r);
-                existing.clearResult(querySupport);
-                existing.setPending();
+                existing.setPending(querySupport);
                 asyncMultiReadEntryMap.put(id(r), existing);
                 size++;
                 return existing;
             }
             if(existing.requiresComputation()) {
-                existing.setPending();
+                existing.setPending(querySupport);
                 return existing;
             }
         }
-        if(existing.isPending()) waitPending(graph, existing);
+        if(existing.isPending()) {
+          waitPending(graph, existing);
+        }
         return existing;
     }
     
     void remove(AsyncMultiReadEntry entry) {
         synchronized(asyncMultiReadEntryMap) {
-            asyncMultiReadEntryMap.remove(entry.request);
+            asyncMultiReadEntryMap.remove(entry.id);
         }
     }
     
@@ -1265,25 +1284,25 @@ public class QueryCache extends QueryCacheBase {
             existing = (ExternalReadEntry)externalReadEntryMap.get(r);
             if(existing == null) {
                 existing = new ExternalReadEntry(r, graph);
-                existing.clearResult(querySupport);
-                existing.setPending();
+                existing.setPending(querySupport);
                 externalReadEntryMap.put(id(r), existing);
                 size++;
                 return existing;
             }
             if(existing.requiresComputation()) {
-                existing.setPending();
+                existing.setPending(querySupport);
                 return existing;
             }
         }
-        if(existing.isPending()) waitPending(graph, existing);
+        if(existing.isPending()) {
+          waitPending(graph, existing);
+        }
         return existing;
     }
-
     
     void remove(ExternalReadEntry entry) {
         synchronized(externalReadEntryMap) {
-            externalReadEntryMap.remove(entry.request);
+            externalReadEntryMap.remove(entry.id);
         }
     }
     
index 6db4726ac4de7eb859327b873f17dfdc6cddfaed..c2b21444fd17157753d2cfc303bd8b4932a488fa 100644 (file)
@@ -131,7 +131,7 @@ abstract public class QueryIdentityHash extends THash {
         }
 
         @Override
-        public void setPending() {
+        public void setPending(QuerySupport querySupport) {
             // TODO Auto-generated method stub
             
         }
index 7743907202eb8fbf54fd584330e3dc84fcdfac16..9b54d15f6996fbf708a5fce9fc5ea00fd467e0ba 100644 (file)
@@ -1266,11 +1266,11 @@ final public class QueryProcessor extends AbstractDisposable implements ReadGrap
 
                for(CacheEntry entry : workarea.keySet()) {
                        Class<?> clazz = entry.getClass();
-                       if(entry instanceof ReadEntry) clazz = ((ReadEntry)entry).request.getClass(); 
-                       else if(entry instanceof MultiReadEntry) clazz = ((MultiReadEntry)entry).request.getClass(); 
-                       else if(entry instanceof AsyncReadEntry) clazz = ((AsyncReadEntry)entry).request.getClass(); 
-                       else if(entry instanceof AsyncMultiReadEntry) clazz = ((AsyncMultiReadEntry)entry).request.getClass(); 
-                       else if(entry instanceof ExternalReadEntry) clazz = ((ExternalReadEntry)entry).request.getClass(); 
+                       if(entry instanceof ReadEntry) clazz = ((ReadEntry)entry).id.getClass(); 
+                       else if(entry instanceof MultiReadEntry) clazz = ((MultiReadEntry)entry).id.getClass(); 
+                       else if(entry instanceof AsyncReadEntry) clazz = ((AsyncReadEntry)entry).id.getClass(); 
+                       else if(entry instanceof AsyncMultiReadEntry) clazz = ((AsyncMultiReadEntry)entry).id.getClass(); 
+                       else if(entry instanceof ExternalReadEntry) clazz = ((ExternalReadEntry)entry).id.getClass(); 
                        Integer c = counts.get(clazz);
                        if(c == null) counts.put(clazz, -1);
                        else counts.put(clazz, c-1);
@@ -1452,17 +1452,17 @@ final public class QueryProcessor extends AbstractDisposable implements ReadGrap
                        return false;
                }
 
-               if (entry.isRefuted()) {
-                       if (Development.DEVELOPMENT) {
-                               if(Development.<Boolean>getProperty(DevelopmentKeys.QUERYPROCESSOR_UPDATE, Bindings.BOOLEAN)) {
-                                       System.err.print("R");
-                                       for (int i = 0; i < e.indent; i++)
-                                               System.err.print(" ");
-                                       System.err.println(entry.getQuery());
-                               }
-                       }
-                       return false;
-               }
+//             if (entry.isRefuted()) {
+//                     if (Development.DEVELOPMENT) {
+//                             if(Development.<Boolean>getProperty(DevelopmentKeys.QUERYPROCESSOR_UPDATE, Bindings.BOOLEAN)) {
+//                                     System.err.print("R");
+//                                     for (int i = 0; i < e.indent; i++)
+//                                             System.err.print(" ");
+//                                     System.err.println(entry.getQuery());
+//                             }
+//                     }
+//                     return false;
+//             }
 
                if (entry.isExcepted()) {
                        if (Development.DEVELOPMENT) {
@@ -1851,6 +1851,22 @@ final public class QueryProcessor extends AbstractDisposable implements ReadGrap
        private Object primitiveUpdateLock = new Object();
        private THashSet scheduledPrimitiveUpdates = new THashSet();
 
+       private ArrayList<CacheEntry> refutations = new ArrayList<>();
+       
+       private void markForUpdate(ReadGraphImpl graph, CacheEntry e) {
+               e.refute();
+               refutations.add(e);
+       }
+
+       private void updateRefutations(ReadGraphImpl graph) {
+               
+               for(CacheEntry e : refutations)
+                       update(graph, e);
+               
+               refutations.clear();
+               
+       }
+       
        public void performDirtyUpdates(final ReadGraphImpl graph) {
 
                cache.dirty = false;
@@ -1870,28 +1886,37 @@ final public class QueryProcessor extends AbstractDisposable implements ReadGrap
                        final int subject = (int)(arg0 >>> 32);
                        final int predicate = (int)(arg0 & 0xffffffff);
 
-                       for(Objects o : QueryCache.entriesObjects(QueryProcessor.this, subject)) update(graph, o);
-                       for(DirectObjects o : QueryCache.entriesDirectObjects(QueryProcessor.this, subject)) update(graph, o);
-                       for(Statements o : QueryCache.entriesStatements(QueryProcessor.this, subject)) update(graph, o);
+                       for(Objects o : QueryCache.entriesObjects(QueryProcessor.this, subject)) markForUpdate(graph, o);
+                       for(DirectObjects o : QueryCache.entriesDirectObjects(QueryProcessor.this, subject)) markForUpdate(graph, o);
+                       for(Statements o : QueryCache.entriesStatements(QueryProcessor.this, subject)) markForUpdate(graph, o);
 
                        if(predicate == instanceOf || predicate == inherits || predicate == subrelationOf) {
                                PrincipalTypes principalTypes = QueryCache.entryPrincipalTypes(QueryProcessor.this, subject);
-                               if(principalTypes != null) update(graph, principalTypes);
+                               if(principalTypes != null) markForUpdate(graph, principalTypes);
                                Types types = QueryCache.entryTypes(QueryProcessor.this, subject);
-                               if(types != null) update(graph, types);
+                               if(types != null) markForUpdate(graph, types);
                        }
 
                        if(predicate == subrelationOf) {
                                SuperRelations superRelations = SuperRelations.entry(QueryProcessor.this, subject);
-                               if(superRelations != null) update(graph, superRelations);
+                               if(superRelations != null) markForUpdate(graph, superRelations);
                        }
 
                        DirectPredicates dp = QueryCache.entryDirectPredicates(QueryProcessor.this, subject);
-                       if(dp != null) update(graph, dp);
+                       if(dp != null) markForUpdate(graph, dp);
                        OrderedSet os = QueryCache.entryOrderedSet(QueryProcessor.this, predicate);
-                       if(os != null) update(graph, os);
+                       if(os != null) markForUpdate(graph, os);
 
+                       updateRefutations(graph);
+                       
                        scheduledObjectUpdates.clear();
+
+                       if (Development.DEVELOPMENT) {
+                               if(Development.<Boolean>getProperty(DevelopmentKeys.QUERYPROCESSOR_UPDATE, Bindings.BOOLEAN)) {
+                                       System.err.println("== Query update ends ==");
+                               }
+                       }
+
                        return;
 
                }
@@ -1902,9 +1927,18 @@ final public class QueryProcessor extends AbstractDisposable implements ReadGrap
                        int arg0 = scheduledValueUpdates.getFirst();
 
                        ValueQuery valueQuery = QueryCache.entryValueQuery(QueryProcessor.this, arg0);
-                       if(valueQuery != null) update(graph, valueQuery);
+                       if(valueQuery != null) markForUpdate(graph, valueQuery);
+
+                       updateRefutations(graph);
 
                        scheduledValueUpdates.clear();
+
+                       if (Development.DEVELOPMENT) {
+                               if(Development.<Boolean>getProperty(DevelopmentKeys.QUERYPROCESSOR_UPDATE, Bindings.BOOLEAN)) {
+                                       System.err.println("== Query update ends ==");
+                               }
+                       }
+                       
                        return;
 
                }
@@ -1918,30 +1952,12 @@ final public class QueryProcessor extends AbstractDisposable implements ReadGrap
                        scheduledPrimitiveUpdates = new THashSet();
                }
 
-               primitiveUpdates.forEach(new TObjectProcedure() {
-
-                       @Override
-                       public boolean execute(Object arg0) {
-
-                               ExternalReadEntry query = (ExternalReadEntry)cache.externalReadEntryMap.get(arg0);
-                               if (query != null) {
-                                       boolean listening = update(graph, query);
-                                       if (!listening && !query.hasParents()) {
-                                               cache.externalReadEntryMap.remove(arg0);
-                                               query.discard();
-                                       }
-                               }
-                               return true;
-                       }
-
-               });
-
                scheduledValueUpdates.forEach(new TIntProcedure() {
 
                        @Override
                        public boolean execute(int arg0) {
                                ValueQuery valueQuery = QueryCache.entryValueQuery(QueryProcessor.this, arg0);
-                               if(valueQuery != null) update(graph, valueQuery);
+                               if(valueQuery != null) markForUpdate(graph, valueQuery);
                                return true;
                        }
 
@@ -1953,15 +1969,15 @@ final public class QueryProcessor extends AbstractDisposable implements ReadGrap
                        public boolean execute(int resource) {
                                
                                ValueQuery valueQuery = QueryCache.entryValueQuery(QueryProcessor.this, resource);
-                               if(valueQuery != null) update(graph, valueQuery);
+                               if(valueQuery != null) markForUpdate(graph, valueQuery);
                                
                                PrincipalTypes principalTypes = QueryCache.entryPrincipalTypes(QueryProcessor.this, resource);
-                               if(principalTypes != null) update(graph, principalTypes);
+                               if(principalTypes != null) markForUpdate(graph, principalTypes);
                                Types types = QueryCache.entryTypes(QueryProcessor.this, resource);
-                               if(types != null) update(graph, types);
+                               if(types != null) markForUpdate(graph, types);
 
                                SuperRelations superRelations = SuperRelations.entry(QueryProcessor.this, resource);
-                               if(superRelations != null) update(graph, superRelations);
+                               if(superRelations != null) markForUpdate(graph, superRelations);
 
                                predicates.add(resource);
                                
@@ -1980,14 +1996,14 @@ final public class QueryProcessor extends AbstractDisposable implements ReadGrap
 
                                if(predicate == instanceOf || predicate == inherits || predicate == subrelationOf) {
                                        PrincipalTypes principalTypes = QueryCache.entryPrincipalTypes(QueryProcessor.this, subject);
-                                       if(principalTypes != null) update(graph, principalTypes);
+                                       if(principalTypes != null) markForUpdate(graph, principalTypes);
                                        Types types = QueryCache.entryTypes(QueryProcessor.this, subject);
-                                       if(types != null) update(graph, types);
+                                       if(types != null) markForUpdate(graph, types);
                                }
 
                                if(predicate == subrelationOf) {
                                        SuperRelations superRelations = SuperRelations.entry(QueryProcessor.this, subject);
-                                       if(superRelations != null) update(graph, superRelations);
+                                       if(superRelations != null) markForUpdate(graph, superRelations);
                                }
 
                                predicates.add(subject);
@@ -2004,12 +2020,12 @@ final public class QueryProcessor extends AbstractDisposable implements ReadGrap
                        @Override
                        public boolean execute(final int subject) {
 
-                               for(Objects o : QueryCache.entriesObjects(QueryProcessor.this, subject)) update(graph, o);
-                               for(DirectObjects o : QueryCache.entriesDirectObjects(QueryProcessor.this, subject)) update(graph, o);
-                               for(Statements o : QueryCache.entriesStatements(QueryProcessor.this, subject)) update(graph, o);
+                               for(Objects o : QueryCache.entriesObjects(QueryProcessor.this, subject)) markForUpdate(graph, o);
+                               for(DirectObjects o : QueryCache.entriesDirectObjects(QueryProcessor.this, subject)) markForUpdate(graph, o);
+                               for(Statements o : QueryCache.entriesStatements(QueryProcessor.this, subject)) markForUpdate(graph, o);
 
                                DirectPredicates entry = QueryCache.entryDirectPredicates(QueryProcessor.this, subject);
-                               if(entry != null) update(graph, entry);
+                               if(entry != null) markForUpdate(graph, entry);
 
                                return true;
 
@@ -2023,7 +2039,7 @@ final public class QueryProcessor extends AbstractDisposable implements ReadGrap
                        public boolean execute(int orderedSet) {
 
                                OrderedSet entry = QueryCache.entryOrderedSet(QueryProcessor.this, orderedSet);
-                               if(entry != null) update(graph, entry);
+                               if(entry != null) markForUpdate(graph, entry);
 
                                return true;
 
@@ -2031,21 +2047,35 @@ final public class QueryProcessor extends AbstractDisposable implements ReadGrap
 
                });
 
-               //              for (Integer subject : predicates) {
-               //                      DirectPredicates entry = DirectPredicates.entry(QueryProcessor.this, subject);
-               //                      if(entry != null) update(graph, entry);
-               //              }
+               updateRefutations(graph);
 
+               primitiveUpdates.forEach(new TObjectProcedure() {
 
-               if (Development.DEVELOPMENT) {
-                       if(Development.<Boolean>getProperty(DevelopmentKeys.QUERYPROCESSOR_UPDATE, Bindings.BOOLEAN)) {
-                               System.err.println("== Query update ends ==");
+                       @Override
+                       public boolean execute(Object arg0) {
+
+                               ExternalReadEntry query = (ExternalReadEntry)cache.externalReadEntryMap.get(arg0);
+                               if (query != null) {
+                                       boolean listening = update(graph, query);
+                                       if (!listening && !query.hasParents()) {
+                                               cache.externalReadEntryMap.remove(arg0);
+                                               query.discard();
+                                       }
+                               }
+                               return true;
                        }
-               }
 
+               });
+               
                scheduledValueUpdates.clear();
                scheduledObjectUpdates.clear();
                scheduledInvalidates.clear();
+               
+               if (Development.DEVELOPMENT) {
+                       if(Development.<Boolean>getProperty(DevelopmentKeys.QUERYPROCESSOR_UPDATE, Bindings.BOOLEAN)) {
+                               System.err.println("== Query update ends ==");
+                       }
+               }
 
        }
 
index 1ceca45a5a0cec7371f632941a13b3c1610fc60a..72f132288bf79990c5bf56ce591463993ccd8acd 100644 (file)
@@ -25,20 +25,20 @@ public final class ReadEntry<T> extends CacheEntryBase<AsyncProcedure<T>> implem
 
     private static final Logger LOGGER = LoggerFactory.getLogger(ReadEntry.class);
 
-    protected Read<T> request;
+    protected Read<T> id;
 
     public ReadEntry(Read<T> request) {
-        this.request = request;
+        this.id = request;
     }
 
     @Override
     int makeHash() {
-        return request.hashCode();
+        return id.hashCode();
     }
 
     @Override
     public Object getOriginalRequest() {
-        return request;
+        return id;
     }
 
     @Override
@@ -57,7 +57,7 @@ public final class ReadEntry<T> extends CacheEntryBase<AsyncProcedure<T>> implem
 
                 try {
 
-                    T result = request.perform(graph);
+                    T result = id.perform(graph);
                     setResult(result);
                     setReady();
 
@@ -76,8 +76,8 @@ public final class ReadEntry<T> extends CacheEntryBase<AsyncProcedure<T>> implem
 
             @Override
             public int type() {
-                if (request instanceof ReadExt) {
-                    return ((ReadExt) request).getType();
+                if (id instanceof ReadExt) {
+                    return ((ReadExt) id).getType();
                 } else {
                     return RequestFlags.INVALIDATE;
                 }
@@ -85,10 +85,10 @@ public final class ReadEntry<T> extends CacheEntryBase<AsyncProcedure<T>> implem
 
             @Override
             public String toString() {
-                if (request == null)
+                if (id == null)
                     return "DISCARDED";
                 else
-                    return request.toString() + statusOrException;
+                    return id.toString() + statusOrException;
             }
 
         };
@@ -96,7 +96,7 @@ public final class ReadEntry<T> extends CacheEntryBase<AsyncProcedure<T>> implem
     }
 
     public static <T> T computeForEach(ReadGraphImpl graph, Read<T> request, ReadEntry<T> entry,
-            AsyncProcedure<T> procedure_) throws DatabaseException {
+            AsyncProcedure<T> procedure_, boolean needsToBlock) throws DatabaseException {
 
         AsyncProcedure<T> procedure = entry != null ? entry : procedure_;
 
@@ -181,10 +181,10 @@ public final class ReadEntry<T> extends CacheEntryBase<AsyncProcedure<T>> implem
 
     @Override
     public String toString() {
-        if (request == null)
+        if (id == null)
             return "DISCARDED";
         else
-            return request.toString() + " - " + statusOrException;
+            return id.toString() + " - " + statusOrException;
     }
 
     public Object get(ReadGraphImpl graph, AsyncProcedure<T> procedure) throws DatabaseException {
@@ -196,8 +196,8 @@ public final class ReadEntry<T> extends CacheEntryBase<AsyncProcedure<T>> implem
 
     @Override
     boolean isImmutable(ReadGraphImpl graph) throws DatabaseException {
-        if (request instanceof ReadExt) {
-            return ((ReadExt) request).isImmutable(graph);
+        if (id instanceof ReadExt) {
+            return ((ReadExt) id).isImmutable(graph);
         }
         return false;
     }