]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
DB and Layer0 modifications for related issues 15/3115/4
authorAntti Villberg <antti.villberg@semantum.fi>
Mon, 19 Aug 2019 08:26:51 +0000 (11:26 +0300)
committerAntti Villberg <antti.villberg@semantum.fi>
Tue, 20 Aug 2019 09:11:23 +0000 (12:11 +0300)
gitlab #347
gitlab #348

Change-Id: Ic5d2209d9865fc44583ea4814cc1d26d212a5f87

23 files changed:
bundles/org.simantics.db.common/META-INF/MANIFEST.MF
bundles/org.simantics.db.common/src/org/simantics/db/common/SimanticsInternal.java [new file with mode: 0644]
bundles/org.simantics.db.common/src/org/simantics/db/common/request/RuntimeEnvironmentRequest.java [new file with mode: 0644]
bundles/org.simantics.db.common/src/org/simantics/db/common/utils/CommonDBUtils.java
bundles/org.simantics.db.common/src/org/simantics/db/common/validation/L0Validations.java
bundles/org.simantics.db.layer0/build.properties
bundles/org.simantics.db.layer0/scl/Simantics/Layer0.scl [new file with mode: 0644]
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/internal/SimanticsInternal.java
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/Layer0Utils.java
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/RuntimeEnvironmentRequest.java
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/validation/ValidationUtils.java
bundles/org.simantics.db.management/META-INF/MANIFEST.MF
bundles/org.simantics.db.management/src/org/simantics/db/management/SessionContext.java
bundles/org.simantics.db.management/src/org/simantics/db/management/internal/SessionManagerProvider.java [deleted file]
bundles/org.simantics.db.services/META-INF/MANIFEST.MF
bundles/org.simantics.db.services/src/org/simantics/db/services/adaption/AdapterRegistry2.java
bundles/org.simantics.db.services/src/org/simantics/db/services/adaption/reflection/ReflectionAdapter2.java
bundles/org.simantics.layer0.utils/META-INF/MANIFEST.MF
bundles/org.simantics.layer0/graph/Layer0.pgraph
bundles/org.simantics.layer0/graph/Layer0Constraints.pgraph
bundles/org.simantics.layer0/graph/Layer0Templates.pgraph
bundles/org.simantics.layer0/graph/Layer0Validations.pgraph
bundles/org.simantics/src/org/simantics/SimanticsPlatform.java

index c45b276d72eb7db405710daec9e89341c28af58f..27e43385191e53f6038eda67523c87df3594f5f4 100644 (file)
@@ -15,7 +15,9 @@ Require-Bundle: org.simantics.db;bundle-version="1.1.0";visibility:=reexport,
  org.simantics.user.ontology;bundle-version="1.0.0",
  org.simantics.layer0x.ontology;bundle-version="1.0.0",
  org.simantics.issues.ontology;bundle-version="1.2.0",
- org.slf4j.api
+ org.slf4j.api,
+ org.simantics.db.management;bundle-version="1.1.0",
+ org.simantics.scl.osgi
 Export-Package: org.simantics.db.common,
  org.simantics.db.common.adaption,
  org.simantics.db.common.auth,
