]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Multiple simultaneous readers 75/1675/1
authorAntti Villberg <antti.villberg@semantum.fi>
Tue, 3 Apr 2018 07:15:13 +0000 (10:15 +0300)
committerAntti Villberg <antti.villberg@semantum.fi>
Tue, 3 Apr 2018 07:15:13 +0000 (10:15 +0300)
refs #6961

Change-Id: If2374874965c23d07a2fbe1f0075c515e1e12d5c

12 files changed:
bundles/org.simantics.db.common/src/org/simantics/db/common/primitiverequest/IsInstanceOf.java
bundles/org.simantics.db.common/src/org/simantics/db/common/request/PossibleTypedParent.java
bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/ReadGraphImpl.java
bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/ReadGraphSupport.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/CodeGen.java
bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/NamespaceIndex.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/QueryCacheBase.java
bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryProcessor.java
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/genericrelation/ExternalRequest.java
bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/SessionImplSocket.java

index 63a5ddcb3293f2fa34f72e118d123dce341e4cc0..d121839ed47e9cc0ea5e63ae68cc34291da2cfc4 100644 (file)
  *******************************************************************************/
 package org.simantics.db.common.primitiverequest;
 
-import org.simantics.db.AsyncReadGraph;
+import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
-import org.simantics.db.common.request.ResourceAsyncRead2;
-import org.simantics.db.procedure.AsyncProcedure;
+import org.simantics.db.common.request.ResourceRead2;
+import org.simantics.db.exception.DatabaseException;
 
