]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Some enhancements made by Antti for multiple readers
authorjsimomaa <jani.simomaa@gmail.com>
Fri, 18 May 2018 06:18:43 +0000 (09:18 +0300)
committerAntti Villberg <antti.villberg@semantum.fi>
Thu, 26 Jul 2018 20:58:37 +0000 (23:58 +0300)
gitlab #5
gitlab #6

Change-Id: Ic185e28ff85cb72783ebadf908f8b58bf523e2b1

19 files changed:
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/CacheEntryBase.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/QueryCacheBase.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/URIToResource.java
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/VariableMapImpl.java
bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/SessionImplSocket.java
bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ClusterSmall.java
bundles/org.simantics.document.base.ontology/graph/Components.pgraph
bundles/org.simantics.document.server/scl/Document/All.scl
bundles/org.simantics.document.server/src/org/simantics/document/server/request/ServerSCLHandlerValueRequest.java
bundles/org.simantics.document.server/src/org/simantics/document/server/request/ServerSCLValueRequest.java
bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/handlers/e4/SyncCurrentTypicalInstanceWithTemplate.java
bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/handlers/e4/SyncCurrentTypicalTemplateToInstances.java
bundles/org.simantics.modeling/scl/Simantics/Workbench.scl
bundles/org.simantics.structural2/src/org/simantics/structural2/scl/ReadComponentTypeInterfaceRequest.java
features/org.simantics.desktop.product.feature/feature.xml

index e3e7d50ecbc04998d62a650a9695ce939b6667ac..c6e41f6189dec87cd4022f5712c08e9701d2b58c 100644 (file)
@@ -112,6 +112,7 @@ import org.simantics.db.common.procedure.wrapper.SyncToAsyncProcedure;
 import org.simantics.db.common.procedure.wrapper.SyncToAsyncSetProcedure;
 import org.simantics.db.common.request.AdaptValue;
 import org.simantics.db.common.request.ResourceRead;
+import org.simantics.db.common.utils.Functions;
 import org.simantics.db.common.utils.Logger;
 import org.simantics.db.common.utils.NameUtils;
 import org.simantics.db.common.validation.L0Validations;
@@ -139,6 +140,7 @@ 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.QueryCacheBase;
 import org.simantics.db.impl.query.QueryProcessor;
 import org.simantics.db.impl.query.QuerySupport;
 import org.simantics.db.impl.query.TripleIntProcedure;
@@ -179,6 +181,7 @@ import org.simantics.scl.compiler.types.Type;
 import org.simantics.scl.compiler.types.exceptions.SCLTypeParseException;
 import org.simantics.scl.reflection.ReflectionUtils;
 import org.simantics.scl.reflection.ValueNotFoundException;
+import org.simantics.scl.runtime.function.Function1;
 import org.simantics.scl.runtime.function.Function3;
 import org.simantics.utils.DataContainer;
 import org.simantics.utils.Development;
@@ -2031,7 +2034,7 @@ public class ReadGraphImpl implements ReadGraph {
                                        throw (DatabaseException) exception;
                                else
                                        throw new DatabaseException(
-                                                       "Unexpected exception in ReadGraph.syncRequest(AsyncMultiRead)",
+                                                       "Unexpected exception in ReadGraph.syncRequest(AsyncRead)",
                                                        exception);
                        }
                }
