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,
--- /dev/null
+/*******************************************************************************
+ * 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);
+ }
+
+}
--- /dev/null
+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ö
+ * @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();
+ }
+
+}
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.List;
import java.util.Set;
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;
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;
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;
+ }
}
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;
+
}
}
bin.includes = META-INF/,\
.,\
plugin.xml,\
- adapters.xml
+ adapters.xml,\
+ scl/
--- /dev/null
+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
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.
*
* 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
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");
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;
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 {
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 {
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.
* @author Hannu Niemistö
* @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();
- }
-
}
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;
import org.simantics.db.layer0.util.ModelTransferableGraphSourceRequest;
import org.simantics.layer0.Layer0;
+import gnu.trove.set.hash.THashSet;
+
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);
}
}
- return result != null ? result : Collections.<Issue>emptySet();
+ return result != null ? new ArrayList(result) : Collections.<Issue>emptyList();
}
}
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
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;
* @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);
}
}
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)
+++ /dev/null
-/*******************************************************************************
- * 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;
- }
-
-}
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
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;
}
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);
AdapterRegistry2.this.handleException(e, t);
}
}
+ return null;
}
});
}
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;
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) {
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
return "ReflectionAdapter$1" + constructor + "$" + Arrays.toString(parameters);
}
- });
+ }, procedure);
}
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
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."
>-- 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
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
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
+
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
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;
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;
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;
}
+ 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.
String message = "Session context created";
LOGGER.info(message);
if (init) {
- sessionContext.registerServices();
+ registerServices(sessionContext);
message = "Session services registered";
LOGGER.info(message);
}