From 46c8189fee24a71d1ce0634e12db5a696e952b10 Mon Sep 17 00:00:00 2001 From: jsimomaa Date: Fri, 18 May 2018 09:18:43 +0300 Subject: [PATCH] Some enhancements made by Antti for multiple readers gitlab #5 gitlab #6 Change-Id: Ic185e28ff85cb72783ebadf908f8b58bf523e2b1 --- .../db/impl/graph/ReadGraphImpl.java | 266 +++++++++++++----- .../db/impl/graph/ReadGraphSupport.java | 2 +- .../db/impl/query/CacheEntryBase.java | 6 +- .../db/impl/query/ExternalReadEntry.java | 30 ++ .../db/impl/query/QueryCacheBase.java | 42 ++- .../db/impl/query/QueryProcessor.java | 100 ++++--- .../db/impl/query/URIToResource.java | 3 +- .../db/layer0/variable/VariableMapImpl.java | 3 +- .../procore/internal/SessionImplSocket.java | 42 +-- .../db/procore/cluster/ClusterSmall.java | 7 +- .../graph/Components.pgraph | 2 +- .../scl/Document/All.scl | 3 + .../request/ServerSCLHandlerValueRequest.java | 10 +- .../server/request/ServerSCLValueRequest.java | 15 +- ...yncCurrentTypicalInstanceWithTemplate.java | 9 +- ...SyncCurrentTypicalTemplateToInstances.java | 8 +- .../scl/Simantics/Workbench.scl | 6 + .../ReadComponentTypeInterfaceRequest.java | 15 +- .../feature.xml | 4 - 19 files changed, 406 insertions(+), 167 deletions(-) diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/ReadGraphImpl.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/ReadGraphImpl.java index e3e7d50ec..c6e41f618 100644 --- a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/ReadGraphImpl.java +++ b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/ReadGraphImpl.java @@ -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 syncRequest(final ExternalRead request, final Procedure procedure) throws DatabaseException { - assert (request != null); - - ListenerBase listener = getListenerBase(procedure); - - final DataContainer exception = new DataContainer(); - final DataContainer result = new DataContainer(); + assert (request != null); - processor.query(this, request, parent, new Procedure() { + 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 exception = new DataContainer(); +// final DataContainer result = new DataContainer(); +// +// processor.query(this, request, parent, new 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); @@ -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 void asyncRequest(final ExternalRead request, final Procedure 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() { + 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() { + // + @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() { +// +// @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.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.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 syncGraph = new ThreadLocal() { + 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) { diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/ReadGraphSupport.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/ReadGraphSupport.java index 3f7e6f4e6..7bfe5b3d2 100644 --- a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/ReadGraphSupport.java +++ b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/ReadGraphSupport.java @@ -89,7 +89,7 @@ public interface ReadGraphSupport { void query(ReadGraphImpl graph, MultiRead request, CacheEntry parent, AsyncMultiProcedure procedure, ListenerBase listener); // void query(ReadGraphImpl graph, AsyncRead request, CacheEntry parent, AsyncProcedure procedure, ListenerBase listener) throws DatabaseException; void query(ReadGraphImpl graph, AsyncMultiRead request, CacheEntry parent, AsyncMultiProcedure procedure, ListenerBase listener); - void query(ReadGraphImpl graph, ExternalRead request, CacheEntry parent, Procedure procedure, ListenerBase listener); + // void query(ReadGraphImpl graph, ExternalRead request, CacheEntry parent, Procedure procedure, ListenerBase listener); // T tryQuery(final ReadGraphImpl graph, final Read request) throws DatabaseException; // void tryQuery(final ReadGraphImpl graph, final AsyncRead request, final AsyncProcedure procedure); diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/CacheEntryBase.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/CacheEntryBase.java index b17c066f3..1506b54af 100644 --- a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/CacheEntryBase.java +++ b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/CacheEntryBase.java @@ -70,7 +70,7 @@ abstract public class CacheEntryBase extends CacheEntry { 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 extends CacheEntry { } @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 extends CacheEntry { } @Override - final public void setPending() { + public void setPending() { statusOrException = PENDING; } diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/ExternalReadEntry.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/ExternalReadEntry.java index 7fb8598b7..40b6f6fab 100644 --- a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/ExternalReadEntry.java +++ b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/ExternalReadEntry.java @@ -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 extends CacheEntryBase 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 request) { assert request != null; @@ -89,6 +99,25 @@ final public class ExternalReadEntry extends CacheEntryBase } + @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 extends CacheEntryBase // Update if(!items.isEmpty()) { + setReady(); setResult(items.removeFirst()); } // Reschedule diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryCacheBase.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryCacheBase.java index f75cd9dcd..d6924c708 100644 --- a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryCacheBase.java +++ b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryCacheBase.java @@ -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 implements AsyncProcedure { + + private Procedure procedure; + private T result = null; + private Throwable throwable = null; + + ExternalProcedureWrapper(Procedure 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 implements InternalProcedure { @@ -1058,6 +1092,12 @@ public class QueryCacheBase { } + public static T resultExternalReadEntry(ReadGraphImpl graph, ExternalRead r, CacheEntry parent, ListenerBase listener, Procedure procedure) throws DatabaseException { + ExternalProcedureWrapper wrap = new ExternalProcedureWrapper<>(procedure); + QueryCache.runnerExternalReadEntry(graph, r, parent, listener, wrap); + return wrap.get(); + } + public static T resultReadEntry(ReadGraphImpl graph, Read r, CacheEntry parent, ListenerBase listener, AsyncProcedure procedure) throws DatabaseException { AsyncProcedureWrapper wrap = new AsyncProcedureWrapper<>(procedure); QueryCache.runnerReadEntry(graph, r, parent, listener, wrap); diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryProcessor.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryProcessor.java index a54484a65..f1e9233eb 100644 --- a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryProcessor.java +++ b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryProcessor.java @@ -169,8 +169,6 @@ final public class QueryProcessor extends AbstractDisposable implements ReadGrap ArrayList[] 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 void query(final ReadGraphImpl impl, final ExternalRead request, final CacheEntry parent, final Procedure procedure, ListenerBase listener) { - - assert(request != null); - assert(procedure != null); - - try { - - queryPrimitiveRead(impl, request, parent, listener, new AsyncProcedure() { - - @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 void query(final ReadGraphImpl impl, final ExternalRead request, final CacheEntry parent, final Procedure procedure, ListenerBase listener) throws DatabaseException { +// +// assert(request != null); +// assert(procedure != null); +// +// try { +// +// queryPrimitiveRead(impl, request, parent, listener, new AsyncProcedure() { +// +// @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) { diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/URIToResource.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/URIToResource.java index 78ae0d12d..b29d518df 100644 --- a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/URIToResource.java +++ b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/URIToResource.java @@ -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> { } 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); diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/VariableMapImpl.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/VariableMapImpl.java index 52ecbc705..45675e684 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/VariableMapImpl.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/VariableMapImpl.java @@ -18,8 +18,9 @@ abstract public class VariableMapImpl implements VariableMap { public Map getVariables(ReadGraph graph, Variable context, String classification, Map map) throws DatabaseException { Map all = getVariables(graph, context, null); + if(all.isEmpty()) return all; - for(Map.Entry entry : all.entrySet()) { if(all.isEmpty()) return all; + for(Map.Entry entry : all.entrySet()) { Set classifications = entry.getValue().getClassifications(graph); if(classifications.contains(classification)) { diff --git a/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/SessionImplSocket.java b/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/SessionImplSocket.java index c6942b5ed..242fcfe3d 100644 --- a/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/SessionImplSocket.java +++ b/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/SessionImplSocket.java @@ -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; @@ -1750,23 +1751,30 @@ public abstract class SessionImplSocket implements Session, WriteRequestSchedule if (listener != null) { - newGraph.processor.query(newGraph, request, null, new Procedure() { - - @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() { +// +// @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); diff --git a/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ClusterSmall.java b/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ClusterSmall.java index ead009984..05b044dfd 100644 --- a/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ClusterSmall.java +++ b/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ClusterSmall.java @@ -886,8 +886,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); diff --git a/bundles/org.simantics.document.base.ontology/graph/Components.pgraph b/bundles/org.simantics.document.base.ontology/graph/Components.pgraph index df5665ea4..95fc62c6b 100644 --- a/bundles/org.simantics.document.base.ontology/graph/Components.pgraph +++ b/bundles/org.simantics.document.base.ontology/graph/Components.pgraph @@ -84,7 +84,7 @@ COMPONENTS.Event [DataDefinition] + @JavaName "dataDefinitions" + computeDataDefinitions :: Variable -> [DataDefinition] + emptyOnClick :: () -> AbstractEventHandler writeEventHandler :: Variable -> (Variable -> (String -> Maybe String) -> String) -> AbstractEventHandler diff --git a/bundles/org.simantics.document.server/src/org/simantics/document/server/request/ServerSCLHandlerValueRequest.java b/bundles/org.simantics.document.server/src/org/simantics/document/server/request/ServerSCLHandlerValueRequest.java index 67d4d7a44..af6d1f6a2 100644 --- a/bundles/org.simantics.document.server/src/org/simantics/document/server/request/ServerSCLHandlerValueRequest.java +++ b/bundles/org.simantics.document.server/src/org/simantics/document/server/request/ServerSCLHandlerValueRequest.java @@ -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 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(); diff --git a/bundles/org.simantics.document.server/src/org/simantics/document/server/request/ServerSCLValueRequest.java b/bundles/org.simantics.document.server/src/org/simantics/document/server/request/ServerSCLValueRequest.java index 77cd9b4f4..9655e0f86 100644 --- a/bundles/org.simantics.document.server/src/org/simantics/document/server/request/ServerSCLValueRequest.java +++ b/bundles/org.simantics.document.server/src/org/simantics/document/server/request/ServerSCLValueRequest.java @@ -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 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(); diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/handlers/e4/SyncCurrentTypicalInstanceWithTemplate.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/handlers/e4/SyncCurrentTypicalInstanceWithTemplate.java index 0c9641a27..565400877 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/handlers/e4/SyncCurrentTypicalInstanceWithTemplate.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/handlers/e4/SyncCurrentTypicalInstanceWithTemplate.java @@ -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 diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/handlers/e4/SyncCurrentTypicalTemplateToInstances.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/handlers/e4/SyncCurrentTypicalTemplateToInstances.java index 0678d5c3b..cb5b81224 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/handlers/e4/SyncCurrentTypicalTemplateToInstances.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/handlers/e4/SyncCurrentTypicalTemplateToInstances.java @@ -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 diff --git a/bundles/org.simantics.modeling/scl/Simantics/Workbench.scl b/bundles/org.simantics.modeling/scl/Simantics/Workbench.scl index 25061240f..a82027ac4 100644 --- a/bundles/org.simantics.modeling/scl/Simantics/Workbench.scl +++ b/bundles/org.simantics.modeling/scl/Simantics/Workbench.scl @@ -19,3 +19,9 @@ importJava "org.simantics.ui.workbench.editor.IEditorRegistry" where editorAdapters :: a -> [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 diff --git a/bundles/org.simantics.structural2/src/org/simantics/structural2/scl/ReadComponentTypeInterfaceRequest.java b/bundles/org.simantics.structural2/src/org/simantics/structural2/scl/ReadComponentTypeInterfaceRequest.java index a93cbe8d4..b50d1604f 100644 --- a/bundles/org.simantics.structural2/src/org/simantics/structural2/scl/ReadComponentTypeInterfaceRequest.java +++ b/bundles/org.simantics.structural2/src/org/simantics/structural2/scl/ReadComponentTypeInterfaceRequest.java @@ -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 - -