]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/ReadGraphImpl.java
Attempt to fix regressions in new code base
[simantics/platform.git] / bundles / org.simantics.db.impl / src / org / simantics / db / impl / graph / ReadGraphImpl.java
index 4ef46e6c681e35e5b041387e21942a0908793869..c95cd93d94c836e4455a98fbed12b97176ffb47d 100644 (file)
@@ -22,6 +22,7 @@ import java.nio.BufferUnderflowException;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.HashSet;
 import java.util.IdentityHashMap;
 import java.util.Iterator;
 import java.util.List;
@@ -89,6 +90,7 @@ import org.simantics.db.common.primitiverequest.Value;
 import org.simantics.db.common.primitiverequest.ValueImplied;
 import org.simantics.db.common.primitiverequest.VariantValueImplied;
 import org.simantics.db.common.procedure.adapter.AsyncMultiProcedureAdapter;
+import org.simantics.db.common.procedure.adapter.AsyncProcedureAdapter;
 import org.simantics.db.common.procedure.adapter.ProcedureAdapter;
 import org.simantics.db.common.procedure.adapter.SyncMultiProcedureAdapter;
 import org.simantics.db.common.procedure.adapter.TransientCacheAsyncListener;
@@ -198,9 +200,10 @@ public class ReadGraphImpl implements AsyncReadGraph {
     final static boolean EMPTY_RESOURCE_CHECK = false;
     
        final public CacheEntry parent;
+       public final ReadGraphImpl parentGraph;
        final public QueryProcessor processor;
        
-       public AsyncBarrierImpl asyncBarrier = null;
+       public final AsyncBarrierImpl asyncBarrier;
        
        final static Binding DATA_TYPE_BINDING_INTERNAL = Bindings.getBindingUnchecked(Datatype.class);
        final static Serializer DATA_TYPE_SERIALIZER = Bindings.getSerializerUnchecked(DATA_TYPE_BINDING_INTERNAL);
@@ -1930,11 +1933,8 @@ public class ReadGraphImpl implements AsyncReadGraph {
 
        @Override
        public <T> T syncRequest(final Read<T> request) throws DatabaseException {
-
                assert (request != null);
-
-               return QueryCache.resultReadEntry(this, request, parent, null, null);
-
+               return (T)QueryCache.runnerReadEntry(this, request, parent, null, null, true);
        }
 
        @Override
@@ -2012,10 +2012,7 @@ public class ReadGraphImpl implements AsyncReadGraph {
                        throws DatabaseException {
 
                assert (request != null);
-               asyncBarrier = new AsyncBarrierImpl(null);
-               BlockingAsyncProcedure<T> ap = new BlockingAsyncProcedure<>(this, null, request);
-               syncRequest(request, ap);
-               return ap.get();
+               return syncRequest(request, new AsyncProcedureAdapter<>() );
 
        }
 
@@ -2045,11 +2042,9 @@ public class ReadGraphImpl implements AsyncReadGraph {
 
                ListenerBase listener = getListenerBase(procedure);
 
-               BlockingAsyncProcedure<T> ap = new BlockingAsyncProcedure<>(this, procedure, request);
-
-               QueryCache.runnerAsyncReadEntry(this, request, parent, listener, ap, true);
-
-               return ap.get();
+//             BlockingAsyncProcedure<T> ap = new BlockingAsyncProcedure<>(this, procedure, request);
+               return (T)QueryCache.runnerAsyncReadEntry(this, request, parent, listener, procedure, true);
+//             return ap.get();
 
        }
 
@@ -5175,7 +5170,7 @@ public class ReadGraphImpl implements AsyncReadGraph {
                assert (request != null);
                assert (procedure != null);
        
-               processor.schedule(new SessionTask(false) {
+               processor.schedule(new SessionTask(this) {
 
                        @Override
                        public void run(int thread) {
@@ -5192,7 +5187,7 @@ public class ReadGraphImpl implements AsyncReadGraph {
        }
 
     public static ReadGraphImpl createAsync(QueryProcessor support) {
-        return new ReadGraphImpl(null, support);
+        return new ReadGraphImpl(null, null, support);
     }
 
        @Override
@@ -5255,7 +5250,7 @@ public class ReadGraphImpl implements AsyncReadGraph {
                assert (request != null);
                assert (procedure != null);
 
-               processor.schedule(new SessionTask(false) {
+               processor.schedule(new SessionTask(this) {
 
                        @Override
                        public void run(int thread) {
@@ -5645,27 +5640,31 @@ public class ReadGraphImpl implements AsyncReadGraph {
         * this execution state.syncParent is the blocking request
         */
 
-       final private boolean isExternal(int thread) {
-               return thread == Integer.MIN_VALUE;
+       ReadGraphImpl(ReadGraphImpl parentGraph, CacheEntry parent, QueryProcessor support) {
+               this.parentGraph = parentGraph;
+               this.parent = parent;
+               this.processor = support;
+               this.asyncBarrier = new AsyncBarrierImpl(parentGraph != null ? parentGraph.asyncBarrier : null);
+       }
+
+       ReadGraphImpl(ReadGraphImpl graph, CacheEntry parent) {
+               this(graph, parent, graph.processor);
        }
 
        ReadGraphImpl(ReadGraphImpl graph) {
-               this(graph.parent, graph.processor);
+               this(graph, graph.parent);
        }
 
-       ReadGraphImpl(CacheEntry parent, QueryProcessor support) {
-               this.parent = parent;
-               this.processor = support;
+       public ReadGraphImpl withParent(CacheEntry parent) {
+               return new ReadGraphImpl(this, parent);
        }
 
-       public static ReadGraphImpl create(QueryProcessor support) {
-               return new ReadGraphImpl(null, support);
+       public ReadGraphImpl forRecompute(CacheEntry parent) {
+               return new ReadGraphImpl(null, parent, processor);
        }
 
-       public static ReadGraphImpl newAsync(ReadGraphImpl parent) {
-               ReadGraphImpl result = new ReadGraphImpl(parent);
-               result.asyncBarrier = new AsyncBarrierImpl(parent.asyncBarrier);
-               return result;
+       public static ReadGraphImpl create(QueryProcessor support) {
+               return new ReadGraphImpl(null, null, support);
        }
 
        public ReadGraphImpl newRestart(ReadGraphImpl impl) {
@@ -5677,11 +5676,6 @@ public class ReadGraphImpl implements AsyncReadGraph {
 
        }
 
-       public ReadGraphImpl withParent(CacheEntry parent) {
-               if(parent == this.parent) return this;
-               else return new ReadGraphImpl(parent, processor);
-       }
-
        final private ListenerBase getListenerBase(final Object procedure) {
                if (procedure instanceof ListenerBase)
                        return (ListenerBase) procedure;
@@ -6324,7 +6318,17 @@ public class ReadGraphImpl implements AsyncReadGraph {
 
     @Override
     public boolean performPending() {
-        return processor.performPending(processor.thread.get());
+        return processor.performPending(this);
+    }
+
+    public Set<ReadGraphImpl> ancestorSet() {
+        HashSet<ReadGraphImpl> result = new HashSet<>();
+        ReadGraphImpl g = this;
+        while(g != null) {
+            result.add(g);
+            g = g.parentGraph;
+        }
+        return result;
     }
 
 }