]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/ReadGraphImpl.java
Fixed asynchronous recompute problems
[simantics/platform.git] / bundles / org.simantics.db.impl / src / org / simantics / db / impl / graph / ReadGraphImpl.java
index fe0e3fcee535b983e119730e00e7d239e789474d..3a735e6c24c07900f92a5006790e100af3bb52b2 100644 (file)
@@ -46,7 +46,6 @@ import org.simantics.databoard.util.binary.BinaryFile;
 import org.simantics.databoard.util.binary.RandomAccessBinary;
 import org.simantics.db.AsyncReadGraph;
 import org.simantics.db.DevelopmentKeys;
-import org.simantics.db.ExternalValue;
 import org.simantics.db.ExternalValueSupport;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.RelationContext;
@@ -5402,11 +5401,6 @@ public class ReadGraphImpl implements ReadGraph {
                return processor.getSession();
        }
 
-//     @Override
-//     final public Builtins getBuiltins() {
-//             return processor.getSession().getBuiltins();
-//     }
-
        @Override
        public <T> void asyncRequest(final Read<T> request) {
 
@@ -5472,10 +5466,6 @@ public class ReadGraphImpl implements ReadGraph {
         return new ReadGraphImpl(null, support);
     }
 
-    public static ReadGraphImpl forRecompute(CacheEntry entry, QueryProcessor support) {
-        return new ReadGraphImpl(entry, support);       
-    }
-
        @Override
        public <T> void asyncRequest(Read<T> request, SyncProcedure<T> procedure) {
                asyncRequest(request, new SyncToAsyncProcedure<T>(procedure));
@@ -6016,53 +6006,17 @@ public class ReadGraphImpl implements ReadGraph {
                return thread == Integer.MIN_VALUE;
        }
 
-//     final private boolean isSync(int thread) {
-//             return thread < -1 && thread > Integer.MIN_VALUE;
-//     }
-
        ReadGraphImpl(ReadGraphImpl graph) {
                this(graph.parent, graph.processor);
        }
 
        ReadGraphImpl(CacheEntry parent, QueryProcessor support) {
-//             this.state = new ReadGraphState(barrier, support);
                this.parent = parent;
                this.processor = support;
        }
        
-       ReadGraphImpl(final QueryProcessor support) {
-               
-//             this.state = state;
-               this.processor = support;
-               this.parent = null;
-               
-       }
-
-//     public static ReadGraphImpl createSync(int syncThread, Object syncParent,
-//                     ReadGraphSupportImpl support) {
-//             return new ReadGraphImpl(syncThread, syncThread, syncParent, null,
-//                             support, new AsyncBarrierImpl(null));
-//     }
-
        public static ReadGraphImpl create(QueryProcessor support) {
-               return new ReadGraphImpl(support);
-       }
-
-//     public ReadGraphImpl newAsync() {
-//             return this;
-////           if(!state.synchronizedExecution) {
-////                   return this;
-////           } else {
-////                   return new ReadGraphImpl(false, parent, state.support, state.barrier);
-////           }
-//     }
-
-//     public ReadGraphImpl newSync() {
-//             return new ReadGraphImpl(parent, processor);
-//     }
-
-       public ReadGraphImpl newSync(CacheEntry parentEntry) {
-               return new ReadGraphImpl(parentEntry, processor);
+               return new ReadGraphImpl(null, support);
        }
 
        public ReadGraphImpl newRestart(ReadGraphImpl impl) {
@@ -6070,41 +6024,10 @@ public class ReadGraphImpl implements ReadGraph {
                WriteGraphImpl write = processor.getSession().getService(
                                WriteGraphImpl.class);
 
-//             if (write.callerThread != impl.callerThread)
-//                     return new WriteGraphImpl(impl.callerThread, parent, state.support, write.writeSupport, write.provider, write.state.barrier);
                return write;
 
        }
 
-//     public ReadGraphImpl newSync(Object parentRequest) {
-//             return new ReadGraphImpl(callerThread, state.parent, state.support, new AsyncBarrierImpl(state.barrier));
-//     }
-
-//     public ReadGraphImpl newSync(final int callerThread, Object parentRequest) {
-//             assert (state.syncThread == callerThread || (state.syncThread == Integer.MIN_VALUE && callerThread != Integer.MIN_VALUE));
-//             return new ReadGraphImpl(callerThread, callerThread, parentRequest,
-//                             state.parent, state.support, new AsyncBarrierImpl(state.barrier));
-//     }
-//
-//     public ReadGraphImpl newSyncAsync(Object parentRequest) {
-////           assert (callerThread < 0);
-//             return new ReadGraphImpl(callerThread, state.syncThread, parentRequest,
-//                             state.parent, state.support, new AsyncBarrierImpl(state.barrier));
-//     }
-//
-//     public ReadGraphImpl newSyncAsync(final int callerThread,
-//                     Object parentRequest) {
-////           assert (callerThread < 0);
-//             // assert(state.syncThread == callerThread || (state.syncThread == Integer.MIN_VALUE
-//             // && callerThread != Integer.MIN_VALUE) );
-//             return new ReadGraphImpl(callerThread, callerThread, parentRequest,
-//                             state.parent, state.support, new AsyncBarrierImpl(state.barrier));
-//     }
-
-       public ReadGraphImpl withAsyncParent(CacheEntry parent) {
-               return new ReadGraphImpl(parent, processor);
-       }
-
        public ReadGraphImpl withParent(CacheEntry parent) {
                if(parent == this.parent) return this;
                else return new ReadGraphImpl(parent, processor);
@@ -6121,56 +6044,13 @@ public class ReadGraphImpl implements ReadGraph {
                
                assert(procedure.done());
                
-//             while (!procedure.done()) {
-//
-//                     boolean executed = processor.resumeTasks(callerThread, null, null);
-//                     if (!executed) {
-//                             try {
-//                                     Thread.sleep(1);
-//                                     //                                                              sema.tryAcquire(1, TimeUnit.MILLISECONDS);
-//                             } catch (InterruptedException e) {
-//                                     e.printStackTrace();
-//                             }
-//                     }
-//
-//             }
-               
        }
 
        public <T> void waitAsyncProcedure(AsyncReadProcedure<T> procedure) {
                
                assert(procedure.done());
                
-//             while (!procedure.done()) {
-//
-//                     boolean executed = processor.processor.resume(this);
-//                     if (!executed) {
-//                             try {
-//                                     Thread.sleep(1);
-//                                     //                                                              sema.tryAcquire(1, TimeUnit.MILLISECONDS);
-//                             } catch (InterruptedException e) {
-//                                     e.printStackTrace();
-//                             }
-//                     }
-//
-//             }
-               
        }
-       
-//     public void waitAsync(Object request) {
-//             try {
-//                     state.barrier.waitBarrier(request, this);
-//             } catch (Throwable t) {
-//                     t.printStackTrace();
-//                     processor.scanPending();
-//                     processor.querySupport.checkTasks();
-//                     throw new RuntimeDatabaseException(t);
-//             }
-//     }
-
-//     public void restart() {
-//             state.barrier.restart();
-//     }
 
        public boolean resumeTasks() {
                return processor.resumeTasks(this);
@@ -6458,9 +6338,6 @@ public class ReadGraphImpl implements ReadGraph {
                        return getValue(r);
                }
        }
-        else if(types.contains(L0.Function)) {
-            return Functions.exec(this, r, this, r, context);
-        }
        else if(types.contains(L0.ExternalValue)) {
                return (T)syncRequest(new AdaptValue(r), TransientCacheListener.<Object>instance());
        }
@@ -6491,14 +6368,6 @@ public class ReadGraphImpl implements ReadGraph {
                 return getVariantValue(r);
             }
         }
-        else if(types.contains(L0.Function)) {
-            Object value = Functions.exec(this, r, this, r, context);
-            try {
-                return new Variant(Bindings.OBJECT.getContentBinding(value), value);
-            } catch ( org.simantics.databoard.binding.error.BindingException e ) {
-                throw new BindingException( "No binding found for class " + value.getClass().getName(), e );
-            }
-        }
         else if(types.contains(L0.ExternalValue)) {
             Object value = syncRequest(new AdaptValue(r), TransientCacheListener.<Object>instance());
             try {
@@ -6552,8 +6421,7 @@ public class ReadGraphImpl implements ReadGraph {
             for(Resource converter : graph.getObjects(resource, L0.ConvertsToValueWith)) {
                 try {
                        if(L0.Functions_functionApplication.equals(converter)) {
-                               return AdaptValue.functionApplication;
-                               //return (Function3<ReadGraph,Resource,Object,T>)graph.syncRequest(new AdaptValue(resource));
+                               return (Function3<ReadGraph,Resource,Object,T>)graph.syncRequest(new AdaptValue(resource));
                        } else {
                                return graph.getValue2(converter, resource);
                        }
@@ -6609,28 +6477,11 @@ public class ReadGraphImpl implements ReadGraph {
                } else {
                        return getValue(r, binding);
                }
-       } else if(types.contains(L0.Function)) {
-            Object value = Functions.exec(this, r, this, r, context);
-            if(binding.isInstance(value)) return (T)value;
-            try {
-                Binding srcBinding = Bindings.OBJECT.getContentBinding(value);
-                return (T)Bindings.adapt(value, srcBinding, binding);
-            } catch(RuntimeException e) {
-                DatabaseException dte = findPossibleRootException(e);
-                if(dte != null) throw dte;
-                else throw new DatabaseException(e);
-            } catch (AdaptException e) {
-                throw new DatabaseException(e);
-            } catch (org.simantics.databoard.binding.error.BindingException e) {
-                throw new DatabaseException(e);
-            }
        } else if(types.contains(L0.ExternalValue)) {
                try {
-                       ExternalValue ev = adapt(r, ExternalValue.class);
-                       return ev.getValue(this, r);
-                       //return (T)ReflectionUtils.getValue(getURI(r)).getValue();
-//             } catch(ValueNotFoundException e) {
-//                     throw new DatabaseException(e);
+                       return (T)ReflectionUtils.getValue(getURI(r)).getValue();
+               } catch(ValueNotFoundException e) {
+                       throw new DatabaseException(e);
                } catch(ClassCastException e) {
                        throw new DatabaseException(e);
                }