-final public class IsInstanceOf extends ResourceAsyncRead2<Boolean> {
+final public class IsInstanceOf extends ResourceRead2<Boolean> {
 
     public IsInstanceOf(Resource resource, Resource resource2) {
         super(resource, resource2);
     }
 
-    @Override
-    public void perform(AsyncReadGraph graph, AsyncProcedure<Boolean> procedure) {
-        graph.forIsInstanceOf(resource, resource2, procedure);
-    }
+       @Override
+       public Boolean perform(ReadGraph graph) throws DatabaseException {
+               return graph.isInstanceOf(resource2, resource2);
+       }
 
 }
index 668791821c7320927fb50c3e785537bf70422783..bae974e3ed235fdd490939699a4f2ab4c283b6a1 100644 (file)
 package org.simantics.db.common.request;
 
 import org.simantics.db.AsyncReadGraph;
+import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.procedure.AsyncProcedure;
 import org.simantics.layer0.Layer0;
 
-public class PossibleTypedParent extends ResourceAsyncRead2<Resource> {
+public class PossibleTypedParent extends ResourceRead2<Resource> {
 
        public PossibleTypedParent(Resource resource, Resource type) {
                super(resource, type);
        }
 
-       @Override
-       public void perform(AsyncReadGraph graph, final AsyncProcedure<Resource> procedure) {
-
-           final Layer0 l0 = graph.getService(Layer0.class);
-
-               graph.forIsInstanceOf(resource, resource2, new AsyncProcedure<Boolean>() {
-
-                       @Override
-                       public void execute(AsyncReadGraph graph, Boolean isInstance) {
-                               if(isInstance) {
-                                       procedure.execute(graph, resource);
-                               } else {
-                                       
-                                       graph.forPossibleObject(resource, l0.PartOf, new AsyncProcedure<Resource>() {
-
-                                               @Override
-                                               public void execute(AsyncReadGraph graph, final Resource parent) {
 
-                                                       if(parent == null) {
-                                                               procedure.execute(graph, null);
-                                                       } else {
-                                                               graph.asyncRequest(new PossibleTypedParent(parent, resource2), procedure);
-                                                       }
-                                                       
-                                               }
-
-                                               @Override
-                                               public void exception(AsyncReadGraph graph, Throwable throwable) {
-                                                       procedure.exception(graph, throwable);
-                                               }
-                                               
-                                       });
-                                       
-                               }
-                       }
-
-                       @Override
-                       public void exception(AsyncReadGraph graph, Throwable throwable) {
-                               procedure.exception(graph, throwable);
+       @Override
+       public Resource perform(ReadGraph graph) throws DatabaseException {
+               if(graph.isInstanceOf(resource, resource2)) {
+                       return resource;
+               } else {
+                       Layer0 L0 = Layer0.getInstance(graph);
+                       Resource possibleParent = graph.getPossibleObject(resource, L0.PartOf);
+                       if(possibleParent != null) {
+                               return graph.syncRequest(new PossibleTypedParent(possibleParent, resource2));
+                       } else {
+                               return null;    
                        }
-               });
-               
-               
+               }
        }
 
+//     @Override
+//     public void perform(AsyncReadGraph graph, final AsyncProcedure<Resource> procedure) {
+//
+//         final Layer0 l0 = graph.getService(Layer0.class);
+//
+//             graph.forIsInstanceOf(resource, resource2, new AsyncProcedure<Boolean>() {
+//
+//                     @Override
+//                     public void execute(AsyncReadGraph graph, Boolean isInstance) {
+//                             if(isInstance) {
+//                                     procedure.execute(graph, resource);
+//                             } else {
+//                                     
+//                                     graph.forPossibleObject(resource, l0.PartOf, new AsyncProcedure<Resource>() {
+//
+//                                             @Override
+//                                             public void execute(AsyncReadGraph graph, final Resource parent) {
+//
+//                                                     if(parent == null) {
+//                                                             procedure.execute(graph, null);
+//                                                     } else {
+//                                                             graph.asyncRequest(new PossibleTypedParent(parent, resource2), procedure);
+//                                                     }
+//                                                     
+//                                             }
+//
+//                                             @Override
+//                                             public void exception(AsyncReadGraph graph, Throwable throwable) {
+//                                                     procedure.exception(graph, throwable);
+//                                             }
+//                                             
+//                                     });
+//                                     
+//                             }
+//                     }
+//
+//                     @Override
+//                     public void exception(AsyncReadGraph graph, Throwable throwable) {
+//                             procedure.exception(graph, throwable);
+//                     }
+//             });
+//             
+//             
+//     }
+
 }
index 3337e55b8455d88dd760efbfc19fe0df08e31a50..25438ef1ef3f0d57878c32c3c03def4111c8ca0c 100644 (file)
@@ -137,6 +137,7 @@ import org.simantics.db.impl.procedure.CallWrappedSingleQueryProcedure4;
 import org.simantics.db.impl.procedure.ResultCallWrappedQueryProcedure4;
 import org.simantics.db.impl.procedure.ResultCallWrappedSingleQueryProcedure4;
 import org.simantics.db.impl.query.CacheEntry;
+import org.simantics.db.impl.query.QueryCache;
 import org.simantics.db.impl.query.QueryProcessor;
 import org.simantics.db.impl.query.QuerySupport;
 import org.simantics.db.impl.query.TripleIntProcedure;
@@ -1896,7 +1897,9 @@ public class ReadGraphImpl implements ReadGraph {
 
                assert (request != null);
 
-               return processor.query(this, request, parent, null, null);
+               return QueryCache.resultReadEntry(this, request, parent, null, null);
+               
+               //return processor.query(this, request, parent, null, null);
 
 //             if (parent != null) {
 //
@@ -1948,7 +1951,9 @@ public class ReadGraphImpl implements ReadGraph {
 
                ListenerBase listener = procedure != null ? getListenerBase(procedure) : null;
 
-        return processor.query(this, request, parent, procedure, listener);
+               return QueryCache.resultReadEntry(this, request, parent, listener, procedure);
+               
+//        return processor.query(this, request, parent, procedure, listener);
         
 
 //             if (parent != null || listener != null) {
@@ -2079,7 +2084,9 @@ public class ReadGraphImpl implements ReadGraph {
                final ResultCallWrappedSingleQueryProcedure4<T> wrapper = new ResultCallWrappedSingleQueryProcedure4<T>(
                                procedure, request);
                
-               processor.query(this, request, parent, wrapper, listener);
+               QueryCache.runnerAsyncReadEntry(this, request, parent, listener, wrapper);
+               
+               //processor.query(this, request, parent, wrapper, listener);
                
                return wrapper.getResult();
 
@@ -2147,35 +2154,12 @@ public class ReadGraphImpl implements ReadGraph {
                assert (request != null);
 
                ListenerBase listener = getListenerBase(procedure);
+               assert(listener == null);
 
-               final ResultCallWrappedSingleQueryProcedure4<T> wrapper = new ResultCallWrappedSingleQueryProcedure4<T>(
-                               procedure, request);
-
-               processor.query(this, request, parent, wrapper, listener);
+//             final ResultCallWrappedSingleQueryProcedure4<T> wrapper = new ResultCallWrappedSingleQueryProcedure4<T>(
+//                             procedure, request);
 
-//             if (parent != null || listener != null || ((request.getFlags() & RequestFlags.SCHEDULE) > 0)) {
-//
-//
-//             } else {
-//
-//                     try {
-//
-////                           final ReadGraphImpl newGraph = newSync();
-//                             processor.tryQuery(this, request, procedure);
-////                           newGraph.waitAsync(null);
-//                             waitAsyncProcedure(procedure);
-//
-//                     } catch (Throwable t) {
-//                             if(Development.DEVELOPMENT) {
-//                                     if(Development.<Boolean>getProperty(DevelopmentKeys.WRITEGRAPH_EXCEPTION_STACKTRACES, Bindings.BOOLEAN)) {
-//                                     t.printStackTrace();
-//                                     }
-//                             }
-//                             procedure.exception(this, t);
-//                             waitAsyncProcedure(procedure);
-//                     }
-//
-//             }
+               QueryCache.runnerAsyncReadEntry(this, request, parent, listener, procedure);
 
        }
 
@@ -5408,7 +5392,8 @@ public class ReadGraphImpl implements ReadGraph {
                if (parent != null || listener != null) {
 
                        try {
-                               processor.query(this, request, parent, procedure,listener);
+                               QueryCache.runnerReadEntry(this, request, parent, listener, procedure);
+                               //processor.query(this, request, parent, procedure,listener);
                        } catch (DatabaseException e) {
                                Logger.defaultLogError(e);
                                // This throwable has already been transferred to procedure at this point - do nothing about it
@@ -5518,7 +5503,8 @@ public class ReadGraphImpl implements ReadGraph {
                if (parent != null || listener != null) {
 
                        try {
-                               processor.query(this, request, parent, procedure, listener);
+                               QueryCache.runnerAsyncReadEntry(this, request, parent, listener, procedure);
+                               //processor.query(this, request, parent, procedure, listener);
                        } catch (DatabaseException e) {
                                Logger.defaultLogError(e);
                        }
index 4f8dfd2eed4b544952bf9efee417315bf6928405..d8fda07b7704c49b96f07c4788d8d5470caf4b46 100644 (file)
@@ -85,9 +85,9 @@ public interface ReadGraphSupport {
     void forHasValue(ReadGraphImpl graph, Resource subject, AsyncProcedure<Boolean> procedure);
     void forOrderedSet(ReadGraphImpl graph, Resource subject, AsyncMultiProcedure<Resource> procedure);
 
-    <T> T query(ReadGraphImpl graph, Read<T> request, CacheEntry parent, AsyncProcedure<T> procedure, ListenerBase listener) throws DatabaseException;
+    //<T> T query(ReadGraphImpl graph, Read<T> request, CacheEntry parent, AsyncProcedure<T> procedure, ListenerBase listener) throws DatabaseException;
     <T> void query(ReadGraphImpl graph, MultiRead<T> request, CacheEntry parent, AsyncMultiProcedure<T> procedure, ListenerBase listener);
-    <T> void query(ReadGraphImpl graph, AsyncRead<T> request, CacheEntry parent, AsyncProcedure<T> procedure, ListenerBase listener) throws DatabaseException;
+//    <T> void query(ReadGraphImpl graph, AsyncRead<T> request, CacheEntry parent, AsyncProcedure<T> procedure, ListenerBase listener) throws DatabaseException;
     <T> void query(ReadGraphImpl graph, AsyncMultiRead<T> request, CacheEntry parent, AsyncMultiProcedure<T> procedure, ListenerBase listener);
     <T> void query(ReadGraphImpl graph, ExternalRead<T> request, CacheEntry parent, Procedure<T> procedure, ListenerBase listener);
     
index 767a82bd5644e8759a282b8820c49b570a8fdd60..8e6cbd145a78d9a1aacf3b99f20c396a789beaae 100644 (file)
@@ -144,9 +144,85 @@ final public class AsyncReadEntry<T> extends CacheEntryBase<AsyncProcedure<T>> {
 
     @Override
     public Object compute(ReadGraphImpl graph, AsyncProcedure<T> procedure) throws DatabaseException {
-       return graph.processor.cache.performQuery(graph, request, this, procedure);
+
+       ReadGraphImpl queryGraph = graph.withParent(this);
+
+       request.perform(queryGraph, new AsyncProcedure<T>() {
+
+               @Override
+               public void execute(AsyncReadGraph returnGraph, T result) {
+                       ReadGraphImpl impl = (ReadGraphImpl)returnGraph;
+                       AsyncReadEntry.this.addOrSet(graph, result);
+                       try {
+                               procedure.execute(graph, result);
+                       } catch (Throwable t) {
+                               t.printStackTrace();
+                       }
+                       //                                      parentBarrier.dec(query);
+               }
+
+               @Override
+               public void exception(AsyncReadGraph returnGraph, Throwable t) {
+                       ReadGraphImpl impl = (ReadGraphImpl)returnGraph;
+                       //                                      AsyncReadGraph resumeGraph = finalParentGraph.newAsync();
+                       AsyncReadEntry.this.except(graph, t);
+                       try {
+                               procedure.exception(graph, t);
+                       } catch (Throwable t2) {
+                               t2.printStackTrace();
+                       }
+                       //                                      parentBarrier.dec(query);
+               }
+
+               @Override
+               public String toString() {
+                       return procedure.toString();
+               }
+
+       });
+
+               return getResult();
+       
+    }
+    
+    public static <T> void computeForEach(ReadGraphImpl parentGraph, AsyncRead<T> request, AsyncReadEntry<T> entry, AsyncProcedure<T> procedure) throws DatabaseException {
+
+               ReadGraphImpl queryGraph = parentGraph.withParent(entry);
+
+               request.perform(queryGraph, new AsyncProcedure<T>() {
+
+                       @Override
+                       public void execute(AsyncReadGraph returnGraph, T result) {
+                               ReadGraphImpl impl = (ReadGraphImpl)returnGraph;
+                               if(entry != null) entry.addOrSet(parentGraph, result);
+                               try {
+                                       procedure.execute(parentGraph, result);
+                               } catch (Throwable t) {
+                                       t.printStackTrace();
+                               }
+                       }
+
+                       @Override
+                       public void exception(AsyncReadGraph returnGraph, Throwable t) {
+                               ReadGraphImpl impl = (ReadGraphImpl)returnGraph;
+                               if(entry != null) entry.except(parentGraph, t);
+                               try {
+                                       procedure.exception(parentGraph, t);
+                               } catch (Throwable t2) {
+                                       t2.printStackTrace();
+                               }
+                       }
+
+                       @Override
+                       public String toString() {
+                               return procedure.toString();
+                       }
+
+               });
+       
     }
     
+    
        @Override
        public String toString() {
                if(isDiscarded()) return "DISCARDED " + request.toString();
index 3bceb1272bad3b7f0f9405799e734ce415a5be5c..857d93487235a0c43f83fd2a2de47c05aa9bb0b0 100644 (file)
@@ -44,7 +44,7 @@ public class CodeGen {
        
        public void generateRunner(StringBuilder content, String clazz, String[] signature, boolean shortcut) {
                
-               line(content, "static void runner" + clazz + "(ReadGraphImpl graph, " + signature[0] + ", CacheEntry parent, ListenerBase listener, " + signature[4] + " procedure) throws DatabaseException {");
+               line(content, "public static void runner" + clazz + "(ReadGraphImpl graph, " + signature[0] + ", CacheEntry parent, ListenerBase listener, " + signature[4] + " procedure) throws DatabaseException {");
                if(shortcut) {
                        line(content, "    if(parent == null && listener == null) {");
                        line(content, "        " + clazz + ".computeForEach(graph, " + signature[1] + ", null, procedure);");
@@ -155,16 +155,16 @@ public class CodeGen {
                     generateQuery(content, "DirectPredicates", signatureR1IntSet, true);
                     generateQuery(content, "Predicates", signatureR1IntSet, true);
                     generateQuery(content, "ReadEntry", signatureRead, true);
+                    generateQuery(content, "AsyncReadEntry", signatureAsyncRead, true);
                     generateQuery(content, "Types", signatureR1IntSet, true);
+                    generateQuery(content, "NamespaceIndex", signatureID2, true);
 
                     generateQuery(content, "AssertedStatements", signatureR2TIP, false);
-                    generateQuery(content, "NamespaceIndex", signatureID2, false);
                     generateQuery(content, "AssertedPredicates", signatureR1IP, false);
                     generateQuery(content, "DirectSuperRelations", signatureR1IP, false);
                     generateQuery(content, "SuperTypes", signatureR1IntSet, false);
                     generateQuery(content, "TypeHierarchy", signatureR1IntSet, false);
                     generateQuery(content, "SuperRelations", signatureR1IntSet, false);
-                    generateQuery(content, "AsyncReadEntry", signatureAsyncRead, false);
                     generateQuery(content, "MultiReadEntry", signatureMultiRead, false);
                     generateQuery(content, "AsyncMultiReadEntry", signatureAsyncMultiRead, false);
                     generateQuery(content, "ExternalReadEntry", signatureExternalRead, false);
index e55e99c6117bd1bf296c6f90a7b31f558ea7be51..884f3f6d4e7ad37c0a124486a50f26173cefda37 100644 (file)
@@ -33,32 +33,30 @@ final public class NamespaceIndex extends StringQuery<InternalProcedure<TObjectI
                provider.cache.remove(this);
        }
        
-       final private void index(ReadGraphImpl graph, final QueryProcessor provider, int root, final InternalProcedure<TObjectIntHashMap<String>> procedure) throws DatabaseException {
+       final static private void index(ReadGraphImpl graph, int root, NamespaceIndex entry, final InternalProcedure<TObjectIntHashMap<String>> procedure) throws DatabaseException {
                
                if(root == 0) {
-            add2(graph, null);
+                       if(entry != null)
+                               entry.add2(graph, null);
             procedure.execute(graph, null);
 //            System.err.println("NamespaceIndex[" + id + "]->null");
             return;
                }
 
-               final int consistsOf = provider.getConsistsOf();
-               final int hasName = provider.getHasName();
+               QueryProcessor processor = graph.processor;
+               
+               final int consistsOf = processor.getConsistsOf();
+               final int hasName = processor.getHasName();
         
         final TObjectIntHashMap<String> result = new TObjectIntHashMap<String>();
         
-        QueryCache.runnerObjects(graph, root, consistsOf, graph.parent, null, new SyncIntProcedure() {
+        QueryCache.runnerObjects(graph, root, consistsOf, entry, null, new SyncIntProcedure() {
                
                @Override
                        public void run(ReadGraphImpl graph) throws DatabaseException {
                        
-                       if(isPending()) { 
-                    add2(graph, result);
-                    procedure.execute(graph, result);
-//                    System.err.println("NamespaceIndex[" + id + "]->" + result.size());
-                       } else {
-                               procedure.exception(graph, (Throwable)statusOrException);
-                       }
+                       if(entry != null) entry.add2(graph, result);
+                       procedure.execute(graph, result);
                                
                        }
 
@@ -74,14 +72,14 @@ final public class NamespaceIndex extends StringQuery<InternalProcedure<TObjectI
 
                        inc();
                        
-                       QueryCache.runnerObjects(graph, obj, hasName, graph.parent, null, new IntProcedure() {
+                       QueryCache.runnerObjects(graph, obj, hasName, entry, null, new IntProcedure() {
                        
                        @Override
                        public void execute(ReadGraphImpl graph, int i) throws DatabaseException {
 
                                inc();
 
-                               QueryCache.runnerValueQuery(graph, i, NamespaceIndex.this, null, new InternalProcedure<byte[]>() {
+                               QueryCache.runnerValueQuery(graph, i, entry, null, new InternalProcedure<byte[]>() {
                                        
                                        @Override
                                        public void execute(ReadGraphImpl graph, byte[] value) throws DatabaseException {
@@ -112,7 +110,7 @@ final public class NamespaceIndex extends StringQuery<InternalProcedure<TObjectI
                                        
                                        @Override
                                        public void exception(ReadGraphImpl graph, Throwable t) throws DatabaseException {
-                                                       except(t);
+                                                       if(entry != null) entry.except(t);
                                                dec(graph);
                             }
 
@@ -127,7 +125,7 @@ final public class NamespaceIndex extends StringQuery<InternalProcedure<TObjectI
                                
                                @Override
                                public void exception(ReadGraphImpl graph, Throwable t) throws DatabaseException {
-                                               except(t);
+                                       if(entry != null) entry.except(t);
                         dec(graph);
                     }
 
@@ -139,27 +137,33 @@ final public class NamespaceIndex extends StringQuery<InternalProcedure<TObjectI
         
     }
 
+       
     @Override
        public Object compute(ReadGraphImpl graph, final InternalProcedure<TObjectIntHashMap<String>> procedure) throws DatabaseException {
+               computeForEach(graph, id, this, procedure);
+               return getResult();
+    }
+
+       public static void computeForEach(ReadGraphImpl graph, final String id, final NamespaceIndex entry, final InternalProcedure<TObjectIntHashMap<String>> procedure) throws DatabaseException {
        
        QueryProcessor processor = graph.processor;
        
 //     System.err.println("NamespaceIndex " + id);
        
         if("http://".equals(id) || "http:/".equals(id)) {
-            index(graph, processor, processor.getRootLibrary(), procedure);
+            index(graph, processor.getRootLibrary(), entry, procedure);
         } else {
             final String[] parts = URIStringUtils.splitURI(id);
             if(parts != null) {
-                QueryCache.runnerNamespaceIndex(graph, parts[0], this, null, new InternalProcedure<TObjectIntHashMap<String>>() {
+                QueryCache.runnerNamespaceIndex(graph, parts[0], entry, null, new InternalProcedure<TObjectIntHashMap<String>>() {
     
                     @Override
                     public void execute(ReadGraphImpl graph, TObjectIntHashMap<String> index) throws DatabaseException {
     
                         if(index != null) {
-                            index(graph, processor, index.get(parts[1]), procedure);
+                            index(graph, index.get(parts[1]), entry, procedure);
                         } else {
-                            add2(graph, null);
+                            if(entry != null) entry.add2(graph, null);
                             procedure.execute(graph, null);
 //                            System.err.println("NamespaceIndex[" + id + "]->null");
                         }
@@ -169,21 +173,19 @@ final public class NamespaceIndex extends StringQuery<InternalProcedure<TObjectI
                     @Override
                     public void exception(ReadGraphImpl graph, Throwable t) throws DatabaseException {
                         if(DebugException.DEBUG) new DebugException(t).printStackTrace();
-                        except(t);
+                        if(entry != null) entry.except(t);
                         procedure.exception(graph, t);
                     }
     
                 });
             } else {
-                add2(graph, null);
+                if(entry != null) entry.add2(graph, null);
                 procedure.execute(graph, null);
 //                System.err.println("NamespaceIndex[" + id + "]->null");
             }
 
         }
         
-        return getResult();
-        
     }
 
     @Override
@@ -191,12 +193,6 @@ final public class NamespaceIndex extends StringQuery<InternalProcedure<TObjectI
        return "NamespaceIndex[" + id + "]";
     }
 
-    synchronized private void add(TObjectIntHashMap<String> result) {
-       
-       throw new Error("Not possible!");
-       
-    }
-
     private void add2(ReadGraphImpl graph, TObjectIntHashMap<String> result) {
        
        if(!isPending()) {
@@ -205,22 +201,12 @@ final public class NamespaceIndex extends StringQuery<InternalProcedure<TObjectI
        
        assert(isPending());
 
-//        ArrayList<InternalProcedure<TObjectIntHashMap<String>>> p = null;
-
         synchronized(this) {
 
             setResult(result);
                setReady();
-//            p = procs;
-//            procs = null; 
         
         }
-        
-//        if(p != null) {
-//        
-//             for(InternalProcedure<TObjectIntHashMap<String>> proc : p) proc.execute(graph, result);
-//             
-//        }
        
     }
     
index 4be12da47d582b08cf0d6dfe16129d42650c7509..dbd0068c3f66100404eda02d5fbba9d70fdc8308 100644 (file)
@@ -47,7 +47,7 @@ public class QueryCache extends QueryCacheBase {
         }
     }
     
-    static void runnerObjects(ReadGraphImpl graph, int r1, int r2, CacheEntry parent, ListenerBase listener, IntProcedure procedure) throws DatabaseException {
+    public static void runnerObjects(ReadGraphImpl graph, int r1, int r2, CacheEntry parent, ListenerBase listener, IntProcedure procedure) throws DatabaseException {
         if(parent == null && listener == null) {
             Objects.computeForEach(graph, r1,r2, null, procedure);
             return;
@@ -89,7 +89,7 @@ public class QueryCache extends QueryCacheBase {
         }
     }
     
-    static void runnerStatements(ReadGraphImpl graph, int r1, int r2, CacheEntry parent, ListenerBase listener, TripleIntProcedure procedure) throws DatabaseException {
+    public static void runnerStatements(ReadGraphImpl graph, int r1, int r2, CacheEntry parent, ListenerBase listener, TripleIntProcedure procedure) throws DatabaseException {
         if(parent == null && listener == null) {
             Statements.computeForEach(graph, r1,r2, null, procedure);
             return;
@@ -131,7 +131,7 @@ public class QueryCache extends QueryCacheBase {
         }
     }
     
-    static void runnerDirectObjects(ReadGraphImpl graph, int r1, int r2, CacheEntry parent, ListenerBase listener, IntProcedure procedure) throws DatabaseException {
+    public static void runnerDirectObjects(ReadGraphImpl graph, int r1, int r2, CacheEntry parent, ListenerBase listener, IntProcedure procedure) throws DatabaseException {
         if(parent == null && listener == null) {
             DirectObjects.computeForEach(graph, r1,r2, null, procedure);
             return;
@@ -173,7 +173,7 @@ public class QueryCache extends QueryCacheBase {
         }
     }
     
-    static void runnerRelationInfoQuery(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, InternalProcedure<RelationInfo> procedure) throws DatabaseException {
+    public static void runnerRelationInfoQuery(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, InternalProcedure<RelationInfo> procedure) throws DatabaseException {
         if(parent == null && listener == null) {
             RelationInfoQuery.computeForEach(graph, r, null, procedure);
             return;
@@ -215,7 +215,7 @@ public class QueryCache extends QueryCacheBase {
         }
     }
     
-    static void runnerURIToResource(ReadGraphImpl graph, String id, CacheEntry parent, ListenerBase listener, InternalProcedure<Integer> procedure) throws DatabaseException {
+    public static void runnerURIToResource(ReadGraphImpl graph, String id, CacheEntry parent, ListenerBase listener, InternalProcedure<Integer> procedure) throws DatabaseException {
         if(parent == null && listener == null) {
             URIToResource.computeForEach(graph, id, null, procedure);
             return;
@@ -257,7 +257,7 @@ public class QueryCache extends QueryCacheBase {
         }
     }
     
-    static void runnerValueQuery(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, InternalProcedure<byte[]> procedure) throws DatabaseException {
+    public static void runnerValueQuery(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, InternalProcedure<byte[]> procedure) throws DatabaseException {
         if(parent == null && listener == null) {
             ValueQuery.computeForEach(graph, r, null, procedure);
             return;
@@ -299,7 +299,7 @@ public class QueryCache extends QueryCacheBase {
         }
     }
     
-    static void runnerOrderedSet(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, IntProcedure procedure) throws DatabaseException {
+    public static void runnerOrderedSet(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, IntProcedure procedure) throws DatabaseException {
         if(parent == null && listener == null) {
             OrderedSet.computeForEach(graph, r, null, procedure);
             return;
@@ -341,7 +341,7 @@ public class QueryCache extends QueryCacheBase {
         }
     }
     
-    static void runnerPrincipalTypes(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, IntProcedure procedure) throws DatabaseException {
+    public static void runnerPrincipalTypes(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, IntProcedure procedure) throws DatabaseException {
         if(parent == null && listener == null) {
             PrincipalTypes.computeForEach(graph, r, null, procedure);
             return;
@@ -383,7 +383,7 @@ public class QueryCache extends QueryCacheBase {
         }
     }
     
-    static void runnerDirectPredicates(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, InternalProcedure<IntSet> procedure) throws DatabaseException {
+    public static void runnerDirectPredicates(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, InternalProcedure<IntSet> procedure) throws DatabaseException {
         if(parent == null && listener == null) {
             DirectPredicates.computeForEach(graph, r, null, procedure);
             return;
@@ -425,7 +425,7 @@ public class QueryCache extends QueryCacheBase {
         }
     }
     
-    static void runnerPredicates(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, InternalProcedure<IntSet> procedure) throws DatabaseException {
+    public static void runnerPredicates(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, InternalProcedure<IntSet> procedure) throws DatabaseException {
         if(parent == null && listener == null) {
             Predicates.computeForEach(graph, r, null, procedure);
             return;
@@ -467,7 +467,7 @@ public class QueryCache extends QueryCacheBase {
         }
     }
     
-    static void runnerReadEntry(ReadGraphImpl graph, Read<?> r, CacheEntry parent, ListenerBase listener, AsyncProcedure procedure) throws DatabaseException {
+    public static void runnerReadEntry(ReadGraphImpl graph, Read<?> r, CacheEntry parent, ListenerBase listener, AsyncProcedure procedure) throws DatabaseException {
         if(parent == null && listener == null) {
             ReadEntry.computeForEach(graph, r, null, procedure);
             return;
@@ -483,6 +483,48 @@ public class QueryCache extends QueryCacheBase {
         }
     }
     
+    AsyncReadEntry getOrCreateAsyncReadEntry(AsyncRead<?> r) throws DatabaseException {
+        AsyncReadEntry existing = null;
+        synchronized(asyncReadEntryMap) {
+            existing = (AsyncReadEntry)asyncReadEntryMap.get(r);
+            if(existing == null) {
+                existing = new AsyncReadEntry(r);
+                existing.clearResult(querySupport);
+                existing.setPending();
+                asyncReadEntryMap.put(id(r), existing);
+                return existing;
+            }
+            if(existing.requiresComputation()) {
+                existing.setPending();
+                return existing;
+            }
+        }
+        if(existing.isPending()) waitPending(existing);
+        return existing;
+    }
+    
+    void remove(AsyncReadEntry entry) {
+        synchronized(asyncReadEntryMap) {
+            asyncReadEntryMap.remove(entry.request);
+        }
+    }
+    
+    public static void runnerAsyncReadEntry(ReadGraphImpl graph, AsyncRead<?> r, CacheEntry parent, ListenerBase listener, AsyncProcedure procedure) throws DatabaseException {
+        if(parent == null && listener == null) {
+            AsyncReadEntry.computeForEach(graph, r, null, procedure);
+            return;
+        }
+        QueryCache cache  = graph.processor.cache;
+        if(procedure == null) procedure = emptyProcedureAsyncReadEntry;
+        AsyncReadEntry entry = (AsyncReadEntry)cache.getOrCreateAsyncReadEntry(r);
+        ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure, false);
+        if(entry.isReady()) entry.performFromCache(graph, procedure);
+        else {
+            AsyncReadEntry.computeForEach(graph, r, entry, procedure);
+            if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());
+        }
+    }
+    
     Types getOrCreateTypes(int r) throws DatabaseException {
         Types existing = null;
         synchronized(typesMap) {
@@ -509,7 +551,7 @@ public class QueryCache extends QueryCacheBase {
         }
     }
     
-    static void runnerTypes(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, InternalProcedure<IntSet> procedure) throws DatabaseException {
+    public static void runnerTypes(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, InternalProcedure<IntSet> procedure) throws DatabaseException {
         if(parent == null && listener == null) {
             Types.computeForEach(graph, r, null, procedure);
             return;
@@ -525,15 +567,15 @@ public class QueryCache extends QueryCacheBase {
         }
     }
     
-    AssertedStatements getOrCreateAssertedStatements(int r1, int r2) throws DatabaseException {
-        AssertedStatements existing = null;
-        synchronized(assertedStatementsMap) {
-            existing = (AssertedStatements)assertedStatementsMap.get(r1,r2);
+    NamespaceIndex getOrCreateNamespaceIndex(String id) throws DatabaseException {
+        NamespaceIndex existing = null;
+        synchronized(namespaceIndexMap) {
+            existing = (NamespaceIndex)namespaceIndexMap.get(id);
             if(existing == null) {
-                existing = new AssertedStatements(r1,r2);
+                existing = new NamespaceIndex(id);
                 existing.clearResult(querySupport);
                 existing.setPending();
-                assertedStatementsMap.put(keyR2(r1,r2), existing);
+                namespaceIndexMap.put(keyID(id), existing);
                 return existing;
             }
             if(existing.requiresComputation()) {
@@ -545,33 +587,37 @@ public class QueryCache extends QueryCacheBase {
         return existing;
     }
     
-    void remove(AssertedStatements entry) {
-        synchronized(assertedStatementsMap) {
-            assertedStatementsMap.remove(entry.id);
+    void remove(NamespaceIndex entry) {
+        synchronized(namespaceIndexMap) {
+            namespaceIndexMap.remove(entry.id);
         }
     }
     
-    static void runnerAssertedStatements(ReadGraphImpl graph, int r1, int r2, CacheEntry parent, ListenerBase listener, TripleIntProcedure procedure) throws DatabaseException {
+    public static void runnerNamespaceIndex(ReadGraphImpl graph, String id, CacheEntry parent, ListenerBase listener, InternalProcedure<TObjectIntHashMap<String>> procedure) throws DatabaseException {
+        if(parent == null && listener == null) {
+            NamespaceIndex.computeForEach(graph, id, null, procedure);
+            return;
+        }
         QueryCache cache  = graph.processor.cache;
-        if(procedure == null) procedure = emptyProcedureAssertedStatements;
-        AssertedStatements entry = (AssertedStatements)cache.getOrCreateAssertedStatements(r1,r2);
+        if(procedure == null) procedure = emptyProcedureNamespaceIndex;
+        NamespaceIndex entry = (NamespaceIndex)cache.getOrCreateNamespaceIndex(id);
         ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure, false);
         if(entry.isReady()) entry.performFromCache(graph, procedure);
         else {
-            entry.compute(graph, procedure);
+            NamespaceIndex.computeForEach(graph, id, entry, procedure);
             if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());
         }
     }
     
-    NamespaceIndex getOrCreateNamespaceIndex(String id) throws DatabaseException {
-        NamespaceIndex existing = null;
-        synchronized(namespaceIndexMap) {
-            existing = (NamespaceIndex)namespaceIndexMap.get(id);
+    AssertedStatements getOrCreateAssertedStatements(int r1, int r2) throws DatabaseException {
+        AssertedStatements existing = null;
+        synchronized(assertedStatementsMap) {
+            existing = (AssertedStatements)assertedStatementsMap.get(r1,r2);
             if(existing == null) {
-                existing = new NamespaceIndex(id);
+                existing = new AssertedStatements(r1,r2);
                 existing.clearResult(querySupport);
                 existing.setPending();
-                namespaceIndexMap.put(keyID(id), existing);
+                assertedStatementsMap.put(keyR2(r1,r2), existing);
                 return existing;
             }
             if(existing.requiresComputation()) {
@@ -583,16 +629,16 @@ public class QueryCache extends QueryCacheBase {
         return existing;
     }
     
-    void remove(NamespaceIndex entry) {
-        synchronized(namespaceIndexMap) {
-            namespaceIndexMap.remove(entry.id);
+    void remove(AssertedStatements entry) {
+        synchronized(assertedStatementsMap) {
+            assertedStatementsMap.remove(entry.id);
         }
     }
     
-    static void runnerNamespaceIndex(ReadGraphImpl graph, String id, CacheEntry parent, ListenerBase listener, InternalProcedure<TObjectIntHashMap<String>> procedure) throws DatabaseException {
+    public static void runnerAssertedStatements(ReadGraphImpl graph, int r1, int r2, CacheEntry parent, ListenerBase listener, TripleIntProcedure procedure) throws DatabaseException {
         QueryCache cache  = graph.processor.cache;
-        if(procedure == null) procedure = emptyProcedureNamespaceIndex;
-        NamespaceIndex entry = (NamespaceIndex)cache.getOrCreateNamespaceIndex(id);
+        if(procedure == null) procedure = emptyProcedureAssertedStatements;
+        AssertedStatements entry = (AssertedStatements)cache.getOrCreateAssertedStatements(r1,r2);
         ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure, false);
         if(entry.isReady()) entry.performFromCache(graph, procedure);
         else {
@@ -627,7 +673,7 @@ public class QueryCache extends QueryCacheBase {
         }
     }
     
-    static void runnerAssertedPredicates(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, IntProcedure procedure) throws DatabaseException {
+    public static void runnerAssertedPredicates(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, IntProcedure procedure) throws DatabaseException {
         QueryCache cache  = graph.processor.cache;
         if(procedure == null) procedure = emptyProcedureAssertedPredicates;
         AssertedPredicates entry = (AssertedPredicates)cache.getOrCreateAssertedPredicates(r);
@@ -665,7 +711,7 @@ public class QueryCache extends QueryCacheBase {
         }
     }
     
-    static void runnerDirectSuperRelations(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, IntProcedure procedure) throws DatabaseException {
+    public static void runnerDirectSuperRelations(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, IntProcedure procedure) throws DatabaseException {
         QueryCache cache  = graph.processor.cache;
         if(procedure == null) procedure = emptyProcedureDirectSuperRelations;
         DirectSuperRelations entry = (DirectSuperRelations)cache.getOrCreateDirectSuperRelations(r);
@@ -703,7 +749,7 @@ public class QueryCache extends QueryCacheBase {
         }
     }
     
-    static void runnerSuperTypes(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, InternalProcedure<IntSet> procedure) throws DatabaseException {
+    public static void runnerSuperTypes(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, InternalProcedure<IntSet> procedure) throws DatabaseException {
         QueryCache cache  = graph.processor.cache;
         if(procedure == null) procedure = emptyProcedureSuperTypes;
         SuperTypes entry = (SuperTypes)cache.getOrCreateSuperTypes(r);
@@ -741,7 +787,7 @@ public class QueryCache extends QueryCacheBase {
         }
     }
     
-    static void runnerTypeHierarchy(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, InternalProcedure<IntSet> procedure) throws DatabaseException {
+    public static void runnerTypeHierarchy(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, InternalProcedure<IntSet> procedure) throws DatabaseException {
         QueryCache cache  = graph.processor.cache;
         if(procedure == null) procedure = emptyProcedureTypeHierarchy;
         TypeHierarchy entry = (TypeHierarchy)cache.getOrCreateTypeHierarchy(r);
@@ -779,7 +825,7 @@ public class QueryCache extends QueryCacheBase {
         }
     }
     
-    static void runnerSuperRelations(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, InternalProcedure<IntSet> procedure) throws DatabaseException {
+    public static void runnerSuperRelations(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, InternalProcedure<IntSet> procedure) throws DatabaseException {
         QueryCache cache  = graph.processor.cache;
         if(procedure == null) procedure = emptyProcedureSuperRelations;
         SuperRelations entry = (SuperRelations)cache.getOrCreateSuperRelations(r);
@@ -791,44 +837,6 @@ public class QueryCache extends QueryCacheBase {
         }
     }
     
-    AsyncReadEntry getOrCreateAsyncReadEntry(AsyncRead<?> r) throws DatabaseException {
-        AsyncReadEntry existing = null;
-        synchronized(asyncReadEntryMap) {
-            existing = (AsyncReadEntry)asyncReadEntryMap.get(r);
-            if(existing == null) {
-                existing = new AsyncReadEntry(r);
-                existing.clearResult(querySupport);
-                existing.setPending();
-                asyncReadEntryMap.put(id(r), existing);
-                return existing;
-            }
-            if(existing.requiresComputation()) {
-                existing.setPending();
-                return existing;
-            }
-        }
-        if(existing.isPending()) waitPending(existing);
-        return existing;
-    }
-    
-    void remove(AsyncReadEntry entry) {
-        synchronized(asyncReadEntryMap) {
-            asyncReadEntryMap.remove(entry.request);
-        }
-    }
-    
-    static void runnerAsyncReadEntry(ReadGraphImpl graph, AsyncRead<?> r, CacheEntry parent, ListenerBase listener, AsyncProcedure procedure) throws DatabaseException {
-        QueryCache cache  = graph.processor.cache;
-        if(procedure == null) procedure = emptyProcedureAsyncReadEntry;
-        AsyncReadEntry entry = (AsyncReadEntry)cache.getOrCreateAsyncReadEntry(r);
-        ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure, false);
-        if(entry.isReady()) entry.performFromCache(graph, procedure);
-        else {
-            entry.compute(graph, procedure);
-            if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());
-        }
-    }
-    
     MultiReadEntry getOrCreateMultiReadEntry(MultiRead<?> r) throws DatabaseException {
         MultiReadEntry existing = null;
         synchronized(multiReadEntryMap) {
@@ -855,7 +863,7 @@ public class QueryCache extends QueryCacheBase {
         }
     }
     
-    static void runnerMultiReadEntry(ReadGraphImpl graph, MultiRead<?> r, CacheEntry parent, ListenerBase listener, AsyncMultiProcedure procedure) throws DatabaseException {
+    public static void runnerMultiReadEntry(ReadGraphImpl graph, MultiRead<?> r, CacheEntry parent, ListenerBase listener, AsyncMultiProcedure procedure) throws DatabaseException {
         QueryCache cache  = graph.processor.cache;
         if(procedure == null) procedure = emptyProcedureMultiReadEntry;
         MultiReadEntry entry = (MultiReadEntry)cache.getOrCreateMultiReadEntry(r);
@@ -893,7 +901,7 @@ public class QueryCache extends QueryCacheBase {
         }
     }
     
-    static void runnerAsyncMultiReadEntry(ReadGraphImpl graph, AsyncMultiRead<?> r, CacheEntry parent, ListenerBase listener, AsyncMultiProcedure procedure) throws DatabaseException {
+    public static void runnerAsyncMultiReadEntry(ReadGraphImpl graph, AsyncMultiRead<?> r, CacheEntry parent, ListenerBase listener, AsyncMultiProcedure procedure) throws DatabaseException {
         QueryCache cache  = graph.processor.cache;
         if(procedure == null) procedure = emptyProcedureAsyncMultiReadEntry;
         AsyncMultiReadEntry entry = (AsyncMultiReadEntry)cache.getOrCreateAsyncMultiReadEntry(r);
@@ -931,7 +939,7 @@ public class QueryCache extends QueryCacheBase {
         }
     }
     
-    static void runnerExternalReadEntry(ReadGraphImpl graph, ExternalRead<?> r, CacheEntry parent, ListenerBase listener, AsyncProcedure procedure) throws DatabaseException {
+    public static void runnerExternalReadEntry(ReadGraphImpl graph, ExternalRead<?> r, CacheEntry parent, ListenerBase listener, AsyncProcedure procedure) throws DatabaseException {
         QueryCache cache  = graph.processor.cache;
         if(procedure == null) procedure = emptyProcedureExternalReadEntry;
         ExternalReadEntry entry = (ExternalReadEntry)cache.getOrCreateExternalReadEntry(r);
index 4056f060b4f7fa6bfb54b74d0df474f63fa08191..e2737f891385911bdb321139dcd7b93a45ff518c 100644 (file)
@@ -100,64 +100,64 @@ public class QueryCacheBase {
                listeners = new THashMap<CacheEntry, ArrayList<ListenerEntry>>(10, 0.75f);
        }
        
-       public <T> Object performQuery(ReadGraphImpl parentGraph, final AsyncRead<T> query, final CacheEntryBase entry_, AsyncProcedure procedure_) throws DatabaseException {
-
-               AsyncReadEntry<T> entry = (AsyncReadEntry<T>)entry_;
-               AsyncProcedure<T> procedure = (AsyncProcedure<T>)procedure_;
-
-               ReadGraphImpl queryGraph = parentGraph.withParent(entry_);
-
-               try {
-                       
-                       query.perform(queryGraph, new AsyncProcedure<T>() {
-
-                               @Override
-                               public void execute(AsyncReadGraph returnGraph, T result) {
-                                       ReadGraphImpl impl = (ReadGraphImpl)returnGraph;
-                                       entry.addOrSet(parentGraph, result);
-                                       try {
-                                               procedure.execute(parentGraph, result);
-                                       } catch (Throwable t) {
-                                               t.printStackTrace();
-                                       }
-//                                     parentBarrier.dec(query);
-                               }
-
-                               @Override
-                               public void exception(AsyncReadGraph returnGraph, Throwable t) {
-                                       ReadGraphImpl impl = (ReadGraphImpl)returnGraph;
-//                                     AsyncReadGraph resumeGraph = finalParentGraph.newAsync();
-                                       entry.except(parentGraph, t);
-                                       try {
-                                               procedure.exception(parentGraph, t);
-                                       } catch (Throwable t2) {
-                                               t2.printStackTrace();
-                                       }
-//                                     parentBarrier.dec(query);
-                               }
-
-                               @Override
-                               public String toString() {
-                                       return procedure.toString();
-                               }
-
-                       });
-
-               } catch (Throwable t) {
-
-                       entry.except(t);
-                       try {
-                               procedure.exception(parentGraph, t);
-                       } catch (Throwable t2) {
-                               t2.printStackTrace();
-                       }
-//                     parentBarrier.dec(query);
-
-               }
-               
-               return null;
-               
-       }
+//     public <T> Object performQuery(ReadGraphImpl parentGraph, final AsyncRead<T> query, final CacheEntryBase entry_, AsyncProcedure procedure_) throws DatabaseException {
+//
+//             AsyncReadEntry<T> entry = (AsyncReadEntry<T>)entry_;
+//             AsyncProcedure<T> procedure = (AsyncProcedure<T>)procedure_;
+//
+//             ReadGraphImpl queryGraph = parentGraph.withParent(entry_);
+//
+//             try {
+//                     
+//                     query.perform(queryGraph, new AsyncProcedure<T>() {
+//
+//                             @Override
+//                             public void execute(AsyncReadGraph returnGraph, T result) {
+//                                     ReadGraphImpl impl = (ReadGraphImpl)returnGraph;
+//                                     entry.addOrSet(parentGraph, result);
+//                                     try {
+//                                             procedure.execute(parentGraph, result);
+//                                     } catch (Throwable t) {
+//                                             t.printStackTrace();
+//                                     }
+////                                   parentBarrier.dec(query);
+//                             }
+//
+//                             @Override
+//                             public void exception(AsyncReadGraph returnGraph, Throwable t) {
+//                                     ReadGraphImpl impl = (ReadGraphImpl)returnGraph;
+////                                   AsyncReadGraph resumeGraph = finalParentGraph.newAsync();
+//                                     entry.except(parentGraph, t);
+//                                     try {
+//                                             procedure.exception(parentGraph, t);
+//                                     } catch (Throwable t2) {
+//                                             t2.printStackTrace();
+//                                     }
+////                                   parentBarrier.dec(query);
+//                             }
+//
+//                             @Override
+//                             public String toString() {
+//                                     return procedure.toString();
+//                             }
+//
+//                     });
+//
+//             } catch (Throwable t) {
+//
+//                     entry.except(t);
+//                     try {
+//                             procedure.exception(parentGraph, t);
+//                     } catch (Throwable t2) {
+//                             t2.printStackTrace();
+//                     }
+////                   parentBarrier.dec(query);
+//
+//             }
+//             
+//             return null;
+//             
+//     }
 
 //     public <T> Object performQuery(ReadGraphImpl parentGraph, final Read<T> query, final CacheEntryBase entry_, AsyncProcedure procedure_) throws DatabaseException {
 //
index a2fff0515b1975f98484ca969005ff40b5c32113..a6c987a9d0e10e0b2beda36f7a571a8633527063 100644 (file)
@@ -524,18 +524,18 @@ final public class QueryProcessor extends AbstractDisposable implements ReadGrap
                                        }
 
                                        // Fall back to using the fixed builtins.
-                                       result = querySupport.getBuiltin(id);
-                                       if (result != 0) {
-                                               procedure.execute(graph, result);
-                                               return;
-                                       } 
+//                                     result = querySupport.getBuiltin(id);
+//                                     if (result != 0) {
+//                                             procedure.execute(graph, result);
+//                                             return;
+//                                     } 
 
-                                       try {
-                                               result = querySupport.getRandomAccessReference(id);
-                                       } catch (ResourceNotFoundException e) {
-                                               procedure.exception(graph, e);
-                                               return;
-                                       }
+//                                     try {
+//                                             result = querySupport.getRandomAccessReference(id);
+//                                     } catch (ResourceNotFoundException e) {
+//                                             procedure.exception(graph, e);
+//                                             return;
+//                                     }
 
                                        if (result != 0) {
                                                procedure.execute(graph, result);
@@ -593,12 +593,12 @@ final public class QueryProcessor extends AbstractDisposable implements ReadGrap
                QueryCache.runnerExternalReadEntry(graph, query, parent, listener, procedure);
        }
 
-    @Override
-       public <T> T query(final ReadGraphImpl graph, final Read<T> query, final CacheEntry parent, final AsyncProcedure<T> procedure, final ListenerBase listener) throws DatabaseException {
-       
-       return QueryCache.resultReadEntry(graph, query, parent, listener, procedure);
-
-       }
+//    @Override
+//     public <T> T query(final ReadGraphImpl graph, final Read<T> query, final CacheEntry parent, final AsyncProcedure<T> procedure, final ListenerBase listener) throws DatabaseException {
+//     
+//     return QueryCache.resultReadEntry(graph, query, parent, listener, procedure);
+//
+//     }
 
        public <T> void queryMultiRead(final ReadGraphImpl graph, final MultiRead<T> query, final CacheEntry parent, final ListenerBase listener, final AsyncMultiProcedure<T> procedure) throws DatabaseException {
 
@@ -1340,7 +1340,7 @@ final public class QueryProcessor extends AbstractDisposable implements ReadGrap
 
                CacheEntry entry = e.entry;
 
-//             System.err.println("updateQuery " + entry);
+               System.err.println("updateQuery " + entry);
                
                /*
                 * If the dependency graph forms a DAG, some entries are inserted in the
@@ -3393,37 +3393,18 @@ final public class QueryProcessor extends AbstractDisposable implements ReadGrap
         assert(procedure != null);
 
         final ListenerBase listener = getListenerBase(procedure);
+        assert(listener == null);
 
         InternalProcedure<IntSet> ip = new InternalProcedure<IntSet>() {
 
-            AtomicBoolean first = new AtomicBoolean(true);
-
             @Override
             public void execute(final ReadGraphImpl graph, IntSet set) {
-                try {
-                    if(first.compareAndSet(true, false)) {
-                        procedure.execute(graph, set);
-//                      impl.state.barrier.dec(this);
-                    } else {
-                        procedure.execute(impl.newRestart(graph), set);
-                    }
-                } catch (Throwable t2) {
-                    Logger.defaultLogError(t2);
-                }
+               procedure.execute(graph, set);
             }
 
             @Override
             public void exception(ReadGraphImpl graph, Throwable t) {
-                try {
-                    if(first.compareAndSet(true, false)) {
-                        procedure.exception(graph, t);
-//                      impl.state.barrier.dec(this);
-                    } else {
-                        procedure.exception(impl.newRestart(graph), t);
-                    }
-                } catch (Throwable t2) {
-                    Logger.defaultLogError(t2);
-                }
+               procedure.exception(graph, t);
             }
 
         };
@@ -3449,44 +3430,25 @@ final public class QueryProcessor extends AbstractDisposable implements ReadGrap
 
        @Override
        final public void forRelationInfo(final ReadGraphImpl impl, final Resource subject, final AsyncProcedure<RelationInfo> procedure) {
-
+               
                assert(subject != null);
                assert(procedure != null);
 
                final ListenerBase listener = getListenerBase(procedure);
+               assert(listener == null);
 
                try {
                        
                        QueryCache.runnerRelationInfoQuery(impl, querySupport.getId(subject), impl.parent, listener, new InternalProcedure<RelationInfo>() {
 
-                               AtomicBoolean first = new AtomicBoolean(true);
-
                                @Override
                                public void execute(final ReadGraphImpl graph, RelationInfo set) {
-                                       try {
-                                               if(first.compareAndSet(true, false)) {
-                                                       procedure.execute(graph, set);
-//                                             impl.state.barrier.dec();
-                                               } else {
-                                                       procedure.execute(impl.newRestart(graph), set);
-                                               }
-                                       } catch (Throwable t2) {
-                                               Logger.defaultLogError(t2);
-                                       }
+                                       procedure.execute(graph, set);                                  
                                }
 
                                @Override
                                public void exception(ReadGraphImpl graph, Throwable t) {
-                                       try {
-                                               if(first.compareAndSet(true, false)) {
-                                                       procedure.exception(graph, t);
-//                                             impl.state.barrier.dec("ReadGraphSupportImpl.1353");
-                                               } else {
-                                                       procedure.exception(impl.newRestart(graph), t);
-                                               }
-                                       } catch (Throwable t2) {
-                                               Logger.defaultLogError(t2);
-                                       }
+                                       procedure.exception(graph, t);
                                }
 
                        });
@@ -4195,15 +4157,15 @@ final public class QueryProcessor extends AbstractDisposable implements ReadGrap
 
        }
 
-       @Override
-       final public <T> void query(final ReadGraphImpl impl, final AsyncRead<T> request, final CacheEntry parent, final AsyncProcedure<T> procedure, ListenerBase listener) throws DatabaseException {
-
-               assert(request != null);
-               assert(procedure != null);
-
-               QueryCache.runnerAsyncReadEntry(impl, request, parent, listener, procedure);
-
-       }
+//     @Override
+//     final public <T> void query(final ReadGraphImpl impl, final AsyncRead<T> request, final CacheEntry parent, final AsyncProcedure<T> procedure, ListenerBase listener) throws DatabaseException {
+//
+//             assert(request != null);
+//             assert(procedure != null);
+//
+//             QueryCache.runnerAsyncReadEntry(impl, request, parent, listener, procedure);
+//
+//     }
 
 //     @Override
 //     final public <T> T tryQuery(final ReadGraphImpl graph, final Read<T> request) throws DatabaseException {
index b090c4a7602170ea33f699e80cfe0a3770773c5d..d7fa8b9356ac9b5db2a13a1de3e3dc688620e8b8 100644 (file)
@@ -25,13 +25,15 @@ class ExternalRequest extends ParametrizedPrimitiveRead<Pair<GenericRelationInde
         }
         if(procedure.isDisposed()) return;
         assert(this.procedure == null);
-        this.session = graph.getSession();
         this.procedure = procedure;
+        this.session = graph.getSession();
         parameter.first.addListener(graph, parameter.second, this);
     }
     
     @Override
     public void unregistered() {
+       if(session == null) return;
+//             System.err.println("asd");
         parameter.first.removeListener(session, parameter.second, this);
     }
     
index b7adbe49bd40c5466fe7a039eb7511ffa71c6b93..c6942b5ed7b7972eb321c28f11fa5c4ec0be91b3 100644 (file)
@@ -89,6 +89,7 @@ import org.simantics.db.impl.graph.WriteSupport;
 import org.simantics.db.impl.internal.RandomAccessValueSupport;
 import org.simantics.db.impl.procedure.ResultCallWrappedQueryProcedure4;
 import org.simantics.db.impl.procedure.ResultCallWrappedSingleQueryProcedure4;
+import org.simantics.db.impl.query.QueryCache;
 import org.simantics.db.impl.query.QueryProcessor;
 import org.simantics.db.impl.query.QueryProcessor.SessionRead;
 import org.simantics.db.impl.query.QueryProcessor.SessionTask;
@@ -1514,7 +1515,8 @@ public abstract class SessionImplSocket implements Session, WriteRequestSchedule
                     if (listener != null) {
 
                        try {
-                               newGraph.processor.query(newGraph, request, null, new AsyncProcedure<T>() {
+                               
+                               AsyncProcedure ap = new AsyncProcedure<T>() {
 
                                        @Override
                                        public void exception(AsyncReadGraph graph, Throwable t) {
@@ -1532,7 +1534,10 @@ public abstract class SessionImplSocket implements Session, WriteRequestSchedule
                                                procedure.execute(graph, t);
                                        }
 
-                               }, listener);
+                               };
+                               
+                               QueryCache.runnerReadEntry(newGraph, request, null, listener, ap);
+                               
                        } catch (Throwable t) {
                            // This is handled by the AsyncProcedure
                                //Logger.defaultLogError("Internal error", t);
@@ -1626,7 +1631,8 @@ public abstract class SessionImplSocket implements Session, WriteRequestSchedule
                     if (listener != null) {
 
                         try {
-                                                       newGraph.processor.query(newGraph, request, null, procedure, listener);
+                               QueryCache.runnerAsyncReadEntry(newGraph, request, null, listener, procedure);
+                                                       //newGraph.processor.query(newGraph, request, null, procedure, listener);
                                                } catch (DatabaseException e) {
                                                        Logger.defaultLogError(e);
                                                }