diff --git a/bundles/org.simantics.db.common/src/org/simantics/db/common/SimanticsInternal.java b/bundles/org.simantics.db.common/src/org/simantics/db/common/SimanticsInternal.java
new file mode 100644 (file)
index 0000000..e59e36f
--- /dev/null
@@ -0,0 +1,157 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.db.common;
+
+import java.util.concurrent.TimeUnit;
+
+import org.simantics.db.Session;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.management.ISessionContext;
+import org.simantics.db.management.ISessionContextProvider;
+import org.simantics.db.management.ISessionContextProviderSource;
+import org.simantics.db.request.ReadInterface;
+import org.simantics.db.request.WriteInterface;
+import org.simantics.layer0.Layer0;
+import org.simantics.operation.Layer0X;
+import org.simantics.utils.threads.ThreadUtils;
+
+/**
+ * An internal facade for accessing basic Simantics platform services.
+ * Usable without a graphical UI, i.e. in headless contexts.
+ * 
+ * Use org.simantics.Simantics instead where ever possible.
+ */
+public class SimanticsInternal {
+
+    private static ISessionContextProviderSource providerSource = null;
+
+    /**
+     * Queue execution of a runnable. 
+     * 
+     * @param runnable
+     */
+    public static void async(Runnable runnable) {
+        ThreadUtils.getBlockingWorkExecutor().execute(runnable);
+    }
+
+    public static void async(Runnable runnable, int delay, TimeUnit unit) {
+        ThreadUtils.getTimer().schedule(runnable, delay, unit);
+    }
+    
+    /**
+     * Queue execution of a non-blocking runnable. Use this method with caution. 
+     * A non-blocking runnable nevers locks anything, No Locks, No semaphores,
+     * No Object.wait(), No synchronized() {} blocks.   
+     * 
+     * @param runnable a non-blocking runnable
+     */
+    public static void asyncNonblocking(Runnable runnable) {
+        ThreadUtils.getNonBlockingWorkExecutor().execute(runnable);
+    }
+
+    /**
+     * Schedule execution of a non-blocking runnable. Use this method with caution. 
+     * A non-blocking runnable never locks anything, No Locks, No semaphores,
+     * No Object,wait(), No synchronized() {} blocks.   
+     * 
+     * @param runnable a non-blocking runnable
+     * @param initialDelay
+     * @param period
+     */
+    public static void asyncNonblocking(Runnable runnable, int initialDelay, int period) {
+        ThreadUtils.getNonBlockingWorkExecutor().scheduleAtFixedRate(runnable, initialDelay, period, TimeUnit.MILLISECONDS);
+    }
+    
+    public static synchronized ISessionContext setSessionContext(ISessionContext ctx) {
+        return getSessionContextProvider().setSessionContext(ctx);
+    }
+
+    public static void setSessionContextProviderSource(ISessionContextProviderSource source) {
+        if (source == null)
+            throw new IllegalArgumentException("null provider source");
+        providerSource = source;
+    }
+
+    public static ISessionContextProviderSource getProviderSource() {
+        if (providerSource == null)
+            throw new IllegalStateException(
+            "providerSource must be initialized by the application before using class Simantics");
+        return providerSource;
+    }
+
+    public static ISessionContextProvider getSessionContextProvider() {
+        return getProviderSource().getActive();
+    }
+
+    /**
+     * Returns the database session context associated with the currently active
+     * context. This method should be used to retrieve session contexts only
+     * when the client is sure that the correct context is active.
+     * 
+     * @return the session context associated with the currently active context
+     *         or <code>null</code> if the context has no session context
+     */
+    public static ISessionContext getSessionContext() {
+        ISessionContextProvider provider = getSessionContextProvider();
+        return provider != null ? provider.getSessionContext() : null;
+    }
+
+    /**
+     * Returns the database Session bound to the currently active context.
+     * 
+     * <p>
+     * The method always returns a non-null Session or produces an
+     * IllegalStateException if a Session was not attainable.
+     * </p>
+     * 
+     * @return the Session bound to the currently active workbench window
+     * @throws IllegalStateException if no Session was available
+     */
+    public static Session getSession() {
+        ISessionContext ctx = getSessionContext();
+        if (ctx == null)
+            throw new IllegalStateException("Session unavailable, no database session open");
+        return ctx.getSession();
+    }
+
+    /**
+     * Returns the database Session bound to the currently active context.
+     * Differently from {@link #getSession()}, this method returns
+     * <code>null</code> if there is no current Session available.
+     * 
+     * @see #getSession()
+     * @return the Session bound to the currently active context or
+     *         <code>null</code>
+     */
+    public static Session peekSession() {
+        ISessionContext ctx = getSessionContext();
+        return ctx == null ? null : ctx.peekSession();
+    }
+
+    public static Layer0 getLayer0() throws DatabaseException {
+        return Layer0.getInstance(getSession());
+    }
+
+    public static Layer0X getLayer0X() throws DatabaseException {
+        return Layer0X.getInstance(getSession());
+    }
+
+    
+    public static <T> T sync(ReadInterface<T> r) throws DatabaseException {
+       return getSession().sync(r);
+    }
+    
+    public static <T> T sync(WriteInterface<T> r) throws DatabaseException {
+       return getSession().sync(r);
+    }
+    
+}
diff --git a/bundles/org.simantics.db.common/src/org/simantics/db/common/request/RuntimeEnvironmentRequest.java b/bundles/org.simantics.db.common/src/org/simantics/db/common/request/RuntimeEnvironmentRequest.java
new file mode 100644 (file)
index 0000000..24a5c10
--- /dev/null
@@ -0,0 +1,153 @@
+package org.simantics.db.common.request;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.common.SimanticsInternal;
+import org.simantics.db.common.utils.CommonDBUtils;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.procedure.Listener;
+import org.simantics.db.request.Read;
+import org.simantics.scl.compiler.environment.specification.EnvironmentSpecification;
+import org.simantics.scl.compiler.module.repository.ImportFailureException;
+import org.simantics.scl.compiler.module.repository.UpdateListener;
+import org.simantics.scl.compiler.runtime.RuntimeEnvironment;
+import org.simantics.scl.osgi.SCLOsgi;
+import org.simantics.scl.runtime.SCLContext;
+
+/**
+ * Finds the runtime environment of a model or other index root.
+ * 
+ * @author Hannu Niemist&ouml;
+ * @author Antti Villberg
+ */
+public class RuntimeEnvironmentRequest extends UnaryRead<Resource, RuntimeEnvironment> {
+
+    public RuntimeEnvironmentRequest(Resource parameter) {
+        super(parameter);
+    }
+
+    protected void fillEnvironmentSpecification(EnvironmentSpecification environmentSpecification) {
+    }
+
+    static class UpdateListenerImpl extends UpdateListener {
+
+        final EnvironmentSpecification environmentSpecification;
+        final Listener<RuntimeEnvironment> callback;
+
+        UpdateListenerImpl(EnvironmentSpecification environmentSpecification, Listener<RuntimeEnvironment> callback) {
+            this.environmentSpecification = environmentSpecification;
+            this.callback = callback;
+        }
+
+        @Override
+        public void notifyAboutUpdate() {
+            if(callback.isDisposed()) {
+                stopListening();
+                return;
+            }
+            getRuntimeEnvironment(environmentSpecification, callback, this);
+        }
+    };
+
+    public static void getRuntimeEnvironment(EnvironmentSpecification environmentSpecification, Listener<RuntimeEnvironment> callback, UpdateListenerImpl listener) {
+
+        try {
+
+            SCLContext context = SCLContext.getCurrent();
+
+            RuntimeEnvironment env;
+            Object graph = context.get("graph");
+            if(graph == null)
+                try {
+                    env = SimanticsInternal.getSession().syncRequest(new Read<RuntimeEnvironment>() {
+                        @Override
+                        public RuntimeEnvironment perform(ReadGraph graph) throws DatabaseException {
+
+                            SCLContext sclContext = SCLContext.getCurrent();
+                            Object oldGraph = sclContext.get("graph");
+                            try {
+                                sclContext.put("graph", graph);
+                                return SCLOsgi.MODULE_REPOSITORY.createRuntimeEnvironment(
+                                        environmentSpecification,
+                                        callback.getClass().getClassLoader(), listener);
+                            } catch (ImportFailureException e) {
+                                throw new DatabaseException(e);
+                            } catch (Throwable t) {
+                                throw new DatabaseException(t);
+                            } finally {
+                                sclContext.put("graph", oldGraph);
+                            }
+                        }
+                    });
+                } catch (DatabaseException e) {
+                    callback.exception(e);
+                    return;
+                }
+            else 
+                env = SCLOsgi.MODULE_REPOSITORY.createRuntimeEnvironment(
+                        environmentSpecification,
+                        callback.getClass().getClassLoader(), listener);
+            callback.execute(env);
+        } catch (ImportFailureException e) {
+            callback.exception(new DatabaseException(e));
+        }
+
+    }
+
+    @Override
+    public RuntimeEnvironment perform(ReadGraph graph)
+            throws DatabaseException {
+        final EnvironmentSpecification environmentSpecification = EnvironmentSpecification.of(
+                "Builtin", "",
+                "StandardLibrary", "",
+                "Simantics/All", "");
+        fillEnvironmentSpecification(environmentSpecification);
+
+        Resource mainModule = CommonDBUtils.getPossibleChild(graph, parameter, "SCLMain");
+        String mainModuleUri;
+        if(mainModule != null) {
+            mainModuleUri = graph.getURI(mainModule);
+            environmentSpecification.importModule(mainModuleUri, "");
+        }
+        else
+            mainModuleUri = graph.getURI(parameter) + "/#"; // Add something dummy to the model uri that cannot be in a real URI
+
+        return graph.syncRequest(new ParametrizedPrimitiveRead<String, RuntimeEnvironment>(mainModuleUri) {
+
+            UpdateListenerImpl sclListener;
+
+            @Override
+            public void register(ReadGraph graph, Listener<RuntimeEnvironment> procedure) {
+
+                SCLContext context = SCLContext.getCurrent();
+                Object oldGraph = context.put("graph", graph);
+                try {
+
+                    if(procedure.isDisposed()) {
+                        getRuntimeEnvironment(environmentSpecification, procedure, null);
+                    } else {
+                        sclListener = new UpdateListenerImpl(environmentSpecification, procedure);
+                        sclListener.notifyAboutUpdate();
+                    }
+
+                } finally {
+                    context.put("graph", oldGraph);
+                }
+
+            }
+
+            @Override
+            public void unregistered() {
+                if(sclListener != null)
+                    sclListener.stopListening();
+            }
+
+        });
+    }
+
+    @Override
+    public int hashCode() {
+        return 31*getClass().hashCode() + super.hashCode();
+    }
+
+}
index a07d42519c45741c1cd5c8c038502ca06c4fab4e..dcd3939a4f2e64d73ed288a1856b471c1ab8fd46 100644 (file)
@@ -4,7 +4,6 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashSet;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
 
@@ -16,8 +15,10 @@ import org.simantics.db.WriteGraph;
 import org.simantics.db.common.procedure.adapter.DirectStatementProcedure;
 import org.simantics.db.common.request.IsParent;
 import org.simantics.db.common.request.ObjectsWithType;
+import org.simantics.db.common.request.PossibleChild;
 import org.simantics.db.common.request.PossibleObjectWithType;
 import org.simantics.db.common.request.PossibleOwner;