@@ -2526,28 +2529,38 @@ public class ReadGraphImpl implements ReadGraph {
        final public <T> T syncRequest(final ExternalRead<T> request,
                        final Procedure<T> procedure) throws DatabaseException {
 
-               assert (request != null);
-
-               ListenerBase listener = getListenerBase(procedure);
-               
-               final DataContainer<Throwable> exception = new DataContainer<Throwable>();
-               final DataContainer<T> result = new DataContainer<T>();
+        assert (request != null);
 
-               processor.query(this, request, parent, new Procedure<T>() {
+        ListenerBase listener = procedure != null ? getListenerBase(procedure) : null;
+        return QueryCache.resultExternalReadEntry(this, request, parent, listener, procedure);
 
-                       @Override
-                       public void exception(Throwable throwable) {
-                               exception.set(throwable);
-                               procedure.exception(throwable);
-                       }
-
-                       @Override
-                       public void execute(T t) {
-                               result.set(t);
-                               procedure.execute(t);
-                       }
-
-               }, listener);
+//         
+//         ListenerBase listener = getListenerBase(procedure);
+//         
+//         return QueryCache.resultExternalReadEntry(this, request, parent, listener, procedure);
+           
+//             assert (request != null);
+//
+//             ListenerBase listener = getListenerBase(procedure);
+//             
+//             final DataContainer<Throwable> exception = new DataContainer<Throwable>();
+//             final DataContainer<T> result = new DataContainer<T>();
+//
+//             processor.query(this, request, parent, new Procedure<T>() {
+//
+//                     @Override
+//                     public void exception(Throwable throwable) {
+//                             exception.set(throwable);
+//                             procedure.exception(throwable);
+//                     }
+//
+//                     @Override
+//                     public void execute(T t) {
+//                             result.set(t);
+//                             procedure.execute(t);
+//                     }
+//
+//             }, listener);
                
 
 
@@ -2581,18 +2594,18 @@ public class ReadGraphImpl implements ReadGraph {
 //                     }
 //
 //             }
-
-               Throwable t = exception.get();
-               if (t != null) {
-                       if (t instanceof DatabaseException)
-                               throw (DatabaseException) t;
-                       else
-                               throw new DatabaseException(
-                                               "Unexpected exception in ReadGraph.syncRequest(Read)",
-                                               t);
-               }
-
-               return result.get();            
+//
+//             Throwable t = exception.get();
+//             if (t != null) {
+//                     if (t instanceof DatabaseException)
+//                             throw (DatabaseException) t;
+//                     else
+//                             throw new DatabaseException(
+//                                             "Unexpected exception in ReadGraph.syncRequest(Read)",
+//                                             t);
+//             }
+//
+//             return result.get();            
 
        }
 
@@ -5761,56 +5774,125 @@ public class ReadGraphImpl implements ReadGraph {
        final public <T> void asyncRequest(final ExternalRead<T> request,
                        final Procedure<T> procedure) {
 
-               assert (request != null);
-               assert (procedure != null);
-
-               ListenerBase listener = getListenerBase(procedure);
-
-               if (parent != null || listener != null) {
-
-                       processor.query(this, request, parent, procedure, listener);
-
-               } else {
-
-                       try {
+           
+        assert (request != null);
+        assert (procedure != null);
 
-                               request.register(this, new Listener<T>() {
+        final ListenerBase listener = getListenerBase(procedure);
 
-                                       @Override
-                                       public void execute(T result) {
-                                               procedure.execute(result);
-                                       }
+        if (parent != null || listener != null) {
 
-                                       @Override
-                                       public void exception(Throwable t) {
-                                               procedure.exception(t);
-                                       }
+            try {
+                QueryCacheBase.resultExternalReadEntry(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
+                //
+            }
+            
+        } else {
 
-                                       @Override
-                                       public String toString() {
-                                               return "asyncRequest(PrimitiveRead) -> " + request;
-                                       }
+            request.register(this, new Listener<T>() {
+                //
+                @Override
+                public void execute(T result) {
+                    procedure.execute(result);
+                }
 
-                                       @Override
-                                       public boolean isDisposed() {
-                                               return true;
-                                       }
+                @Override
+                public void exception(Throwable t) {
+                    procedure.exception(t);
+                }
 
-                               });
+                @Override
+                public String toString() {
+                    return "asyncRequest(PrimitiveRead) -> " + request;
+                }
 
-                       } catch (Throwable t) {
+                @Override
+                public boolean isDisposed() {
+                    return true;
+                }
 
-                               if (t instanceof DatabaseException)
-                                       procedure.exception(t);
-                               else
-                                       procedure
-                                                       .exception(new DatabaseException(
-                                                                       "Unexpected exception in ReadGraph.asyncRequest(SingleAsyncRead, SingleProcedure)",
-                                                                       t));
+            });            
+            
+//          final ReadGraphImpl newGraph = newSync();
 
-                       }
+//            try {
+//
+//                T result = request.perform(this);
+//                
+//                try {
+//                    procedure.execute(this, result);
+//                } catch (Throwable t) {
+//                    Logger.defaultLogError(t);
+//                }
+//
+//            } catch (Throwable t) {
+//
+//                try {
+//                    procedure.exception(this, t);
+//                } catch (Throwable t2) {
+//                    Logger.defaultLogError(t2);
+//                }
+//
+//            } finally {
+//
+//            }
 
-               }
+        }
+           
+//             assert (request != null);
+//             assert (procedure != null);
+//
+//             ListenerBase listener = getListenerBase(procedure);
+//
+//             if (parent != null || listener != null) {
+//
+//                     processor.query(this, request, parent, procedure, listener);
+//
+//             } else {
+//
+//                     try {
+//
+//                             request.register(this, new Listener<T>() {
+//
+//                                     @Override
+//                                     public void execute(T result) {
+//                                             procedure.execute(result);
+//                                     }
+//
+//                                     @Override
+//                                     public void exception(Throwable t) {
+//                                             procedure.exception(t);
+//                                     }
+//
+//                                     @Override
+//                                     public String toString() {
+//                                             return "asyncRequest(PrimitiveRead) -> " + request;
+//                                     }
+//
+//                                     @Override
+//                                     public boolean isDisposed() {
+//                                             return true;
+//                                     }
+//
+//                             });
+//
+//                     } catch (Throwable t) {
+//
+//                             if (t instanceof DatabaseException)
+//                                     procedure.exception(t);
+//                             else
+//                                     procedure
+//                                                     .exception(new DatabaseException(
+//                                                                     "Unexpected exception in ReadGraph.asyncRequest(SingleAsyncRead, SingleProcedure)",
+//                                                                     t));
+//
+//                     }
+//
+//             }
 
        }
 
@@ -6371,6 +6453,9 @@ 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());
        }
@@ -6401,6 +6486,14 @@ 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 {
@@ -6511,6 +6604,21 @@ 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);
@@ -6662,16 +6770,22 @@ public class ReadGraphImpl implements ReadGraph {
         }
     }
     
+    private static ThreadLocal<Boolean> syncGraph = new ThreadLocal<Boolean>() {
+        protected Boolean initialValue() {
+            return true;
+        }
+    };
+
     @Override
     public boolean setSynchronous(boolean value) {
-        boolean old = processor.synch;
-        processor.synch = value;
+        boolean old = getSynchronous();
+        syncGraph.set(value);
         return old;
     }
     
     @Override
     public boolean getSynchronous() {
-        return processor.synch;
+        return syncGraph.get();
     }
     
     public void ensureLoaded(int resource) {
index 3f7e6f4e63ba7d07b8442fd50903a18fb4927d8f..7bfe5b3d2860d0680cce0da959aed4c71b5fefba 100644 (file)
@@ -89,7 +89,7 @@ public interface ReadGraphSupport {
     <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, 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);
+    //<T> void query(ReadGraphImpl graph, ExternalRead<T> request, CacheEntry parent, Procedure<T> procedure, ListenerBase listener);
     
 //    <T> T tryQuery(final ReadGraphImpl graph, final Read<T> request) throws DatabaseException;
 //    <T> void tryQuery(final ReadGraphImpl graph, final AsyncRead<T> request, final AsyncProcedure<T> procedure);
index b17c066f380b5548562985d967cff6d33f5ed378..1506b54afc3041eacc2cc7718505960b64f34654 100644 (file)
@@ -70,7 +70,7 @@ abstract public class CacheEntryBase<Procedure> extends CacheEntry<Procedure> {
     abstract int makeHash();
     
     // This can be tested to see if the result is finished
-    private Object result = NO_RESULT;
+    Object result = NO_RESULT;
     
     final public boolean isFresh() {
        return REQUIRES_COMPUTATION == statusOrException;
@@ -108,7 +108,7 @@ abstract public class CacheEntryBase<Procedure> extends CacheEntry<Procedure> {
     }
 
     @Override
-    final public void except(Throwable t) {
+    public void except(Throwable t) {
        if(DebugPolicy.QUERY_STATE) System.out.println("[QUERY STATE]: excepted " + this);
        if(statusOrException != DISCARDED) {
                statusOrException = EXCEPTED;
@@ -133,7 +133,7 @@ abstract public class CacheEntryBase<Procedure> extends CacheEntry<Procedure> {
     }
 
     @Override
-    final public void setPending() {
+    public void setPending() {
        statusOrException = PENDING;
     }
     
index 7fb8598b7c36087f074ea71425b8c4c2434fc0d1..40b6f6fab408ac8d37ed13224cb2953e0ff9d469 100644 (file)
@@ -15,6 +15,7 @@ import java.util.ArrayList;
 import java.util.LinkedList;
 
 import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.impl.DebugPolicy;
 import org.simantics.db.impl.graph.ReadGraphImpl;
 import org.simantics.db.procedure.AsyncProcedure;
 import org.simantics.db.procedure.Procedure;
@@ -47,6 +48,15 @@ final public class ExternalReadEntry<T> extends CacheEntryBase<AsyncProcedure<T>
         request = null;
         super.discard();
     }
+
+    @Override
+    public void setPending() {
+        if(result != NO_RESULT) {
+            //new Exception("result = " + result).printStackTrace();
+        }
+        statusOrException = PENDING;
+        result = REQUIRES_COMPUTATION;
+    }
     
     public ExternalReadEntry(ExternalRead<T> request) {
         assert request != null;
@@ -89,6 +99,25 @@ final public class ExternalReadEntry<T> extends CacheEntryBase<AsyncProcedure<T>
         
     }
     
+    @Override
+    public void except(Throwable t) {
+        if(DebugPolicy.QUERY_STATE) System.out.println("[QUERY STATE]: excepted " + this);
+        if(statusOrException != DISCARDED) {
+            statusOrException = EXCEPTED;
+            result = t;
+        } else {
+            result = t;
+        }
+        assert(isExcepted());
+    }
+    
+    @Override
+    public void setResult(Object result) {
+        super.setResult(result);
+        assert(!(result instanceof Throwable));
+        assert(!isExcepted());
+    }
+
     @Override
     final public Query getQuery() {
        
@@ -102,6 +131,7 @@ final public class ExternalReadEntry<T> extends CacheEntryBase<AsyncProcedure<T>
 
                                        // Update
                                        if(!items.isEmpty()) {
+                                           setReady();
                                                setResult(items.removeFirst());
                                        }
                                        // Reschedule
index f75cd9dcd80b790727383a5d078f84f9c374c994..d6924c708a9738fa1cd517fc686f1cb461369cc7 100644 (file)
@@ -16,6 +16,7 @@ import org.simantics.db.procedure.AsyncMultiProcedure;
 import org.simantics.db.procedure.AsyncProcedure;
 import org.simantics.db.procedure.Listener;
 import org.simantics.db.procedure.ListenerBase;
+import org.simantics.db.procedure.Procedure;
 import org.simantics.db.request.AsyncMultiRead;
 import org.simantics.db.request.AsyncRead;
 import org.simantics.db.request.ExternalRead;
@@ -200,9 +201,9 @@ public class QueryCacheBase {
                                        
                                        // Just for safety
                                        if(entry.isDiscarded()) return;
-                                       if(entry.isExcepted()) entry.setPending();
                                        
                                        if(used.compareAndSet(false, true)) {
+                           //entry.setPending();
                                                entry.addOrSet(parentGraph.processor, result);
                                                procedure.execute(parentGraph, result);
                                        } else {
@@ -945,6 +946,39 @@ public class QueryCacheBase {
                
     }
 
+    static class ExternalProcedureWrapper<T> implements AsyncProcedure<T> {
+        
+        private Procedure<T> procedure;
+        private T result = null;
+        private Throwable throwable = null;
+        
+        ExternalProcedureWrapper(Procedure<T> procedure) {
+            this.procedure = procedure;
+        }
+
+        @Override
+        public void execute(AsyncReadGraph graph, T result) {
+            if(procedure != null) procedure.execute(result);
+            this.result = result;
+        }
+
+        @Override
+        public void exception(AsyncReadGraph graph, Throwable throwable) {
+            if(procedure != null) procedure.exception(throwable);
+            this.throwable = throwable;
+        }
+        
+        public T get() throws DatabaseException {
+            if(throwable != null) {
+                if(throwable instanceof DatabaseException) throw (DatabaseException)throwable;
+                else throw new DatabaseException(throwable);
+            } else {
+                return result;
+            }
+        }
+        
+    }
+
     
     static class InternalProcedureWrapper<T> implements InternalProcedure<T> {
        
@@ -1058,6 +1092,12 @@ public class QueryCacheBase {
 
     }
 
+    public static <T> T resultExternalReadEntry(ReadGraphImpl graph, ExternalRead r, CacheEntry parent, ListenerBase listener, Procedure<T> procedure) throws DatabaseException {
+        ExternalProcedureWrapper<T> wrap = new ExternalProcedureWrapper<>(procedure);
+        QueryCache.runnerExternalReadEntry(graph, r, parent, listener, wrap);
+        return wrap.get();
+    }
+
     public static <T> T resultReadEntry(ReadGraphImpl graph, Read r, CacheEntry parent, ListenerBase listener, AsyncProcedure<T> procedure) throws DatabaseException {
        AsyncProcedureWrapper<T> wrap = new AsyncProcedureWrapper<>(procedure);
         QueryCache.runnerReadEntry(graph, r, parent, listener, wrap);
index a54484a6566e623ae9fd4c1ea6b3dac63060572e..f1e9233eb685b7fe87cb47ca4c00704503edec9a 100644 (file)
@@ -169,8 +169,6 @@ final public class QueryProcessor extends AbstractDisposable implements ReadGrap
 
        ArrayList<SessionTask>[]                           delayQueues;
        
-       public boolean synch = true;
-
        final Object querySupportLock;
        
        public Long modificationCounter = 0L;
@@ -572,7 +570,17 @@ final public class QueryProcessor extends AbstractDisposable implements ReadGrap
 
                        });
                } catch (DatabaseException e) {
-                       Logger.defaultLogError(e);
+                   
+                   try {
+                       
+                procedure.exception(graph, e);
+                
+            } catch (DatabaseException e1) {
+                
+                Logger.defaultLogError(e1);
+                
+            }
+                   
                }
 
        }
@@ -1360,7 +1368,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
@@ -4336,48 +4344,48 @@ final public class QueryProcessor extends AbstractDisposable implements ReadGrap
 
        }
 
-       @Override
-       final public <T> void query(final ReadGraphImpl impl, final ExternalRead<T> request, final CacheEntry parent, final Procedure<T> procedure, ListenerBase listener) {
-
-               assert(request != null);
-               assert(procedure != null);
-
-               try {
-               
-                       queryPrimitiveRead(impl, request, parent, listener, new AsyncProcedure<T>() {
-       
-                               @Override
-                               public String toString() {
-                                       return procedure.toString();
-                               }
-       
-                               @Override
-                               public void execute(AsyncReadGraph graph, T result) {
-                                       try {
-                                               procedure.execute(result);
-                                       } catch (Throwable t2) {
-                                               Logger.defaultLogError(t2);
-                                       }
-                               }
-
-                               @Override
-                               public void exception(AsyncReadGraph graph, Throwable throwable) {
-                                       try {
-                                               procedure.exception(throwable);
-                                       } catch (Throwable t2) {
-                                               Logger.defaultLogError(t2);
-                                       }
-                               }
-       
-                       });
-                       
-               } catch (DatabaseException e) {
-                       
-                       throw new IllegalStateException(e);
-                       
-               }
-
-       }
+//     @Override
+//     final public <T> void query(final ReadGraphImpl impl, final ExternalRead<T> request, final CacheEntry parent, final Procedure<T> procedure, ListenerBase listener) throws DatabaseException {
+//
+//             assert(request != null);
+//             assert(procedure != null);
+//
+//             try {
+//             
+//                     queryPrimitiveRead(impl, request, parent, listener, new AsyncProcedure<T>() {
+//     
+//                             @Override
+//                             public String toString() {
+//                                     return procedure.toString();
+//                             }
+//     
+//                             @Override
+//                             public void execute(AsyncReadGraph graph, T result) {
+//                                     try {
+//                                             procedure.execute(result);
+//                                     } catch (Throwable t2) {
+//                                             Logger.defaultLogError(t2);
+//                                     }
+//                             }
+//
+//                             @Override
+//                             public void exception(AsyncReadGraph graph, Throwable throwable) {
+//                                     try {
+//                                             procedure.exception(throwable);
+//                                     } catch (Throwable t2) {
+//                                             Logger.defaultLogError(t2);
+//                                     }
+//                             }
+//     
+//                     });
+//                     
+//             } catch (DatabaseException e) {
+//                     
+//                     throw new IllegalStateException(e);
+//                     
+//             }
+//
+//     }
 
        @Override
        public VirtualGraph getProvider(Resource subject, Resource predicate, Resource object) {
index 78ae0d12d0ba0a147ca79b7ac65f894952e2bf47..b29d518df13789956002f48a88902432daa30e92 100644 (file)
@@ -15,6 +15,7 @@ import org.simantics.databoard.util.URIStringUtils;
 import org.simantics.db.ObjectResourceIdMap;
 import org.simantics.db.common.exception.DebugException;
 import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.exception.ResourceNotFoundException;
 import org.simantics.db.impl.graph.ReadGraphImpl;
 import org.simantics.db.impl.procedure.InternalProcedure;
 
@@ -61,7 +62,7 @@ public class URIToResource extends StringQuery<InternalProcedure<Integer>> {
                
             } else {
                
-               DatabaseException e = new DatabaseException("No URI for " + id);
+                ResourceNotFoundException e = new ResourceNotFoundException("No resource for URI: " + id);
                if(entry != null) entry.except(e);
                procedure.exception(graph, e);
                 
index 52ecbc705774b8fa1edc75d2da34923b0129778f..45675e6842ed63b138ba1c6b5c80abaf952389a4 100644 (file)
@@ -18,8 +18,9 @@ abstract public class VariableMapImpl implements VariableMap {
        public Map<String, Variable> getVariables(ReadGraph graph, Variable context, String classification, Map<String, Variable> map) throws DatabaseException {
                
        Map<String,Variable> all = getVariables(graph, context, null);
+       if(all.isEmpty()) return all;
     
-       for(Map.Entry<String, Variable> entry : all.entrySet()) {       if(all.isEmpty()) return all;
+       for(Map.Entry<String, Variable> entry : all.entrySet()) {
        
                Set<String> classifications = entry.getValue().getClassifications(graph);
                if(classifications.contains(classification)) {
index 8bbccd080512af308765c0a15c1a413526c5acf1..f3b6c2e0b9ba8c065746f0b17b49efc5d83cac27 100644 (file)
@@ -90,6 +90,7 @@ 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.QueryCacheBase;
 import org.simantics.db.impl.query.QueryProcessor;
 import org.simantics.db.impl.query.QueryProcessor.SessionRead;
 import org.simantics.db.impl.query.QueryProcessor.SessionTask;
@@ -1748,23 +1749,30 @@ public abstract class SessionImplSocket implements Session, WriteRequestSchedule
 
                     if (listener != null) {
 
-                        newGraph.processor.query(newGraph, request, null, new Procedure<T>() {
-
-                            @Override
-                            public void exception(Throwable t) {
-                                procedure.exception(t);
-                                if(throwable != null) {
-                                    throwable.set(t);
-                                }
-                            }
-
-                            @Override
-                            public void execute(T t) {
-                                if(result != null) result.set(t);
-                                procedure.execute(t);
-                            }
-
-                        }, listener);
+                        try {
+                            QueryCacheBase.resultExternalReadEntry(newGraph, request, null, listener, procedure);
+                        } catch (DatabaseException e) {
+                            Logger.defaultLogError(e);
+                        }
+                        
+                        
+//                        newGraph.processor.query(newGraph, request, null, new Procedure<T>() {
+//
+//                            @Override
+//                            public void exception(Throwable t) {
+//                                procedure.exception(t);
+//                                if(throwable != null) {
+//                                    throwable.set(t);
+//                                }
+//                            }
+//
+//                            @Override
+//                            public void execute(T t) {
+//                                if(result != null) result.set(t);
+//                                procedure.execute(t);
+//                            }
+//
+//                        }, listener);
 
 //                        newGraph.waitAsync(request);
 
index c8309c6bf5303a2909564de1a2f29637a8a34534..51818048f4f644c08714f29c8dab8b9feeff4dfa 100644 (file)
@@ -908,8 +908,11 @@ final public class ClusterSmall extends ClusterImpl {
         if (ClusterTraitsSmall.resourceRefIsLocal(resourceRef)) {
             key = clusterBits | resourceRef;
         } else {
-            foreignTable.fillResourceUID(ClusterTraitsSmall.resourceRefGetForeignIndex((short)resourceRef), this);
-            key = ClusterTraitsBase.createResourceKey(clusterSupport.getClusterKeyByClusterUIDOrMake(clusterUID1, clusterUID2), executeIndex);
+            // TODO: not so nice
+            synchronized(this) {
+                foreignTable.fillResourceUID(ClusterTraitsSmall.resourceRefGetForeignIndex((short)resourceRef), this);
+                key = ClusterTraitsBase.createResourceKey(clusterSupport.getClusterKeyByClusterUIDOrMake(clusterUID1, clusterUID2), executeIndex);
+            }
         }
         if (DEBUG)
             System.out.println("ClusterSmall.execute key=" + key);
index df5665ea463bf41855b789f46e87e60f4fce37b5..95fc62c6bc6b62ad8c04465a66186b0b7ab9f6d3 100644 (file)
@@ -84,7 +84,7 @@ COMPONENTS.Event <T COMPONENTS.ParentlessComponent
  
 COMPONENTS.CommandEvent <T COMPONENTS.Event
    @connectionPoint RELATIONS.data1
-   @sclAttribute PROPERTIES.dataDefinitions "dataDefinitions self" "[DataDefinition]"
+   @sclAttribute PROPERTIES.dataDefinitions "computeDataDefinitions self" "[DataDefinition]"
    @sclAttribute PROPERTIES.SCLFunction "emptyOnClick ()" "String"
 
 DOC.commandEvent : L0.Template
index 4e9cdeabc5da46d7ef3343c7f1d4d812b8c33564..8a6b4d80b765b98cf30fa4c802370bfc7d1cb24b 100644 (file)
@@ -113,6 +113,9 @@ importJava "org.simantics.document.server.Functions" where
 
     dataDefinitions :: Variable -> <ReadGraph> [DataDefinition]
 
+    @JavaName "dataDefinitions"
+    computeDataDefinitions :: Variable -> <ReadGraph> [DataDefinition]
+
     emptyOnClick :: () -> <ReadGraph> AbstractEventHandler
     
     writeEventHandler :: Variable -> (Variable -> (String -> Maybe String) -> <WriteGraph> String) -> <ReadGraph> AbstractEventHandler
index 67d4d7a44cf10694dc3e0e653043e4969dd733a4..af6d1f6a22e1f1bb0b8f4cd3cc3c59d415724cad 100644 (file)
@@ -82,8 +82,9 @@ public class ServerSCLHandlerValueRequest extends AbstractExpressionCompilationR
                        parent = parent.getParent(graph);
                        represents = parent.getPossibleRepresents(graph);
                }
-               Resource root = graph.syncRequest(new IndexRoot(property.getRepresents(graph)));
-               return Pair.make(parent.getType(graph), root);
+               Resource componentType = parent.getType(graph); 
+               Resource root = graph.syncRequest(new IndexRoot(parent.getRepresents(graph)));
+               return Pair.make(componentType, root);
        }
 
     public static List<TCon> getEffects(ReadGraph graph, Variable context) throws DatabaseException {
@@ -251,8 +252,9 @@ public class ServerSCLHandlerValueRequest extends AbstractExpressionCompilationR
                                return Pair.make(type, root);
                        } else {
                                Resource doc = graph.syncRequest(new PossibleTypedParent(component, DocumentationResource.getInstance(graph).Document));
-                               Resource root = graph.syncRequest(new IndexRoot(component));
-                               return Pair.make(graph.getSingleType(doc), root);
+                               Resource componentType = graph.getSingleType(doc); 
+                               Resource root = graph.syncRequest(new IndexRoot(doc));
+                               return Pair.make(componentType, root);
                        }
                }
                throw new IllegalStateException();
index 77cd9b4f4a3a8cfe175b27c40508819dc3cfa880..9655e0f86d96e074b7d9a9fa9027343209736667 100644 (file)
@@ -80,6 +80,7 @@ public class ServerSCLValueRequest extends AbstractExpressionCompilationRequest<
                        Resource type = graph.syncRequest(new FindPossibleComponentTypeRequest(represents));
                        if(type != null) {
                                Resource root = graph.syncRequest(new IndexRoot(type));
+                               //System.err.println("getComponentTypeAndRoot1 " + property.getURI(graph) + " => " + graph.getPossibleURI(type) + " " + graph.getPossibleURI(root));
                                return Pair.make(type, root);
                        }
                }
@@ -87,8 +88,11 @@ public class ServerSCLValueRequest extends AbstractExpressionCompilationRequest<
                        parent = parent.getParent(graph);
                        represents = parent.getPossibleRepresents(graph);
                }
-               Resource root = graph.syncRequest(new IndexRoot(property.getRepresents(graph)));
-               return Pair.make(parent.getType(graph), root);
+//             Resource root = graph.syncRequest(new IndexRoot(property.getRepresents(graph)));
+        Resource componentType = parent.getType(graph);
+        Resource root = graph.syncRequest(new IndexRoot(parent.getRepresents(graph)));
+        //System.err.println("getComponentTypeAndRoot2 " + property.getURI(graph) + " => " + graph.getPossibleURI(componentType) + " " + graph.getPossibleURI(root));
+               return Pair.make(componentType, root);
        }
 
        private static Pair<Resource,Resource> getComponentTypeAndRoot(ReadGraph graph, Resource component)  throws DatabaseException {
@@ -96,11 +100,14 @@ public class ServerSCLValueRequest extends AbstractExpressionCompilationRequest<
                        Resource type = graph.syncRequest(new FindPossibleComponentTypeRequest(component));
                        if(type != null) {
                                Resource root = graph.syncRequest(new IndexRoot(type));
+          //      System.err.println("getComponentTypeAndRoot3 " + graph.getPossibleURI(component) + " => " + graph.getPossibleURI(type) + " " + graph.getPossibleURI(root));
                                return Pair.make(type, root);
                        } else {
                                Resource doc = graph.syncRequest(new PossibleTypedParent(component, DocumentationResource.getInstance(graph).Document));
-                               Resource root = graph.syncRequest(new IndexRoot(component));
-                               return Pair.make(graph.getSingleType(doc), root);
+                               Resource componentType = graph.getSingleType(doc);
+                Resource root = graph.syncRequest(new IndexRoot(doc));
+            //    System.err.println("getComponentTypeAndRoot4 " + graph.getPossibleURI(component) + " => " + graph.getPossibleURI(componentType) + " " + graph.getPossibleURI(root));
+                               return Pair.make(componentType, root);
                        }
                }
                throw new IllegalStateException();
index 0c9641a27f45275ce221c06b4e58c3d68c071c17..565400877525ea43b30baa98493e950b04ec357c 100644 (file)
@@ -19,6 +19,7 @@ import org.simantics.modeling.ui.documents.OpenPlainTextDocumentAdapter;
 import org.simantics.modeling.ui.property.TypicalPropertyTester;
 import org.simantics.modeling.ui.typicals.RuleChooserDialog;
 import org.simantics.ui.workbench.IResourceEditorInput;
+import org.simantics.ui.workbench.ResourceEditorActionContributor;
 import org.simantics.utils.ui.ErrorLogger;
 import org.simantics.utils.ui.workbench.WorkbenchUtils;
 
@@ -41,8 +42,12 @@ public class SyncCurrentTypicalInstanceWithTemplate {
         }
         if (activeEditor == null)
             return false;
-        IResourceEditorInput input = (IResourceEditorInput) activeEditor.getEditorInput();
-        return TypicalPropertyTester.isTypicalInstanceEditor(Simantics.getSession(), input.getResource());
+        if(activeEditor.getEditorInput() instanceof IResourceEditorInput) {
+            IResourceEditorInput input = (IResourceEditorInput) activeEditor.getEditorInput();
+            return TypicalPropertyTester.isTypicalInstanceEditor(Simantics.getSession(), input.getResource());
+        } else {
+            return false;
+        }
     }
     
     @Execute
index 0678d5c3b93dd4f996f1b8db983bde8427cd9f8c..cb5b81224a1f0def0e4ea5b3e6ece2ff609e8210 100644 (file)
@@ -40,8 +40,12 @@ public class SyncCurrentTypicalTemplateToInstances {
         }
         if (activeEditor == null)
             return false;
-        IResourceEditorInput input = (IResourceEditorInput) activeEditor.getEditorInput();
-        return TypicalPropertyTester.isTypicalMasterEditor(Simantics.getSession(), input.getResource());
+        if(activeEditor.getEditorInput() instanceof IResourceEditorInput) {
+            IResourceEditorInput input = (IResourceEditorInput) activeEditor.getEditorInput();
+            return TypicalPropertyTester.isTypicalMasterEditor(Simantics.getSession(), input.getResource());
+        } else {
+            return false;
+        }
     }
     
     @Execute
index 25061240f8c140e6e001ffbde2c37e028ca398b0..a82027ac47ba925a0c3731488344755bb65466fe 100644 (file)
@@ -19,3 +19,9 @@ importJava "org.simantics.ui.workbench.editor.IEditorRegistry" where
 
 editorAdapters :: a -> <ReadGraph> [EditorAdapter]
 editorAdapters object = vectorToList $ editorAdapters_ getEditorRegistryInstance object
+
+importJava "org.simantics.utils.strings.StringInputValidator" where
+    data StringInputValidator
+
+importJava "org.simantics.browsing.ui.swt.widgets.DragSourceListenerFactory" where
+    data DragSourceListenerFactory
\ No newline at end of file
index a93cbe8d4237abc857aa5bbbaa742d6c9b2b7929..b50d1604f2ad82aed9f84420341a0c28233f178f 100644 (file)
@@ -8,11 +8,14 @@ import org.simantics.databoard.Bindings;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
 import org.simantics.db.common.request.ResourceRead;
+import org.simantics.db.common.utils.NameUtils;
 import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.scl.SCLDatabaseException;
 import org.simantics.db.layer0.util.Layer0Utils;
 import org.simantics.layer0.Layer0;
 import org.simantics.scl.compiler.environment.Environment;
 import org.simantics.scl.compiler.environment.Environments;
+import org.simantics.scl.compiler.errors.CompilationError;
 import org.simantics.scl.compiler.top.SCLExpressionCompilationException;
 import org.simantics.scl.compiler.types.Type;
 
@@ -38,8 +41,16 @@ public class ReadComponentTypeInterfaceRequest extends ResourceRead<Map<String,
                                try {
                                    type = Environments.getType(environment, typeName);
                                } catch(SCLExpressionCompilationException e) {
-                                   e.printStackTrace();
-                                   continue;
+                           StringBuilder b = new StringBuilder();
+                           b.append("Couldn't compile interface properties in type '" + NameUtils.getSafeName(graph, t) + " for environment " + environment);
+                           b.append("':\n");
+                           StringBuilder b2 = new StringBuilder();
+                           for(CompilationError error : e.getErrors()) {
+                               b2.append(error.description);
+                               b2.append('\n');
+                           }
+                           System.err.println(b.toString() + b2.toString());
+                           throw new SCLDatabaseException(b.toString()+b2.toString(), b2.toString(), e.getErrors());
                                }
                                ComponentTypeProperty property = new ComponentTypeProperty(relation, type);
                                result.put(name, property);
index be715fa9afe6647e558316949f2a4ac1849f290b..59c22464375383ef51b34e2c4080e9c80a8b8937 100644 (file)
          id="org.simantics.scl.rest.feature"
          version="0.0.0"/>
 
-   <includes
-         id="fi.semantum.simupedia"
-         version="0.0.0"/>
-
    <plugin
          id="org.simantics.desktop.product"
          download-size="0"