+import org.simantics.db.common.request.RuntimeEnvironmentRequest;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.exception.InvalidResourceReferenceException;
 import org.simantics.db.service.ClusterUID;
@@ -26,6 +27,10 @@ import org.simantics.db.service.DirectQuerySupport;
 import org.simantics.db.service.SerialisationSupport;
 import org.simantics.db.service.XSupport;
 import org.simantics.layer0.Layer0;
+import org.simantics.scl.compiler.environment.Environments;
+import org.simantics.scl.compiler.runtime.RuntimeEnvironment;
+import org.simantics.scl.compiler.top.SCLExpressionCompilationException;
+import org.simantics.scl.compiler.types.Type;
 import org.simantics.utils.datastructures.collections.CollectionUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -313,5 +318,32 @@ public class CommonDBUtils {
        return xs.isClusterLoaded(clusterUID);
     }
     
+    public static Type getSCLType(ReadGraph graph, RuntimeEnvironment runtimeEnvironment, String typeText) throws DatabaseException {
+        try {
+            return Environments.getType(runtimeEnvironment.getEnvironment(), typeText);
+        } catch (SCLExpressionCompilationException e) {
+            throw new DatabaseException(e);
+        }
+    }
+
+    public static Type getSCLType(ReadGraph graph, Resource resource, String typeText) throws DatabaseException {
+        try {
+            RuntimeEnvironment runtimeEnvironment = graph.syncRequest(new RuntimeEnvironmentRequest(resource));
+            return Environments.getType(runtimeEnvironment.getEnvironment(), typeText);
+        } catch (SCLExpressionCompilationException e) {
+            throw new DatabaseException(e);
+        }
+    }
+
+    public static Resource getPossibleChild(ReadGraph graph, Resource resource, String name) throws DatabaseException {
+        return graph.sync(new PossibleChild(resource, name));
+    }
+
+    public static Resource getPossibleChild(ReadGraph graph, Resource resource, Resource type, String name) throws DatabaseException {
+        Resource child = graph.sync(new PossibleChild(resource, name));
+        if(child == null) return null;
+        if(!graph.isInstanceOf(child, type)) return null;
+        return child;
+    }
     
 }
index a1ed10e77626c56c063aecbabfaa9fd313a2c642..99ef91b7aa0040815b23a4dae559fa1ad3d7d6dd 100644 (file)
@@ -3,41 +3,50 @@ package org.simantics.db.common.validation;
 import org.simantics.databoard.Bindings;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
+import org.simantics.db.common.utils.CommonDBUtils;
 import org.simantics.db.common.utils.NameUtils;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.layer0.Layer0;
+import org.simantics.scl.compiler.types.Type;
 
 public class L0Validations {
 
        public static String checkValueType(ReadGraph graph, Resource subject, Resource predicate) throws DatabaseException {
+               
                if (subject == null)
                        return null;
                if (predicate == null)
                        return null;
 
                Layer0 L0 = Layer0.getInstance(graph);
-           if(graph.isSubrelationOf(predicate, L0.HasProperty)) {
+               if(graph.isSubrelationOf(predicate, L0.HasProperty)) {
                        Resource object = graph.getPossibleObject(subject, predicate);
                        if(object == null) return null;
-               String valueType = graph.getPossibleRelatedValue(predicate, L0.RequiresValueType, Bindings.STRING);
-               if(valueType != null) {
-                       String valueType2 = graph.getPossibleRelatedValue(object, L0.HasValueType, Bindings.STRING);
-                       if(!valueType.equals(valueType2)) {
-                                       StringBuilder sb = new StringBuilder()
-                                       .append("The value type ")
-                                       .append(valueType)
-                                       .append(" of predicate ")
-                                       .append(NameUtils.getSafeName(graph, predicate, true))
-                                       .append(" does not match the value type ")
-                                       .append(valueType2)
-                                       .append(" of object ")
-                                       .append(NameUtils.getSafeName(graph, object, true))
-                                       .append(".");
-                                       return sb.toString();
-                       }
-               }
-           }
-           return null;
+                       String valueTypeText = graph.getPossibleRelatedValue(predicate, L0.RequiresValueType, Bindings.STRING);
+                       if(valueTypeText != null) {
+                               Type valueType = CommonDBUtils.getSCLType(graph, subject, valueTypeText);
+                               String valueTypeText2 = graph.getPossibleRelatedValue(object, L0.HasValueType, Bindings.STRING);
+                               if(valueTypeText2 != null) {
+                                       Type valueType2 = CommonDBUtils.getSCLType(graph, subject, valueTypeText2);
+                                       if(!valueType.equals(valueType2)) {
+                                               StringBuilder sb = new StringBuilder()
+                                                               .append("The value type ")
+                                                               .append(valueType)
+                                                               .append(" of predicate ")
+                                                               .append(NameUtils.getSafeName(graph, predicate, true))
+                                                               .append(" does not match the value type ")
+                                                               .append(valueType2)
+                                                               .append(" of object ")
+                                                               .append(NameUtils.getSafeName(graph, object, true))
+                                                               .append(".");
+                                               return sb.toString();
+                                       }
+                               }
+                       }
+               }
+               
+               return null;
+               
        }
        
 }
index f686835b49d03a38b07eba041fc387dddc0cc326..edf9665deb468a4671d1e4d1f19a3d3bb6163400 100644 (file)
@@ -15,4 +15,5 @@ exclude.. = org/simantics/db/layer0/spm/org.simantics.db.build.zip
 bin.includes = META-INF/,\
                .,\
                plugin.xml,\
-               adapters.xml
+               adapters.xml,\
+               scl/
diff --git a/bundles/org.simantics.db.layer0/scl/Simantics/Layer0.scl b/bundles/org.simantics.db.layer0/scl/Simantics/Layer0.scl
new file mode 100644 (file)
index 0000000..0b034a1
--- /dev/null
@@ -0,0 +1,9 @@
+include "Simantics/DB"
+include "Simantics/Issue"
+
+importJava "org.simantics.db.layer0.function.All" where
+  uriValidator :: Resource -> <ReadGraph> [Issue]
+  valueValidator :: Resource -> <ReadGraph> [Issue]
+  relationValidator :: Resource -> <ReadGraph> [Issue]
+  propertyValidator :: Resource -> <ReadGraph> [Issue]
+  clusterValidator :: Resource -> <ReadGraph> [Issue]
\ No newline at end of file
index 8ae309e6825c9d01af3ded4c754db378a42d55e9..d30be8ffcd21fc9f8ff3dae4a5713e5328270b31 100644 (file)
 package org.simantics.db.layer0.internal;
 
 import java.io.File;
-import java.util.concurrent.TimeUnit;
 
 import org.eclipse.core.runtime.Platform;
 import org.simantics.db.Resource;
-import org.simantics.db.Session;
-import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.layer0.util.SimanticsClipboard;
 import org.simantics.db.layer0.util.SimanticsKeys;
 import org.simantics.db.management.ISessionContext;
-import org.simantics.db.management.ISessionContextProvider;
-import org.simantics.db.management.ISessionContextProviderSource;
-import org.simantics.db.request.ReadInterface;
-import org.simantics.db.request.WriteInterface;
-import org.simantics.layer0.Layer0;
-import org.simantics.operation.Layer0X;
-import org.simantics.utils.threads.ThreadUtils;
 
 /**
  * An internal facade for accessing basic Simantics platform services.
@@ -35,112 +25,7 @@ import org.simantics.utils.threads.ThreadUtils;
  * 
  * Use org.simantics.Simantics instead where ever possible.
  */
-public class SimanticsInternal {
-
-    private static ISessionContextProviderSource providerSource = null;
-
-    /**
-     * Queue execution of a runnable. 
-     * 
-     * @param runnable
-     */
-    public static void async(Runnable runnable) {
-        ThreadUtils.getBlockingWorkExecutor().execute(runnable);
-    }
-
-    public static void async(Runnable runnable, int delay, TimeUnit unit) {
-        ThreadUtils.getTimer().schedule(runnable, delay, unit);
-    }
-    
-    /**
-     * Queue execution of a non-blocking runnable. Use this method with caution. 
-     * A non-blocking runnable nevers locks anything, No Locks, No semaphores,
-     * No Object.wait(), No synchronized() {} blocks.   
-     * 
-     * @param runnable a non-blocking runnable
-     */
-    public static void asyncNonblocking(Runnable runnable) {
-        ThreadUtils.getNonBlockingWorkExecutor().execute(runnable);
-    }
-
-    /**
-     * Schedule execution of a non-blocking runnable. Use this method with caution. 
-     * A non-blocking runnable never locks anything, No Locks, No semaphores,
-     * No Object,wait(), No synchronized() {} blocks.   
-     * 
-     * @param runnable a non-blocking runnable
-     * @param initialDelay
-     * @param period
-     */
-    public static void asyncNonblocking(Runnable runnable, int initialDelay, int period) {
-        ThreadUtils.getNonBlockingWorkExecutor().scheduleAtFixedRate(runnable, initialDelay, period, TimeUnit.MILLISECONDS);
-    }
-    
-    public static synchronized ISessionContext setSessionContext(ISessionContext ctx) {
-        return getSessionContextProvider().setSessionContext(ctx);
-    }
-
-    public static void setSessionContextProviderSource(ISessionContextProviderSource source) {
-        if (source == null)
-            throw new IllegalArgumentException("null provider source");
-        providerSource = source;
-    }
-
-    public static ISessionContextProviderSource getProviderSource() {
-        if (providerSource == null)
-            throw new IllegalStateException(
-            "providerSource must be initialized by the application before using class Simantics");
-        return providerSource;
-    }
-
-    public static ISessionContextProvider getSessionContextProvider() {
-        return getProviderSource().getActive();
-    }
-
-    /**
-     * Returns the database session context associated with the currently active
-     * context. This method should be used to retrieve session contexts only
-     * when the client is sure that the correct context is active.
-     * 
-     * @return the session context associated with the currently active context
-     *         or <code>null</code> if the context has no session context
-     */
-    public static ISessionContext getSessionContext() {
-        ISessionContextProvider provider = getSessionContextProvider();
-        return provider != null ? provider.getSessionContext() : null;
-    }
-
-    /**
-     * Returns the database Session bound to the currently active context.
-     * 
-     * <p>
-     * The method always returns a non-null Session or produces an
-     * IllegalStateException if a Session was not attainable.
-     * </p>
-     * 
-     * @return the Session bound to the currently active workbench window
-     * @throws IllegalStateException if no Session was available
-     */
-    public static Session getSession() {
-        ISessionContext ctx = getSessionContext();
-        if (ctx == null)
-            throw new IllegalStateException("Session unavailable, no database session open");
-        return ctx.getSession();
-    }
-
-    /**
-     * Returns the database Session bound to the currently active context.
-     * Differently from {@link #getSession()}, this method returns
-     * <code>null</code> if there is no current Session available.
-     * 
-     * @see #getSession()
-     * @return the Session bound to the currently active context or
-     *         <code>null</code>
-     */
-    public static Session peekSession() {
-        ISessionContext ctx = getSessionContext();
-        return ctx == null ? null : ctx.peekSession();
-    }
+public class SimanticsInternal extends org.simantics.db.common.SimanticsInternal {
 
     /**
      * @return the currently open and active project as an IProject
@@ -179,23 +64,6 @@ public class SimanticsInternal {
         return clipboard;
     }
 
-    public static Layer0 getLayer0() throws DatabaseException {
-        return Layer0.getInstance(getSession());
-    }
-
-    public static Layer0X getLayer0X() throws DatabaseException {
-        return Layer0X.getInstance(getSession());
-    }
-
-    
-    public static <T> T sync(ReadInterface<T> r) throws DatabaseException {
-       return getSession().sync(r);
-    }
-    
-    public static <T> T sync(WriteInterface<T> r) throws DatabaseException {
-       return getSession().sync(r);
-    }
-    
     public static File getTemporaryDirectory() {
         File workspace = Platform.getLocation().toFile();
         File temp = new File(workspace, "tempFiles");
index 62c7093da11e999d7e22b60a17ccb1221088fe18..610c8c8bd42d8735868cf1f80e4603ae5e63b7d8 100644 (file)
@@ -74,6 +74,7 @@ import org.simantics.db.common.request.ObjectsWithType;
 import org.simantics.db.common.request.PossibleChild;
 import org.simantics.db.common.request.PossibleIndexRoot;
 import org.simantics.db.common.request.WriteRequest;
+import org.simantics.db.common.utils.CommonDBUtils;
 import org.simantics.db.common.utils.NameUtils;
 import org.simantics.db.event.ChangeListener;
 import org.simantics.db.exception.CancelTransactionException;
@@ -353,13 +354,9 @@ public class Layer0Utils {
                throw new IllegalArgumentException("Unable to convert datatype into SCL type: " + type);
        }
 
-
+       @Deprecated
        public static Type getSCLType(ReadGraph graph, RuntimeEnvironment runtimeEnvironment, String typeText) throws DatabaseException {
-        try {
-                       return Environments.getType(runtimeEnvironment.getEnvironment(), typeText);
-               } catch (SCLExpressionCompilationException e) {
-                       throw new DatabaseException(e);
-               }
+           return CommonDBUtils.getSCLType(graph, runtimeEnvironment, typeText);
        }
 
        public static Type getSCLType(ReadGraph graph, Variable property) throws DatabaseException {
@@ -646,15 +643,14 @@ public class Layer0Utils {
                return graph.getPossibleResource(graph.getURI(root) + suffix);
        }
 
+       @Deprecated
        public static Resource getPossibleChild(ReadGraph graph, Resource resource, String name) throws DatabaseException {
-               return graph.sync(new PossibleChild(resource, name));
+               return CommonDBUtils.getPossibleChild(graph, resource, name);
        }
 
+       @Deprecated
        public static Resource getPossibleChild(ReadGraph graph, Resource resource, Resource type, String name) throws DatabaseException {
-               Resource child = graph.sync(new PossibleChild(resource, name));
-               if(child == null) return null;
-               if(!graph.isInstanceOf(child, type)) return null;
-               return child;
+               return CommonDBUtils.getPossibleChild(graph, resource, type, name);
        }
 
        public static RelationContext relationContext(ReadGraph graph, Resource subject, Resource predicate) throws DatabaseException {
index 9f6b8fe530799439bcad7f3d9fab82319fc2733a..17fbf1e7c8cb562a41bfc387b5b46b4478d48e36 100644 (file)
@@ -1,19 +1,6 @@
 package org.simantics.db.layer0.util;
 
-import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
-import org.simantics.db.common.request.ParametrizedPrimitiveRead;
-import org.simantics.db.common.request.UnaryRead;
-import org.simantics.db.exception.DatabaseException;
-import org.simantics.db.layer0.internal.SimanticsInternal;
-import org.simantics.db.procedure.Listener;
-import org.simantics.db.request.Read;
-import org.simantics.scl.compiler.environment.specification.EnvironmentSpecification;
-import org.simantics.scl.compiler.module.repository.ImportFailureException;
-import org.simantics.scl.compiler.module.repository.UpdateListener;
-import org.simantics.scl.compiler.runtime.RuntimeEnvironment;
-import org.simantics.scl.osgi.SCLOsgi;
-import org.simantics.scl.runtime.SCLContext;
 
 /**
  * Finds the runtime environment of a model or other index root.
@@ -21,134 +8,11 @@ import org.simantics.scl.runtime.SCLContext;
  * @author Hannu Niemist&ouml;
  * @author Antti Villberg
  */
-public class RuntimeEnvironmentRequest extends UnaryRead<Resource, RuntimeEnvironment> {
+@Deprecated
+public class RuntimeEnvironmentRequest extends org.simantics.db.common.request.RuntimeEnvironmentRequest {
 
     public RuntimeEnvironmentRequest(Resource parameter) {
         super(parameter);
     }
 
-    protected void fillEnvironmentSpecification(EnvironmentSpecification environmentSpecification) {
-    }
-
-    static class UpdateListenerImpl extends UpdateListener {
-
-        final EnvironmentSpecification environmentSpecification;
-        final Listener<RuntimeEnvironment> callback;
-
-        UpdateListenerImpl(EnvironmentSpecification environmentSpecification, Listener<RuntimeEnvironment> callback) {
-            this.environmentSpecification = environmentSpecification;
-            this.callback = callback;
-        }
-
-        @Override
-        public void notifyAboutUpdate() {
-            if(callback.isDisposed()) {
-                stopListening();
-                return;
-            }
-            getRuntimeEnvironment(environmentSpecification, callback, this);
-        }
-    };
-
-    public static void getRuntimeEnvironment(EnvironmentSpecification environmentSpecification, Listener<RuntimeEnvironment> callback, UpdateListenerImpl listener) {
-
-        try {
-
-            SCLContext context = SCLContext.getCurrent();
-
-            RuntimeEnvironment env;
-            Object graph = context.get("graph");
-            if(graph == null)
-                try {
-                    env = SimanticsInternal.getSession().syncRequest(new Read<RuntimeEnvironment>() {
-                        @Override
-                        public RuntimeEnvironment perform(ReadGraph graph) throws DatabaseException {
-
-                            SCLContext sclContext = SCLContext.getCurrent();
-                            Object oldGraph = sclContext.get("graph");
-                            try {
-                                sclContext.put("graph", graph);
-                                return SCLOsgi.MODULE_REPOSITORY.createRuntimeEnvironment(
-                                        environmentSpecification,
-                                        callback.getClass().getClassLoader(), listener);
-                            } catch (ImportFailureException e) {
-                                throw new DatabaseException(e);
-                            } catch (Throwable t) {
-                                throw new DatabaseException(t);
-                            } finally {
-                                sclContext.put("graph", oldGraph);
-                            }
-                        }
-                    });
-                } catch (DatabaseException e) {
-                    callback.exception(e);
-                    return;
-                }
-            else 
-                env = SCLOsgi.MODULE_REPOSITORY.createRuntimeEnvironment(
-                        environmentSpecification,
-                        callback.getClass().getClassLoader(), listener);
-            callback.execute(env);
-        } catch (ImportFailureException e) {
-            callback.exception(new DatabaseException(e));
-        }
-
-    }
-
-    @Override
-    public RuntimeEnvironment perform(ReadGraph graph)
-            throws DatabaseException {
-        final EnvironmentSpecification environmentSpecification = EnvironmentSpecification.of(
-                "Builtin", "",
-                "StandardLibrary", "",
-                "Simantics/All", "");
-        fillEnvironmentSpecification(environmentSpecification);
-
-        Resource mainModule = Layer0Utils.getPossibleChild(graph, parameter, "SCLMain");
-        String mainModuleUri;
-        if(mainModule != null) {
-            mainModuleUri = graph.getURI(mainModule);
-            environmentSpecification.importModule(mainModuleUri, "");
-        }
-        else
-            mainModuleUri = graph.getURI(parameter) + "/#"; // Add something dummy to the model uri that cannot be in a real URI
-
-        return graph.syncRequest(new ParametrizedPrimitiveRead<String, RuntimeEnvironment>(mainModuleUri) {
-
-            UpdateListenerImpl sclListener;
-
-            @Override
-            public void register(ReadGraph graph, Listener<RuntimeEnvironment> procedure) {
-
-                SCLContext context = SCLContext.getCurrent();
-                Object oldGraph = context.put("graph", graph);
-                try {
-
-                    if(procedure.isDisposed()) {
-                        getRuntimeEnvironment(environmentSpecification, procedure, null);
-                    } else {
-                        sclListener = new UpdateListenerImpl(environmentSpecification, procedure);
-                        sclListener.notifyAboutUpdate();
-                    }
-
-                } finally {
-                    context.put("graph", oldGraph);
-                }
-
-            }
-
-            @Override
-            public void unregistered() {
-                if(sclListener != null)
-                    sclListener.stopListening();
-            }
-
-        });
-    }
-
-    @Override
-    public int hashCode() {
-        return 31*getClass().hashCode() + super.hashCode();
-    }
-
 }
index 673eeaee5847e0bbc2c9dfba59f0038cc2143e0d..47c829cd86443ae0d04bfaf5803da028dabbc5d7 100644 (file)
@@ -1,7 +1,6 @@
 package org.simantics.db.layer0.validation;
 
-import gnu.trove.set.hash.THashSet;
-
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 import java.util.Map;
@@ -18,6 +17,8 @@ import org.simantics.db.layer0.util.DomainProcessor3;
 import org.simantics.db.layer0.util.ModelTransferableGraphSourceRequest;
 import org.simantics.layer0.Layer0;
 
+import gnu.trove.set.hash.THashSet;
+
 public class ValidationUtils {
 
     /**
@@ -62,7 +63,7 @@ public class ValidationUtils {
         return validateConstraints(graph, r, null);
     }
 
-    public static Set<Issue> validateConstraintsForDomain(ReadGraph graph, Resource r) throws DatabaseException {
+    public static List<Issue> validateConstraintsForDomain(ReadGraph graph, Resource r) throws DatabaseException {
         Set<Issue> result = null;
 
         DomainProcessor3 dp = ModelTransferableGraphSourceRequest.getDomainOnly(graph, null, r);
@@ -75,7 +76,7 @@ public class ValidationUtils {
             }
         }
 
-        return result != null ? result : Collections.<Issue>emptySet();
+        return result != null ? new ArrayList(result) : Collections.<Issue>emptyList();
     }
 
 }
index ecf2439e8be4fdbbd352a8c17f125f9cae7141e7..75fdb8b6f209d4850f4bf5fa55b4b1ce2872ef6f 100644 (file)
@@ -5,9 +5,9 @@ Bundle-SymbolicName: org.simantics.db.management
 Bundle-Version: 1.1.0.qualifier
 Bundle-Activator: org.simantics.db.management.internal.Activator
 Bundle-Vendor: VTT Technical Research Centre of Finland
-Require-Bundle: org.simantics.db.services;bundle-version="0.8.0",
- org.simantics.db.procore;bundle-version="0.8.0",
- org.eclipse.core.runtime;bundle-version="3.5.0"
+Require-Bundle: org.eclipse.core.runtime;bundle-version="3.5.0",
+ org.simantics.utils;bundle-version="1.1.0",
+ org.simantics.layer0;bundle-version="1.1.0"
 Bundle-ActivationPolicy: lazy
 Export-Package: org.simantics.db.management,
  org.simantics.db.management.discovery
index dae8bea7545184cbf7faf82dbc76f6ababa8ab35..88293f42b90f97e79dc9e2ff46113854ba48d43f 100644 (file)
@@ -16,19 +16,14 @@ import java.util.Arrays;
 import java.util.UUID;
 import java.util.concurrent.TimeoutException;
 
-import org.eclipse.core.runtime.IStatus;
 import org.simantics.db.Disposable;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.Session;
 import org.simantics.db.VirtualGraph;
-import org.simantics.db.common.processor.MergingDelayedWriteProcessor;
-import org.simantics.db.common.processor.MergingGraphRequestProcessor;
-import org.simantics.db.common.request.ReadRequest;
 import org.simantics.db.exception.DatabaseException;
-import org.simantics.db.management.internal.Activator;
+import org.simantics.db.request.Read;
 import org.simantics.db.service.LifecycleSupport;
 import org.simantics.db.service.VirtualGraphSupport;
-import org.simantics.db.services.GlobalServiceInitializer;
 import org.simantics.layer0.Layer0;
 import org.simantics.utils.datastructures.disposable.DisposeState;
 import org.simantics.utils.datastructures.disposable.IDisposable;
@@ -46,16 +41,11 @@ import org.simantics.utils.threads.SyncListenerList;
  * @author Tuukka Lehtonen
  */
 public class SessionContext extends HintContext implements ISessionContext, Disposable {
-    private static final boolean    SESSION_DEBUG            = false;
 
-//    private final IServerAddress        address;
+       private static final boolean    SESSION_DEBUG            = false;
 
     private Session                 session;
 
-    private boolean                 servicesRegistered       = false;
-
-    private IStatus                 servicesRegisteredStatus = null;
-
     public static SessionContext create(Session session, boolean initialize) throws DatabaseException {
         return new SessionContext(session, initialize);
     }
@@ -67,40 +57,21 @@ public class SessionContext extends HintContext implements ISessionContext, Disp
     }
 
     private void initializeSession(Session s) throws DatabaseException {
-        s.registerService(MergingGraphRequestProcessor.class, new MergingGraphRequestProcessor("SessionService", s, 20));
-        s.registerService(MergingDelayedWriteProcessor.class, new MergingDelayedWriteProcessor(s, 20));
         s.registerService(VirtualGraph.class, s.getService(VirtualGraphSupport.class).getMemoryPersistent(UUID.randomUUID().toString()));
 
         // Builtins needs to be initialized for the new session before
         // anything useful can be done with it.
-        s.syncRequest(new ReadRequest() {
+        s.syncRequest(new Read<Object>() {
             @Override
-            public void run(ReadGraph g) {
+            public Object perform(ReadGraph g) {
                 // Registers Builtins with the ServiceLocator of the Graph's session.
                Layer0.getInstance(g);
+               return null;
             }
         });
+        
     }
 
-    public void registerServices() {
-        if (servicesRegistered)
-            return;
-
-        // Register any services available for the SessionLocator of the new
-        // Session.
-        servicesRegisteredStatus = new GlobalServiceInitializer().initialize(session);
-        if (!servicesRegisteredStatus.isOK()) {
-            Activator.getDefault().getLog().log(servicesRegisteredStatus);
-        }
-
-        servicesRegistered = true;
-    }
-
-//    @Override
-//    public IServerAddress getAddress() {
-//        return address;
-//    }
-
     @Override
     public Session getSession() {
         if (session == null)
diff --git a/bundles/org.simantics.db.management/src/org/simantics/db/management/internal/SessionManagerProvider.java b/bundles/org.simantics.db.management/src/org/simantics/db/management/internal/SessionManagerProvider.java
deleted file mode 100644 (file)
index 8196712..0000000
+++ /dev/null
@@ -1,68 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2011 Association for Decentralized Information Management
- * in Industry THTH ry.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *     VTT Technical Research Centre of Finland - initial API and implementation
- *******************************************************************************/
-package org.simantics.db.management.internal;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-import java.util.Properties;
-
-import org.eclipse.core.runtime.Platform;
-import org.osgi.framework.Bundle;
-import org.simantics.db.SessionManager;
-import org.simantics.utils.FileUtils;
-
-import fi.vtt.simantics.procore.SessionManagerSource;
-
-/**
- * Complete hack for the time being. Simply provides the SessionManager behind
- * procore's SessionManagerSource with proper initialization.
- */
-public final class SessionManagerProvider {
-
-    // TODO: move this into BundleContext as a service ?
-    private static SessionManagerProvider provider;
-
-    private SessionManager sessionManager;
-
-    public static SessionManagerProvider getInstance() {
-        if (provider == null)
-            provider = new SessionManagerProvider();
-        return provider;
-    }
-
-    public SessionManager getSessionManager() throws IOException {
-        if (sessionManager == null) {
-            sessionManager = SessionManagerSource.getSessionManager(loadProperties());
-        }
-        return sessionManager;
-    }
-
-    private Properties loadProperties() {
-        Bundle procore = Platform.getBundle("org.simantics.db.procore");
-        URL url = procore.getResource("log4j.properties");
-        if (url != null) {
-            InputStream in = null;
-            try {
-                in = url.openStream();
-                Properties props = new Properties();
-                props.load(in);
-                return props;
-            } catch (Exception e) {
-            } finally {
-                FileUtils.uncheckedClose(in);
-            }
-        }
-        return null;
-    }
-
-}
index 7403f3d7004f475e4de2bd17d7006cef5739d349..bb78bf41ee57507907c197c3fa84286e0bcded56 100644 (file)
@@ -6,9 +6,13 @@ Bundle-Version: 1.1.0.qualifier
 Bundle-Vendor: VTT Technical Research Centre of Finland
 Require-Bundle: org.eclipse.core.runtime,
  gnu.trove3,
- org.simantics.layer0.utils;bundle-version="1.1.0",
  org.simantics.layer0x.ontology;bundle-version="1.0.0",
- org.slf4j.api;bundle-version="1.7.25"
+ org.slf4j.api;bundle-version="1.7.25",
+ org.simantics.utils;bundle-version="1.1.0",
+ org.simantics.db;bundle-version="1.1.0",
+ org.simantics.scl.reflection,
+ org.simantics.db.common;bundle-version="1.1.0",
+ org.simantics.layer0.utils
 Export-Package: org.simantics.db.services,
  org.simantics.db.services.activation,
  org.simantics.db.services.adaption
index 578b42a61d885d13cfb06e20e7c31436d00a6af2..fe9bab55201f188be514d33c2d21e702586be0a1 100644 (file)
@@ -36,6 +36,7 @@ import org.simantics.db.adaption.AdapterInstaller;
 import org.simantics.db.adaption.AdaptionService;
 import org.simantics.db.common.request.ReadRequest;
 import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.request.Read;
 import org.simantics.db.services.adaption.reflection.AdaptingDynamicAdapter2;
 import org.simantics.db.services.adaption.reflection.AtMostOneRelatedResource2;
 import org.simantics.db.services.adaption.reflection.ConstantAdapter;
@@ -337,9 +338,9 @@ public class AdapterRegistry2 {
     }
 
     public void updateAdaptionService(Session s, final AdaptionService service) throws DatabaseException {
-        s.syncRequest(new ReadRequest() {
+        s.syncRequest(new Read() {
             @Override
-            public void run(ReadGraph g) {
+            public Object perform(ReadGraph g) {
                 for(AdapterInstaller t : installerSources.keySet()) {
                     try {
                         t.install(g, service);
@@ -347,6 +348,7 @@ public class AdapterRegistry2 {
                         AdapterRegistry2.this.handleException(e, t);
                     }
                 }
+                return null;
             }
         });
     }
index 187fc52199a390f37b68b3a48a940d20faa4d359..42eb3d8bee0cf2cfd7fed0b8e47555665341931f 100644 (file)
@@ -18,12 +18,16 @@ import java.util.Arrays;
 import org.simantics.db.AsyncReadGraph;
 import org.simantics.db.Resource;
 import org.simantics.db.adaption.Adapter;
-import org.simantics.db.common.request.AsyncReadRequest;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.procedure.AsyncProcedure;
+import org.simantics.db.request.AsyncRead;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class ReflectionAdapter2<T> implements Adapter<T, Resource> {
 
+       private static final Logger LOGGER = LoggerFactory.getLogger(ReflectionAdapter2.class);
+
        Constructor<? extends T> constructor;
        IDynamicAdapter2[] parameters;
        
@@ -40,22 +44,20 @@ public class ReflectionAdapter2<T> implements Adapter<T, Resource> {
 
        if(parameters.length == 0) {
            
-//            System.out.println("ReflectionAdapter2 " + ReflectionAdapter2.this);
-
            try {
                 procedure.execute(g, constructor.newInstance());
             } catch (IllegalArgumentException e) {
                 procedure.exception(g, e);
-                e.printStackTrace();
+                LOGGER.error("Unexpected exception during adapter creation", e);
             } catch (InstantiationException e) {
                 procedure.exception(g, e);
-                e.printStackTrace();
+                LOGGER.error("Unexpected exception during adapter creation", e);
             } catch (IllegalAccessException e) {
                 procedure.exception(g, e);
-                e.printStackTrace();
+                LOGGER.error("Unexpected exception during adapter creation", e);
             } catch (InvocationTargetException e) {
                 procedure.exception(g, e.getCause());
-                e.getCause().printStackTrace();
+                LOGGER.error("Unexpected exception during adapter creation", e.getCause());
             }
             
        } else if( parameters.length == 1 && parameters[0] instanceof ThisResource2) {
@@ -64,49 +66,50 @@ public class ReflectionAdapter2<T> implements Adapter<T, Resource> {
                 procedure.execute(g, constructor.newInstance(r));
             } catch (IllegalArgumentException e) {
                 procedure.exception(g, e);
-                e.printStackTrace();
+                LOGGER.error("Unexpected exception during adapter creation", e);
             } catch (InstantiationException e) {
                 procedure.exception(g, e);
-                e.printStackTrace();
+                LOGGER.error("Unexpected exception during adapter creation", e);
             } catch (IllegalAccessException e) {
                 procedure.exception(g, e);
-                e.printStackTrace();
+                LOGGER.error("Unexpected exception during adapter creation", e);
             } catch (InvocationTargetException e) {
                 procedure.exception(g, e.getCause());
-                e.getCause().printStackTrace();
+                LOGGER.error("Unexpected exception during adapter creation", e.getCause());
             }
                
        } else {
        
-            g.asyncRequest(new AsyncReadRequest() {
-    
+            g.asyncRequest(new AsyncRead<T>() {
+                
                 @Override
-                public void run(AsyncReadGraph graph) {
-                       
+                public void perform(AsyncReadGraph graph, AsyncProcedure<T> p) {
+                    
                     Object[] args = new Object[parameters.length];
                     try {
-                       for(int i=0;i<parameters.length;++i)
-                               args[i] = parameters[i].adapt(graph, r);
-                       procedure.execute(graph, constructor.newInstance(args));
-                               } catch (IllegalArgumentException e) {
-                                   procedure.exception(g, e);
-                                       e.printStackTrace();
-                               } catch (InstantiationException e) {
-                        procedure.exception(g, e);
-                                       e.printStackTrace();
-                               } catch (IllegalAccessException e) {
-                        procedure.exception(g, e);
-                                       e.printStackTrace();
-                               } catch (InvocationTargetException e) {
-                        procedure.exception(g, e.getCause());
-                                       e.getCause().printStackTrace();
-                               } catch (DatabaseException e) {
-                        procedure.exception(g, e);
-                                       e.printStackTrace();
-                               } catch (Throwable t) {
-                                   procedure.exception(g, t);
-                                   t.printStackTrace();
-                               }
+                        for(int i=0;i<parameters.length;++i)
+                            args[i] = parameters[i].adapt(graph, r);
+                        p.execute(graph, constructor.newInstance(args));
+                    } catch (IllegalArgumentException e) {
+                        p.exception(g, e);
+                        LOGGER.error("Unexpected exception during adapter creation", e);
+                    } catch (InstantiationException e) {
+                        p.exception(g, e);
+                        LOGGER.error("Unexpected exception during adapter creation", e);
+                    } catch (IllegalAccessException e) {
+                        p.exception(g, e);
+                        LOGGER.error("Unexpected exception during adapter creation", e);
+                    } catch (InvocationTargetException e) {
+                        p.exception(g, e.getCause());
+                        LOGGER.error("Unexpected exception during adapter creation", e);
+                    } catch (DatabaseException e) {
+                        p.exception(g, e);
+                        LOGGER.error("Unexpected exception during adapter creation", e);
+                    } catch (Throwable t) {
+                        p.exception(g, t);
+                        LOGGER.error("Unexpected exception during adapter creation", t);
+                    }
+                    
                 }
                 
                 @Override
@@ -114,7 +117,7 @@ public class ReflectionAdapter2<T> implements Adapter<T, Resource> {
                        return "ReflectionAdapter$1" + constructor + "$" + Arrays.toString(parameters);
                 }
                 
-            });
+            }, procedure);
         
        }
         
index f9f82e4a002e3ce7f332d6bae9ab08bb86182430..36f82a01dc69cee7d9cf3b0de233753343b1b851 100644 (file)
@@ -17,10 +17,10 @@ Export-Package: org.simantics.layer0.utils,
  org.simantics.layer0.utils.triggers,
  org.simantics.layer0.utils.writer
 Require-Bundle: gnu.trove3;bundle-version="3.0.3",
- org.simantics.db.common;bundle-version="0.8.0";visibility:=reexport,
  org.eclipse.equinox.common;bundle-version="3.5.0",
  org.simantics.layer0;bundle-version="1.0.0",
- org.simantics.layer0x.ontology;bundle-version="1.0.0"
+ org.simantics.layer0x.ontology;bundle-version="1.0.0",
+ org.simantics.db.common;bundle-version="1.1.0"
 Bundle-Vendor: VTT Technical Research Centre of Finland
 Bundle-ClassPath: .
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
index e3d00e8aa418fa57ebcacaf4da42650fc44ac3f3..d169c9684402f401abe44a54be69db6457e83cad 100644 (file)
@@ -4,6 +4,9 @@
 L0 = <http://www.simantics.org/Layer0-1.1> : L0.Ontology
     L0.HasResourceClass "org.simantics.layer0.Layer0"
 
+L0.SCLMain : L0.SCLModule
+    L0.SCLModule.definition """ include "Simantics/Layer0" """
+
 // Types
 L0.Entity : L0.Type
     L0.HasDescription "All types are inherited from this type."
@@ -42,6 +45,7 @@ L0.Entity : L0.Type
     >-- L0.Entity.methods
     @L0.assert L0.Entity.methods
       _ : L0.Property
+        L0.HasValueType "StructuredProperty"
     
 L0.Entity.methods ==> "StructuredProperty" <R L0.HasProperty : L0.FunctionalRelation
   L0.domainProperties L0.Functions.methodsPropertyDomainProperties
index fb9d271bb141a66f35f23e78b10b817e22b82b30..afa68bbe2cbeb62dc938bba618e34c24c12366e5 100644 (file)
@@ -2,7 +2,11 @@ L0 = <http://www.simantics.org/Layer0-1.1>
 
 L0.Constraint <T L0.Entity
     >-- L0.Constraint.Validator <R L0.HasProperty : L0.FunctionalRelation
-        L0.RequiresValueType "ReadGraph => Resource -> [Issue]"
+        L0.RequiresValueType "Resource -> <ReadGraph> [Issue]"
+
+L0.SCLValidator <T L0.SCLValue
+    L0.HasValueType "Resource -> <ReadGraph> [Issue]"
+    
 L0.HasConstraint <R L0.IsRelatedTo
     L0.InverseOf L0.HasConstraint.Inverse <R L0.IsRelatedTo     
     <-- L0.Type
index 0dbba3181589a58260003ff062c3e4da753ee895..ef5a587e521376e2ddc39de4af0a3e11059e3b9d 100644 (file)
@@ -50,3 +50,10 @@ L0.sclAction : L0.Template
           L0.SCLAction.action _ : L0.SCLValue
             L0.SCLValue.expression %expression
             L0.HasValueType L0.SCLAction.valueType
+
+L0.sclConstraint : L0.Template
+    @template %constraint %expression
+      %constraint : L0.Constraint
+        L0.Constraint.Validator _ : L0.SCLValidator
+          L0.SCLValue.expression %expression
+
index 7c9f35bd75b511303ec430e25d9d7e85c638c94b..f192ea6fdc29b8bee6b710c0c5b1cc49c60e902b 100644 (file)
@@ -1,16 +1,14 @@
 L0 = <http://www.simantics.org/Layer0-1.1>
 
 L0.Entity
-  L0.HasConstraint L0.Entity.RelationConstraint : L0.Constraint
-    L0.Constraint.Validator L0.Functions.relationValidator
-  L0.HasConstraint L0.Entity.PropertyConstraint : L0.Constraint
-    L0.Constraint.Validator L0.Functions.propertyValidator
-  L0.HasConstraint L0.Entity.ValueConstraint : L0.Constraint
-    L0.Constraint.Validator L0.Functions.valueValidator
-  L0.HasConstraint L0.Entity.URIConstraint : L0.Constraint
-    L0.Constraint.Validator L0.Functions.uriValidator
-  L0.HasConstraint L0.Entity.ClusterConstraint : L0.Constraint
-    L0.Constraint.Validator L0.Functions.clusterValidator
-
-
-        
\ No newline at end of file
+  L0.HasConstraint L0.Entity.RelationConstraint
+    @L0.sclConstraint "relationValidator"
+  L0.HasConstraint L0.Entity.PropertyConstraint
+    @L0.sclConstraint "propertyValidator"
+  L0.HasConstraint L0.Entity.ValueConstraint
+    @L0.sclConstraint "valueValidator"
+  L0.HasConstraint L0.Entity.ClusterConstraint
+    @L0.sclConstraint "clusterValidator"
+  L0.HasConstraint L0.Entity.URIConstraint
+    @L0.sclConstraint "uriValidator"
+    
\ No newline at end of file
index 2504ba62d8f9ae04f4111bfbdaafa0086409d8f1..7839ce70db31de7b0de4dc80d6725e8dc603b505 100644 (file)
@@ -45,6 +45,8 @@ import org.eclipse.osgi.service.datalocation.Location;
 import org.eclipse.osgi.service.resolver.BundleDescription;
 import org.ini4j.Ini;
 import org.ini4j.InvalidFileFormatException;
+import org.simantics.SimanticsPlatform.OntologyRecoveryPolicy;
+import org.simantics.SimanticsPlatform.RecoveryPolicy;
 import org.simantics.databoard.Bindings;
 import org.simantics.databoard.Databoard;
 import org.simantics.datatypes.literal.Font;
@@ -59,6 +61,8 @@ import org.simantics.db.SessionModel;
 import org.simantics.db.UndoContext;
 import org.simantics.db.VirtualGraph;
 import org.simantics.db.WriteGraph;
+import org.simantics.db.common.processor.MergingDelayedWriteProcessor;
+import org.simantics.db.common.processor.MergingGraphRequestProcessor;
 import org.simantics.db.common.request.ObjectsWithType;
 import org.simantics.db.common.request.WriteResultRequest;
 import org.simantics.db.common.utils.Transaction;
@@ -82,6 +86,7 @@ import org.simantics.db.service.QueryControl;
 import org.simantics.db.service.UndoRedoSupport;
 import org.simantics.db.service.VirtualGraphSupport;
 import org.simantics.db.service.XSupport;
+import org.simantics.db.services.GlobalServiceInitializer;
 import org.simantics.graph.db.GraphDependencyAnalyzer;
 import org.simantics.graph.db.GraphDependencyAnalyzer.IU;
 import org.simantics.graph.db.GraphDependencyAnalyzer.IdentityNode;
@@ -950,6 +955,13 @@ public class SimanticsPlatform implements LifecycleListener {
 
     }
 
+    public void registerServices(SessionContext context) {
+        new GlobalServiceInitializer().initialize(session);
+        session.registerService(MergingGraphRequestProcessor.class, new MergingGraphRequestProcessor("SessionService", session, 20));
+        session.registerService(MergingDelayedWriteProcessor.class, new MergingDelayedWriteProcessor(session, 20));
+    }
+
+
     public SessionContext createSessionContext(boolean init) throws PlatformException {
         try {
             // Construct and initialize SessionContext from Session.
@@ -957,7 +969,7 @@ public class SimanticsPlatform implements LifecycleListener {
             String message = "Session context created";
             LOGGER.info(message);
             if (init) {
-                sessionContext.registerServices();
+                registerServices(sessionContext);
                 message = "Session services registered";
                 LOGGER.info(message);
             }