* More control over computational values served by ReadGraph.
* More cacheable Connections (Connection2)
gitlab #169
Change-Id: I304de13f97c25661fed2905e33887e315144591e
package org.simantics.db.common.request;
+import org.simantics.db.ComputationalValue;
import org.simantics.db.ReadGraph;
import org.simantics.db.Resource;
import org.simantics.db.common.utils.Functions;
import org.simantics.db.exception.DatabaseException;
import org.simantics.db.exception.RuntimeDatabaseException;
import org.simantics.layer0.Layer0;
-import org.simantics.scl.reflection.ReflectionUtils;
-import org.simantics.scl.reflection.ValueNotFoundException;
import org.simantics.scl.runtime.function.FunctionImpl3;
/**
super(resource);
}
- private static final FunctionImpl3<ReadGraph,Resource,Object,Object> functionApplication = new FunctionImpl3<ReadGraph,Resource,Object,Object>() {
+ public static final FunctionImpl3<ReadGraph,Resource,Object,Object> functionApplication = new FunctionImpl3<ReadGraph,Resource,Object,Object>() {
@Override
public Object apply(ReadGraph graph, Resource resource, Object context) {
@Override
public Object perform(ReadGraph graph) throws DatabaseException {
String uri = graph.getURI(resource);
- try {
- if(Layer0.URIs.Functions_functionApplication.equals(uri)) return functionApplication;
- return ReflectionUtils.getValue(uri).getValue();
- } catch (ValueNotFoundException e) {
- throw new DatabaseException("Couldn't adapt the value " + uri, e);
- }
+ if(Layer0.URIs.Functions_functionApplication.equals(uri)) return functionApplication;
+ ComputationalValue ev = graph.adapt(resource, ComputationalValue.class);
+ return ev.getValue(graph, resource);
+
}
}
import org.simantics.databoard.util.binary.BinaryFile;
import org.simantics.databoard.util.binary.RandomAccessBinary;
import org.simantics.db.AsyncReadGraph;
+import org.simantics.db.ComputationalValue;
import org.simantics.db.DevelopmentKeys;
import org.simantics.db.ExternalValueSupport;
import org.simantics.db.ReadGraph;
return getValue(r, binding);
}
} else if(types.contains(L0.ExternalValue)) {
- try {
- return (T)ReflectionUtils.getValue(getURI(r)).getValue();
- } catch(ValueNotFoundException e) {
- throw new DatabaseException(e);
- } catch(ClassCastException e) {
- throw new DatabaseException(e);
+ ComputationalValue cv = syncRequest(new PossibleAdapter<ComputationalValue>(r, ComputationalValue.class), TransientCacheAsyncListener.instance());
+ if(cv != null) {
+ return cv.getValue(this, r);
+ } else {
+ // This should not even be possible since L0 defines an adapter for all values
+ try {
+ return (T)ReflectionUtils.getValue(getURI(r)).getValue();
+ } catch(ValueNotFoundException e) {
+ throw new DatabaseException(e);
+ } catch(ClassCastException e) {
+ throw new DatabaseException(e);
+ }
}
}
else {
class="org.simantics.db.layer0.adapter.impl.ModelImportAdvisorFactory">
</resource>
</target>
-
+
+ <target interface="org.simantics.db.ComputationalValue">
+ <!-- TODO: should be ExternalValue but handle all values to minimize regressions for the time being -->
+ <type uri="http://www.simantics.org/Layer0-0.0/Value"
+ class="org.simantics.db.layer0.adapter.ReflectionComputationalValue">
+ </type>
+ <resource
+ uri="http://www.simantics.org/Layer0-0.0/Functions/sclValue"
+ class="org.simantics.db.layer0.adapter.SCLComputationalValue">
+ </resource>
+ </target>
+
</adapters>
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2018 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:
+ * Semantum Oy - initial API and implementation
+ *******************************************************************************/
+package org.simantics.db.layer0.adapter;
+
+import org.simantics.db.ConverterComputationalValue;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.exception.RuntimeDatabaseException;
+import org.simantics.db.layer0.variable.Variable;
+import org.simantics.scl.runtime.SCLContext;
+import org.simantics.scl.runtime.function.Function1;
+import org.simantics.scl.runtime.function.FunctionImpl3;
+
+/**
+ * @author Antti Villberg
+ * @since 1.36.0
+ */
+public abstract class ContextualRelatedValue implements ConverterComputationalValue {
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public <T> T getValue(ReadGraph graph, Resource resource) throws DatabaseException {
+ return (T) new FunctionImpl3<ReadGraph, Resource, Object, Object>() {
+ @Override
+ public Object apply(ReadGraph graph, Resource converter, Object context) {
+ SCLContext sclContext = SCLContext.getCurrent();
+ Object oldGraph = sclContext.get("graph");
+ try {
+ if (context instanceof Variable) {
+ Variable variable = (Variable)context;
+ try {
+ Function1<Object,Object> fn = getFunction(graph, variable.getParent(graph).getRepresents(graph), variable.getRepresents(graph), variable.getPredicateResource(graph));
+ sclContext.put("graph", graph);
+ return fn.apply(variable);
+ } catch (DatabaseException e) {
+ throw new RuntimeDatabaseException(e);
+ }
+ } if (context instanceof Resource) {
+ Resource resource = (Resource)context;
+ try {
+ // Here converter is the object and context is the subject
+ Function1<Object,Object> fn = getFunction(graph, resource, converter, null);
+ return fn.apply(resource);
+ } catch (DatabaseException e) {
+ throw new RuntimeDatabaseException(e);
+ }
+ } else {
+ throw new IllegalStateException("Unknown context " + context);
+ }
+ } finally {
+ sclContext.put("graph", oldGraph);
+ }
+ }
+ };
+ }
+
+}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2018 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:
+ * Semantum Oy - initial API and implementation
+ *******************************************************************************/
+package org.simantics.db.layer0.adapter;
+
+import org.simantics.db.ComputationalValue;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.scl.reflection.ReflectionUtils;
+import org.simantics.scl.reflection.ValueNotFoundException;
+
+/**
+ * @author Antti Villberg
+ * @since 1.36.0
+ */
+public class ReflectionComputationalValue implements ComputationalValue {
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public <T> T getValue(ReadGraph graph, Resource resource) throws DatabaseException {
+ try {
+ return (T)ReflectionUtils.getValue(graph.getURI(resource)).getValue();
+ } catch(ValueNotFoundException e) {
+ throw new DatabaseException(e);
+ } catch(ClassCastException e) {
+ throw new DatabaseException(e);
+ }
+ }
+
+}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2018 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:
+ * Semantum Oy - initial API and implementation
+ *******************************************************************************/
+package org.simantics.db.layer0.adapter;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.scl.CompileResourceValueRequest;
+import org.simantics.db.layer0.scl.CompileValueRequest;
+import org.simantics.scl.runtime.function.Function1;
+
+/**
+ * @author Antti Villberg
+ * @since 1.36.0
+ */
+public class SCLComputationalValue extends ContextualRelatedValue {
+
+ @Override
+ public Function1<Object,Object> getFunction(ReadGraph graph, Resource s, Resource o, Resource p) throws DatabaseException {
+ if (s != null && p != null && o != null) {
+ return CompileValueRequest.compile(graph, s, o, p);
+ } else if (o != null) {
+ return CompileResourceValueRequest.compile(graph, o);
+ } else {
+ throw new DatabaseException("Could not compile SCL expression: s=" + s + " p=" + p + " o=" + o);
+ }
+ }
+
+}
import org.simantics.databoard.Bindings;
import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
import org.simantics.db.exception.DatabaseException;
import org.simantics.db.exception.RuntimeDatabaseException;
import org.simantics.db.request.Read;
import org.simantics.scl.runtime.SCLContext;
import org.simantics.scl.runtime.function.Function1;
import org.simantics.utils.datastructures.Pair;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import gnu.trove.map.hash.THashMap;
public abstract class AbstractExpressionCompilationRequest<CompilationContext extends AbstractExpressionCompilationContext,EvaluationContext>
implements Read<Function1<EvaluationContext,Object>> {
+ private static final Logger LOGGER = LoggerFactory.getLogger(AbstractExpressionCompilationRequest.class);
+
protected static final Type RESOURCE = Types.con("Simantics/DB", "Resource");
protected static final Type VARIABLE = Types.con("Simantics/Variables", "Variable");
protected static Name PROPERTY_VALUE = Name.create("Simantics/Variables", "propertyValue");
return false;
}
+ @SuppressWarnings("unchecked")
private Function1<EvaluationContext, Object> eval(ExpressionEvaluator evaluator, ReadGraph graph) throws DatabaseException {
Object oldGraph = SCLContext.getCurrent().put("graph", graph);
try {
return (Function1<EvaluationContext,Object>)evaluator.eval();
} catch(RuntimeDatabaseException e) {
- e.printStackTrace();
+ LOGGER.error("Failed to evaluate SCL expression", e);
if(e.getCause() instanceof DatabaseException)
throw (DatabaseException)e.getCause();
else
throw new SCLDatabaseException(b.toString()+b2.toString(), b2.toString(), e.getErrors());
} catch(Throwable e) {
// Should not happen!
- e.printStackTrace();
+ LOGGER.error("This error should never happen", e);
throw new RuntimeException(e);
} finally {
SCLContext.getCurrent().put("graph", oldGraph);
return concreteEffects;
} catch(MatchException e) {
// Should not happen!
- e.printStackTrace();
+ LOGGER.error("Failed to get expression effects", e);
throw new RuntimeException(e);
}
}
- @SuppressWarnings("unchecked")
@Override
public Function1<EvaluationContext,Object> perform(final ReadGraph graph) throws DatabaseException {
CompilationContext context = getCompilationContext(graph);
else
return base;
}
-
- protected static String resolveExpectedValueType(ReadGraph graph, org.simantics.db.layer0.variable.Variable context) throws DatabaseException {
+
+ protected static String resolveExpectedValueType(ReadGraph graph, Resource predicate) throws DatabaseException {
Layer0 L0 = Layer0.getInstance(graph);
- String valueType = graph.getPossibleRelatedValue(context.getPredicateResource(graph), L0.RequiresValueType, Bindings.STRING);
- return valueType;
+ return graph.getPossibleRelatedValue(predicate, L0.RequiresValueType, Bindings.STRING);
}
+
}
*
* @author Antti Villberg
*/
-public class CompileResourceValueRequest extends AbstractExpressionCompilationRequest<CompilationContext, Resource> {
+public class CompileResourceValueRequest extends AbstractExpressionCompilationRequest<CompilationContext, Object> {
public static class CompilationContext extends AbstractExpressionCompilationContext {
public CompilationContext(RuntimeEnvironment runtimeEnvironment) {
SCLContext sclContext = SCLContext.getCurrent();
Object oldGraph = sclContext.get("graph");
try {
- Function1<Resource,Object> exp = graph.syncRequest(new CompileResourceValueRequest(literal),
- TransientCacheListener.<Function1<Resource,Object>>instance());
+ Function1<Object,Object> exp = graph.syncRequest(new CompileResourceValueRequest(literal),
+ TransientCacheListener.instance());
sclContext.put("graph", graph);
return exp.apply(literal);
} catch (DatabaseException e) {
}
}
+ public static Function1<Object,Object> compile(ReadGraph graph, Resource literal) throws DatabaseException {
+ return graph.syncRequest(new CompileResourceValueRequest(literal), TransientCacheListener.instance());
+ }
+
@Override
protected String getExpressionText(ReadGraph graph)
throws DatabaseException {
*
* @author Tuukka Lehtonen
*/
-public class CompileValueRequest extends AbstractExpressionCompilationRequest<CompilationContext, Variable> {
+public class CompileValueRequest extends AbstractExpressionCompilationRequest<CompilationContext, Object> {
public static class CompilationContext extends AbstractExpressionCompilationContext {
public CompilationContext(RuntimeEnvironment runtimeEnvironment) {
SCLContext sclContext = SCLContext.getCurrent();
Object oldGraph = sclContext.get("graph");
try {
- Function1<Variable,Object> exp = graph.syncRequest(new CompileValueRequest(graph, context),
- TransientCacheListener.<Function1<Variable,Object>>instance());
+ Function1<Object,Object> exp = graph.syncRequest(new CompileValueRequest(graph, context),
+ TransientCacheListener.instance());
sclContext.put("graph", graph);
return exp.apply(context);
} catch (DatabaseException e) {
}
}
+ public static Function1<Object,Object> compile(ReadGraph graph, Resource component, Resource literal, Resource predicate) throws DatabaseException {
+ SCLContext sclContext = SCLContext.getCurrent();
+ Object oldGraph = sclContext.get("graph");
+ try {
+ Function1<Object,Object> exp = graph.syncRequest(new CompileValueRequest(component, literal, predicate),
+ TransientCacheListener.instance());
+ sclContext.put("graph", graph);
+ return exp;
+ } catch (DatabaseException e) {
+ throw (DatabaseException)e;
+ } catch (Throwable t) {
+ throw new DatabaseException(t);
+ } finally {
+ sclContext.put("graph", oldGraph);
+ }
+ }
+
@Override
protected String getExpressionText(ReadGraph graph)
throws DatabaseException {
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2018 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:
+ * Semantum Oy - initial API and implementation
+ *******************************************************************************/
+package org.simantics.db;
+
+import org.simantics.db.exception.DatabaseException;
+
+/**
+ * @author Antti Villberg
+ * @since 1.36.0
+ */
+public interface ComputationalValue {
+
+ public <T> T getValue(ReadGraph graph, Resource resource) throws DatabaseException;
+
+}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2018 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:
+ * Semantum Oy - initial API and implementation
+ *******************************************************************************/
+package org.simantics.db;
+
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.scl.runtime.function.Function1;
+
+/**
+ * @author Antti Villberg
+ * @since 1.36.0
+ */
+public interface ConverterComputationalValue extends ComputationalValue {
+
+ /**
+ * This computes the expression function that shall be called with given context
+ * as defined in
+ * {@link ReadGraph#getRelatedValue2(Resource, Resource, Object, org.simantics.databoard.binding.Binding)}.
+ *
+ * <p>
+ * Context can be Resource (literal) or Variable. With Resource context this
+ * gets called with <code>(null, null, literal resource)</code>. With Variable
+ * property context this gets called with
+ * <code>(represents of parent, represents, predicate resource)</code>.
+ */
+ Function1<Object,Object> getFunction(ReadGraph graph, Resource s, Resource o, Resource p) throws DatabaseException;
+
+}
<target interface="org.simantics.db.layer0.variable.VariableBuilder">
<type uri="http://www.simantics.org/Modeling-1.2/SCLCommandSession" class="org.simantics.document.server.state.StateVariableBuilder" />
</target>
+ <target interface="org.simantics.db.ComputationalValue">
+ <resource uri="http://www.simantics.org/Documentation-0.0/Functions/sclValue"
+ class="org.simantics.document.server.SCLComputationalValue">
+ </resource>
+ <resource uri="http://www.simantics.org/Documentation-0.0/Functions/sclHandlerValue"
+ class="org.simantics.document.server.HandlerSCLComputationalValue">
+ </resource>
+ </target>
</adapters>
\ No newline at end of file
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2018 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:
+ * Semantum Oy - initial API and implementation
+ *******************************************************************************/
+package org.simantics.document.server;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.adapter.ContextualRelatedValue;
+import org.simantics.document.server.request.ServerSCLHandlerValueRequest;
+import org.simantics.scl.runtime.function.Function1;
+
+/**
+ * @author Antti Villberg
+ * @since 1.36.0
+ */
+public class HandlerSCLComputationalValue extends ContextualRelatedValue {
+
+ @Override
+ public Function1<Object,Object> getFunction(ReadGraph graph, Resource s, Resource o, Resource p) throws DatabaseException {
+ return ServerSCLHandlerValueRequest.compile(graph, s, o, p);
+ }
+
+}
\ No newline at end of file
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2018 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:
+ * Semantum Oy - initial API and implementation
+ *******************************************************************************/
+package org.simantics.document.server;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.adapter.ContextualRelatedValue;
+import org.simantics.document.server.request.ServerSCLValueRequest;
+import org.simantics.scl.runtime.function.Function1;
+
+/**
+ * @author Antti Villberg
+ * @since 1.36.0
+ */
+public class SCLComputationalValue extends ContextualRelatedValue {
+
+ @Override
+ public Function1<Object,Object> getFunction(ReadGraph graph, Resource s, Resource o, Resource p) throws DatabaseException {
+ return ServerSCLValueRequest.compile(graph, s, o, p);
+ }
+
+}
\ No newline at end of file
import org.simantics.db.Resource;
import org.simantics.db.common.procedure.adapter.TransientCacheListener;
import org.simantics.db.common.request.IndexRoot;
+import org.simantics.db.common.request.PossibleTypedParent;
+import org.simantics.db.common.request.UnaryRead;
import org.simantics.db.exception.DatabaseException;
-import org.simantics.db.layer0.request.VariableRead;
import org.simantics.db.layer0.scl.AbstractExpressionCompilationContext;
import org.simantics.db.layer0.scl.AbstractExpressionCompilationRequest;
import org.simantics.db.layer0.util.RuntimeEnvironmentRequest2;
import org.simantics.db.layer0.variable.Variable;
+import org.simantics.document.base.ontology.DocumentationResource;
import org.simantics.document.server.request.ServerSCLHandlerValueRequest.CompilationContext;
import org.simantics.layer0.Layer0;
import org.simantics.scl.compiler.elaboration.expressions.EApply;
import org.simantics.structural2.scl.ReadComponentTypeInterfaceRequest;
import org.simantics.utils.datastructures.Pair;
-public class ServerSCLHandlerValueRequest extends AbstractExpressionCompilationRequest<CompilationContext, Variable> {
+public class ServerSCLHandlerValueRequest extends AbstractExpressionCompilationRequest<CompilationContext, Object> {
- private final Variable context;
private final Pair<Resource,Resource> componentTypeAndRoot;
private final Resource literal;
protected String possibleExpectedValueType;
}
}
- private ServerSCLHandlerValueRequest(Variable context, Pair<Resource,Resource> componentTypeAndRoot, Resource literal, String possibleExpectedValueType) {
+ private ServerSCLHandlerValueRequest(Pair<Resource,Resource> componentTypeAndRoot, Resource literal, String possibleExpectedValueType) {
assert(literal != null);
- this.context = context;
this.literal = literal;
this.componentTypeAndRoot = componentTypeAndRoot;
this.possibleExpectedValueType = possibleExpectedValueType;
}
public ServerSCLHandlerValueRequest(ReadGraph graph, Variable context) throws DatabaseException {
- this(context, getComponentTypeAndRoot(graph, context), context.getRepresents(graph), resolveExpectedValueType(graph, context));
+ this(getComponentTypeAndRoot(graph, context), context.getRepresents(graph), resolveExpectedValueType(graph, context.getPredicateResource(graph)));
+ }
+
+ public ServerSCLHandlerValueRequest(ReadGraph graph, Resource s, Resource o, Resource p) throws DatabaseException {
+ this(getComponentTypeAndRoot(graph, s), o, resolveExpectedValueType(graph, p));
}
private static Pair<Resource,Resource> getComponentTypeAndRoot(ReadGraph graph, Variable property) throws DatabaseException {
return Pair.make(parent.getType(graph), root);
}
+ private static Pair<Resource,Resource> getComponentTypeAndRoot(ReadGraph graph, Resource component) throws DatabaseException {
+ if(component != null) {
+ Resource type = graph.syncRequest(new FindPossibleComponentTypeRequest(component));
+ if(type != null) {
+ Resource root = graph.syncRequest(new IndexRoot(type));
+ return Pair.make(type, root);
+ } else {
+ Resource doc = graph.syncRequest(new PossibleTypedParent(component, DocumentationResource.getInstance(graph).Document));
+ Resource componentType = graph.getSingleType(doc);
+ Resource root = graph.syncRequest(new IndexRoot(doc));
+ return Pair.make(componentType, root);
+ }
+ }
+ throw new IllegalStateException();
+ }
public static List<TCon> getEffects(ReadGraph graph, Variable context) throws DatabaseException {
try {
SCLContext sclContext = SCLContext.getCurrent();
Object oldGraph = sclContext.get("graph");
try {
- Function1<Variable,Object> exp = graph.syncRequest(new ServerSCLHandlerValueRequest(graph, context),
- TransientCacheListener.<Function1<Variable,Object>>instance());
+ Function1<Object,Object> exp = graph.syncRequest(new ServerSCLHandlerValueRequest(graph, context),
+ TransientCacheListener.instance());
sclContext.put("graph", graph);
return exp.apply(context);
} catch (DatabaseException e) {
}
}
+ public static Function1<Object, Object> compile(ReadGraph graph, Variable context) throws DatabaseException {
+ return graph.syncRequest(new ServerSCLHandlerValueRequest(graph, context), TransientCacheListener.instance());
+ }
+
+ public static Function1<Object, Object> compile(ReadGraph graph, Resource s, Resource o, Resource p) throws DatabaseException {
+ return graph.syncRequest(new ServerSCLHandlerValueRequest(graph, s, o, p), TransientCacheListener.<Function1<Object,Object>>instance());
+ }
+
@Override
protected String getExpressionText(ReadGraph graph)
throws DatabaseException {
@Override
protected CompilationContext getCompilationContext(ReadGraph graph) throws DatabaseException {
-
- return graph.syncRequest(new VariableRead<CompilationContext>(context) {
-
+ return graph.syncRequest(new UnaryRead<Pair<Resource,Resource>,CompilationContext>(componentTypeAndRoot) {
@Override
public CompilationContext perform(ReadGraph graph) throws DatabaseException {
-
- Pair<Resource,Resource> parameter = getComponentTypeAndRoot(graph, variable);
RuntimeEnvironment runtimeEnvironment = graph.syncRequest(getRuntimeEnvironmentRequest(parameter.first, parameter.second));
-
Map<String, ComponentTypeProperty> propertyMap =
graph.syncRequest(new ReadComponentTypeInterfaceRequest(parameter.first, runtimeEnvironment.getEnvironment()),
TransientCacheListener.<Map<String, ComponentTypeProperty>>instance());
-
-// Map<String, ComponentTypeProperty> result = new HashMap<String,ComponentTypeProperty>(propertyMap);
-// for(DataDefinition dd : Functions.dataDefinitions(graph, variable)) {
-// result.put(dd.target, null);
-// }
-
return new CompilationContext(runtimeEnvironment, propertyMap);
-
}
-
});
-
}
@Override
@Override
public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((context == null) ? 0 : context.hashCode());
- return result;
+ return 31*(31*getClass().hashCode() + literal.hashCode()) + componentTypeAndRoot.hashCode();
}
@Override
if (getClass() != obj.getClass())
return false;
ServerSCLHandlerValueRequest other = (ServerSCLHandlerValueRequest) obj;
- if (context == null) {
- if (other.context != null)
- return false;
- } else if (!context.equals(other.context))
- return false;
- return true;
+ return literal.equals(other.literal) && componentTypeAndRoot.equals(other.componentTypeAndRoot);
}
-// @Override
-// public int hashCode() {
-// return 31*(31*getClass().hashCode() + literal.hashCode()) + componentTypeAndRoot.hashCode();
-// }
-//
-// @Override
-// public boolean equals(Object obj) {
-// if(this == obj)
-// return true;
-// if(obj == null || obj.getClass() != getClass())
-// return false;
-// ServerSCLHandlerValueRequest other = (ServerSCLHandlerValueRequest)obj;
-// return literal.equals(other.literal) && componentTypeAndRoot.equals(other.componentTypeAndRoot);
-// }
-
}
import org.simantics.db.Resource;
import org.simantics.db.common.procedure.adapter.TransientCacheListener;
import org.simantics.db.common.request.IndexRoot;
+import org.simantics.db.common.request.PossibleTypedParent;
import org.simantics.db.common.request.UnaryRead;
import org.simantics.db.exception.DatabaseException;
import org.simantics.db.layer0.scl.AbstractExpressionCompilationContext;
import org.simantics.db.layer0.scl.AbstractExpressionCompilationRequest;
import org.simantics.db.layer0.util.RuntimeEnvironmentRequest2;
import org.simantics.db.layer0.variable.Variable;
+import org.simantics.document.base.ontology.DocumentationResource;
import org.simantics.document.server.request.ServerSCLValueRequest.CompilationContext;
import org.simantics.layer0.Layer0;
import org.simantics.scl.compiler.common.names.Name;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class ServerSCLValueRequest extends AbstractExpressionCompilationRequest<CompilationContext, Variable> {
+public class ServerSCLValueRequest extends AbstractExpressionCompilationRequest<CompilationContext, Object> {
private final Pair<Resource,Resource> componentTypeAndRoot;
private final Resource literal;
}
public ServerSCLValueRequest(ReadGraph graph, Variable context) throws DatabaseException {
- this(getComponentTypeAndRoot(graph, context), context.getRepresents(graph), resolveExpectedValueType(graph, context));
+ this(getComponentTypeAndRoot(graph, context), context.getRepresents(graph), resolveExpectedValueType(graph, context.getPredicateResource(graph)));
+ }
+
+ public ServerSCLValueRequest(ReadGraph graph, Resource s, Resource o, Resource p) throws DatabaseException {
+ this(getComponentTypeAndRoot(graph, s), o, resolveExpectedValueType(graph, p));
}
private static Pair<Resource,Resource> getComponentTypeAndRoot(ReadGraph graph, Variable property) throws DatabaseException {
return Pair.make(parent.getType(graph), root);
}
+ private static Pair<Resource,Resource> getComponentTypeAndRoot(ReadGraph graph, Resource component) throws DatabaseException {
+ if(component != null) {
+ Resource type = graph.syncRequest(new FindPossibleComponentTypeRequest(component));
+ if(type != null) {
+ Resource root = graph.syncRequest(new IndexRoot(type));
+ // System.err.println("getComponentTypeAndRoot3 " + graph.getPossibleURI(component) + " => " + graph.getPossibleURI(type) + " " + graph.getPossibleURI(root));
+ return Pair.make(type, root);
+ } else {
+ Resource doc = graph.syncRequest(new PossibleTypedParent(component, DocumentationResource.getInstance(graph).Document));
+ if(doc != null) {
+ Resource componentType = graph.getSingleType(doc);
+ Resource root = graph.syncRequest(new IndexRoot(doc));
+ return Pair.make(componentType, root);
+ } else {
+ System.err.println("component = " + component);
+ Resource root = graph.syncRequest(new IndexRoot(component));
+// Resource componentType = graph.getSingleType(doc);
+ return Pair.make(null, root);
+ }
+ }
+ }
+ throw new IllegalStateException();
+ }
+
public static Object compileAndEvaluate(ReadGraph graph, Variable context) throws DatabaseException {
SCLContext sclContext = SCLContext.getCurrent();
Object oldGraph = sclContext.get("graph");
try {
- Function1<Variable,Object> exp = compile(graph, context);
+ Function1<Object,Object> exp = compile(graph, context);
sclContext.put("graph", graph);
return exp.apply(context);
} catch (DatabaseException e) {
sclContext.put("graph", oldGraph);
}
}
-
- public static Function1<Variable, Object> compile(ReadGraph graph, Variable context) throws DatabaseException {
- return graph.syncRequest(new ServerSCLValueRequest(graph, context), TransientCacheListener.<Function1<Variable,Object>>instance());
+
+ public static Function1<Object, Object> compile(ReadGraph graph, Variable context) throws DatabaseException {
+ return graph.syncRequest(new ServerSCLValueRequest(graph, context), TransientCacheListener.instance());
+ }
+
+ public static Function1<Object, Object> compile(ReadGraph graph, Resource s, Resource o, Resource p) throws DatabaseException {
+ return graph.syncRequest(new ServerSCLValueRequest(graph, s, o, p), TransientCacheListener.instance());
}
@Override
return literal.equals(other.literal) && componentTypeAndRoot.equals(other.componentTypeAndRoot);
}
- public static Function1<Variable, Object> validate(ReadGraph graph, Variable context) throws DatabaseException {
- return graph.syncRequest(new ServerSCLValueValidationRequest(graph, context), TransientCacheListener.<Function1<Variable,Object>>instance());
+ public static Function1<Object, Object> validate(ReadGraph graph, Variable context) throws DatabaseException {
+ return graph.syncRequest(new ServerSCLValueValidationRequest(graph, context), TransientCacheListener.instance());
}
public static class ServerSCLValueValidationRequest extends ServerSCLValueRequest {
L0.Functions.listResources : L0.ExternalValue
L0.Functions.resourceAsValue : L0.ExternalValue
L0.Functions.functionApplication : L0.ExternalValue
+
+// This was replaced by L0.Functions.sclValue to make things more uniform
L0.Functions.computeExpression : L0.ExternalValue
+ @L0.tag L0.Deprecated
+
+L0.Functions.sclValue : L0.ExternalValue
L0.Functions.composedPropertyValue : L0.ExternalValue
L0.Functions.standardValueAccessor : L0.ExternalValue
@L0.tag L0.Abstract
>-- L0.SCLValue.expression --> L0.String <R L0.HasProperty : L0.TotalFunction
>-- L0.SCLValue.environment --> L0.SCLValue.Environment <R L0.IsRelatedTo : L0.TotalFunction
- @L0.assert L0.ConvertsToValueWith L0.Functions.computeExpression
+ @L0.assert L0.ConvertsToValueWith L0.Functions.sclValue
L0.SCLValueType <T L0.Entity
>-- L0.SCLValueType.validator ==> "Variable -> <ReadGraph> String" <R L0.HasProperty
</resource>
</target>
+ <target interface="org.simantics.db.ComputationalValue">
+ <resource uri="http://www.simantics.org/Modeling-0.0/Functions/sclValue"
+ class="org.simantics.modeling.SCLComputationalValue">
+ </resource>
+ </target>
+
</adapters>
\ No newline at end of file
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2018 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:
+ * Semantum Oy - initial API and implementation
+ *******************************************************************************/
+package org.simantics.modeling;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.adapter.ContextualRelatedValue;
+import org.simantics.scl.runtime.function.Function1;
+import org.simantics.structural2.scl.CompileStructuralValueRequest;
+
+/**
+ * @author Antti Villberg
+ * @since 1.36.0
+ */
+public class SCLComputationalValue extends ContextualRelatedValue {
+
+ @Override
+ public Function1<Object,Object> getFunction(ReadGraph graph, Resource s, Resource o, Resource p) throws DatabaseException {
+ return CompileStructuralValueRequest.compile(graph, s, o, p);
+ }
+
+}
\ No newline at end of file
SCLContext sclContext = SCLContext.getCurrent();
Object oldGraph = sclContext.get("graph");
try {
- Function1<Variable,Object> exp = graph.syncRequest(new CompileSCLQueryRequest(graph, context),
- TransientCacheListener.<Function1<Variable,Object>>instance());
+ Function1<Object,Object> exp = graph.syncRequest(new CompileSCLQueryRequest(graph, context),
+ TransientCacheListener.<Function1<Object,Object>>instance());
sclContext.put("graph", graph);
return exp.apply(context);
} catch (DatabaseException e) {
SCLContext sclContext = SCLContext.getCurrent();
Object oldGraph = sclContext.get("graph");
try {
- Function1<Variable,Object> exp = graph.syncRequest(new CompileSCLValueRequest(graph, context),
- TransientCacheListener.<Function1<Variable,Object>>instance());
+ Function1<Object,Object> exp = graph.syncRequest(new CompileSCLValueRequest(graph, context),
+ TransientCacheListener.instance());
sclContext.put("graph", graph);
return exp.apply(context);
} catch (DatabaseException e) {
SCLContext sclContext = SCLContext.getCurrent();
Object oldGraph = sclContext.get("graph");
try {
- Function1<Variable,Object> exp = graph.syncRequest(new CompileSCLValueRequest(graph, context),
- TransientCacheListener.<Function1<Variable,Object>>instance());
+ Function1<Object,Object> exp = graph.syncRequest(new CompileSCLValueRequest(graph, context),
+ TransientCacheListener.instance());
sclContext.put("graph", graph);
return exp.apply(context);
} catch (DatabaseException e) {
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2018 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:
+ * Semantum Oy - initial API and implementation
+ *******************************************************************************/
+package org.simantics.structural2;
+
+import java.util.Collection;
+import java.util.Set;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.variable.Variable;
+import org.simantics.structural2.variables.Connection;
+import org.simantics.structural2.variables.Connection2;
+import org.simantics.structural2.variables.ConnectionBrowser;
+import org.simantics.structural2.variables.VariableConnectionPointDescriptor;
+
+import gnu.trove.set.hash.THashSet;
+
+/**
+ * @author Antti Villberg
+ * @since 1.36.0
+ */
+public class ConnectionImpl implements Connection {
+
+ private final Variable component;
+ private final Resource predicate;
+
+ public ConnectionImpl(Variable component, Resource predicate) {
+ this.component = component;
+ this.predicate = predicate;
+ }
+
+ @Override
+ public Collection<Variable> getConnectionPoints(ReadGraph graph, Resource relationType) throws DatabaseException {
+ Set<Variable> result = new THashSet<Variable>();
+ for(VariableConnectionPointDescriptor desc : ConnectionBrowser.flatten(graph, component, predicate, relationType)) {
+ result.add(desc.getVariable(graph));
+ }
+ return result;
+ }
+
+ @Override
+ public Collection<String> getConnectionPointURIs(ReadGraph graph, Resource relationType) throws DatabaseException {
+ Set<String> result = new THashSet<String>();
+ for(VariableConnectionPointDescriptor desc : ConnectionBrowser.flatten(graph, component, predicate, relationType)) {
+ result.add(desc.getURI(graph));
+ }
+ return result;
+ }
+
+ @Override
+ public Collection<VariableConnectionPointDescriptor> getConnectionPointDescriptors(ReadGraph graph,
+ Resource relationType) throws DatabaseException {
+ return ConnectionBrowser.flatten(graph, component, predicate, relationType);
+ }
+
+ @Override
+ public Connection2 getConnection2() {
+ return new ConnectionImpl2(predicate);
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((component == null) ? 0 : component.hashCode());
+ result = prime * result + ((predicate == null) ? 0 : predicate.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ ConnectionImpl other = (ConnectionImpl) obj;
+ if (component == null) {
+ if (other.component != null)
+ return false;
+ } else if (!component.equals(other.component))
+ return false;
+ if (predicate == null) {
+ if (other.predicate != null)
+ return false;
+ } else if (!predicate.equals(other.predicate))
+ return false;
+ return true;
+ }
+
+}
\ No newline at end of file
/*******************************************************************************
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * Copyright (c) 2007, 2018 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
import org.simantics.db.exception.DatabaseException;
import org.simantics.db.layer0.variable.Variable;
import org.simantics.structural2.variables.Connection;
+import org.simantics.structural2.variables.Connection2;
import org.simantics.structural2.variables.ConnectionBrowser;
import org.simantics.structural2.variables.VariableConnectionPointDescriptor;
import gnu.trove.set.hash.THashSet;
-public class ConnectionImpl2 implements Connection {
+public class ConnectionImpl2 implements Connection, Connection2 {
- private final Variable component;
private final Resource predicate;
-
- public ConnectionImpl2(Variable component, Resource predicate) {
- this.component = component;
+
+ public ConnectionImpl2(Resource predicate) {
this.predicate = predicate;
}
-
+
@Override
public int hashCode() {
final int prime = 31;
}
@Override
- public Collection<Variable> getConnectionPoints(ReadGraph graph, Resource relationType) throws DatabaseException {
- Set<Variable> result = new THashSet<Variable>();
+ public Collection<String> getConnectionPointURIs(ReadGraph graph, Variable component, Resource relationType)
+ throws DatabaseException {
+ Set<String> result = new THashSet<String>();
for(VariableConnectionPointDescriptor desc : ConnectionBrowser.flatten(graph, component, predicate, relationType)) {
- result.add(desc.getVariable(graph));
+ result.add(desc.getURI(graph));
}
return result;
}
-
+
@Override
- public Collection<String> getConnectionPointURIs(ReadGraph graph, Resource relationType) throws DatabaseException {
- Set<String> result = new THashSet<String>();
+ public Collection<Variable> getConnectionPoints(ReadGraph graph, Variable component, Resource relationType)
+ throws DatabaseException {
+ Set<Variable> result = new THashSet<Variable>();
for(VariableConnectionPointDescriptor desc : ConnectionBrowser.flatten(graph, component, predicate, relationType)) {
- result.add(desc.getURI(graph));
+ result.add(desc.getVariable(graph));
}
return result;
}
@Override
- public Collection<VariableConnectionPointDescriptor> getConnectionPointDescriptors(ReadGraph graph, Resource relationType) throws DatabaseException {
+ public Collection<VariableConnectionPointDescriptor> getConnectionPointDescriptors(ReadGraph graph,
+ Variable component, Resource relationType) throws DatabaseException {
return ConnectionBrowser.flatten(graph, component, predicate, relationType);
}
+ @Override
+ public Collection<String> getConnectionPointURIs(ReadGraph graph, Resource relationType) throws DatabaseException {
+ throw new IllegalStateException();
+ }
+
+ @Override
+ public Collection<Variable> getConnectionPoints(ReadGraph graph, Resource relationType) throws DatabaseException {
+ throw new IllegalStateException();
+ }
+
+ @Override
+ public Collection<VariableConnectionPointDescriptor> getConnectionPointDescriptors(ReadGraph graph,
+ Resource relationType) throws DatabaseException {
+ throw new IllegalStateException();
+ }
+
+ @Override
+ public Connection2 getConnection2() {
+ return this;
+ }
+
}
\ No newline at end of file
@Override
public Object getValue(ReadGraph graph, Variable context) throws DatabaseException {
StandardGraphPropertyVariable variable = (StandardGraphPropertyVariable)context;
- return new ConnectionImpl2(context.getParent(graph), variable.property.predicate);
+ return new ConnectionImpl(context.getParent(graph), variable.property.predicate);
}
@Override
SCLContext sclContext = SCLContext.getCurrent();
Object oldGraph = sclContext.get("graph");
try {
- Function1<Variable,Object> exp = graph.syncRequest(new CompileStructuralValueRequest(graph, context) {
+ Function1<Object,Object> exp = graph.syncRequest(new CompileStructuralValueRequest(graph, context) {
protected String getExpressionText(ReadGraph graph) throws DatabaseException {
return expression;
}
},
- TransientCacheListener.<Function1<Variable,Object>>instance());
+ TransientCacheListener.instance());
sclContext.put("graph", graph);
return exp.apply(context);
} catch (DatabaseException e) {
import org.simantics.db.layer0.scl.AbstractExpressionCompilationRequest;
import org.simantics.db.layer0.util.RuntimeEnvironmentRequest;
import org.simantics.db.layer0.util.RuntimeEnvironmentRequest2;
-import org.simantics.db.layer0.variable.Variable;
import org.simantics.layer0.Layer0;
import org.simantics.scl.compiler.elaboration.expressions.EApply;
import org.simantics.scl.compiler.elaboration.expressions.EConstant;
*
* @author Antti Villberg
*/
-abstract public class AbstractCompileStructuralValueRequest extends AbstractExpressionCompilationRequest<CompilationContext, Variable> {
+public abstract class AbstractCompileStructuralValueRequest extends AbstractExpressionCompilationRequest<CompilationContext, Object> {
protected final Resource relation;
SCLContext sclContext = SCLContext.getCurrent();
Object oldGraph = sclContext.get("graph");
try {
- Function1<Variable,Object> exp = graph.syncRequest(new CompileProceduralExpressionValueRequest(graph, expression, context),
- TransientCacheListener.<Function1<Variable,Object>>instance());
+ Function1<Object,Object> exp = graph.syncRequest(new CompileProceduralExpressionValueRequest(graph, expression, context),
+ TransientCacheListener.instance());
sclContext.put("graph", graph);
return exp.apply(context);
} catch (DatabaseException e) {
Object oldGraph = sclContext.get("graph");
CompileStructuralValueRequest request = new CompileStructuralValueRequest(graph, context);
try {
- Function1<Variable,Object> exp = graph.syncRequest(request, TransientCacheListener.<Function1<Variable,Object>>instance());
+ Function1<Object,Object> exp = graph.syncRequest(request, TransientCacheListener.instance());
sclContext.put("graph", graph);
return exp.apply(context);
} catch (Throwable t) {
}
}
+ public static Function1<Object, Object> compile(ReadGraph graph, Resource s, Resource o, Resource p) throws DatabaseException {
+ return graph.syncRequest(new CompileStructuralValueRequest(s, o, p), TransientCacheListener.instance());
+ }
+
@Override
protected String getExpressionText(ReadGraph graph)
throws DatabaseException {
Collection<VariableConnectionPointDescriptor> getConnectionPointDescriptors(ReadGraph graph, Resource relationType) throws DatabaseException;
+ Connection2 getConnection2();
+
}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2018 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:
+ * Semantum Oy - initial API and implementation
+ *******************************************************************************/
+package org.simantics.structural2.variables;
+
+import java.util.Collection;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.variable.Variable;
+
+/**
+ * Improves query result cacheability over {@link Connection}.
+ *
+ * @author Antti Villberg
+ * @since 1.36.0
+ * @see Connection
+ */
+public interface Connection2 {
+
+ /**
+ * Return absolute URIs of the connection points. An optional (may be null) relationType may be used
+ * to filter the returned connection points.
+ */
+ Collection<String> getConnectionPointURIs(ReadGraph graph, Variable component, Resource relationType) throws DatabaseException;
+
+ /**
+ * Return the connection points. An optional (may be null) relationType may be used
+ * to filter the returned connection points.
+ */
+ Collection<Variable> getConnectionPoints(ReadGraph graph, Variable component, Resource relationType) throws DatabaseException;
+
+ Collection<VariableConnectionPointDescriptor> getConnectionPointDescriptors(ReadGraph graph, Variable component, Resource relationType) throws DatabaseException;
+
+}
import org.simantics.db.common.request.BinaryRead;
import org.simantics.db.common.request.ResourceRead;
import org.simantics.db.common.request.TransientUnaryRead;
-import org.simantics.db.common.utils.CommonDBUtils;
import org.simantics.db.common.utils.NameUtils;
import org.simantics.db.common.utils.NearestOwnerFinder;
import org.simantics.db.exception.DatabaseException;
import org.simantics.structural2.queries.ConnectionSet;
import org.simantics.structural2.utils.StructuralUtils;
import org.simantics.structural2.utils.StructuralUtils.StructuralComponentClass;
-import org.simantics.structural2.variables.StandardProceduralChildVariable.FixedConnection;
-import org.simantics.utils.datastructures.Pair;
import gnu.trove.map.hash.THashMap;
import gnu.trove.set.hash.THashSet;
Variable conn = child.getPossibleProperty(graph, cp);
FixedConnection fc = (FixedConnection)conn.getValue(graph);
- Set<VariableConnectionPointDescriptor> result = new THashSet<VariableConnectionPointDescriptor>(1+fc.cps.size());
- result.add(new ComponentConnectionDescriptor(child, cp));// (graph, STR, curConfiguration, "/" + c.name + "#" + conn.getName(graph)));
- for(Pair<String,Resource> cpzz : fc.cps) {
- if(cpzz.first == null) {
- throw new DatabaseException("Lifted connection was not resolved.");
- }
- result.add(new PairConnectionDescriptor(curConfiguration, cpzz));
- }
+ Set<VariableConnectionPointDescriptor> result = new THashSet<VariableConnectionPointDescriptor>(1+fc.size());
+ result.add(new ComponentConnectionDescriptor(child, cp));
+ fc.addConnectionDescriptors(graph, curConfiguration, result);
return result;
} else {
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2018 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:
+ * Semantum Oy - initial API and implementation
+ *******************************************************************************/
+package org.simantics.structural2.variables;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Set;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.variable.Variable;
+import org.simantics.utils.datastructures.Pair;
+import org.slf4j.LoggerFactory;
+
+import gnu.trove.set.hash.THashSet;
+
+/**
+ * @author Antti Villberg
+ * @since 1.36.0
+ */
+public class FixedConnection implements Connection, Connection2 {
+
+ private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(FixedConnection.class);
+
+ /*
+ * This is the parent of the component to be connected
+ */
+ private final Variable procedural;
+
+ private final Collection<Pair<String, Resource>> cps = new ArrayList<Pair<String, Resource>>();
+
+ public FixedConnection(Variable procedural) {
+ this.procedural = procedural;
+ }
+
+ public void addAll(List<Pair<String, Resource>> cps) throws DatabaseException {
+ /*
+ * For interface connections the name is null
+ */
+ for (Pair<String, Resource> cp : cps) {
+ this.cps.add(cp);
+ }
+ }
+
+ public int size() {
+ return cps.size();
+ }
+
+ public void addConnectionDescriptors(ReadGraph graph, Variable curConfiguration,
+ Collection<VariableConnectionPointDescriptor> result) throws DatabaseException {
+ for (Pair<String, Resource> cpzz : cps) {
+ // This is a connection to an interface terminal. It is handled by
+ // ConnectionBrowser in separate logic. We should never have gotten this far
+ if (cpzz.first == null) {
+ String message = "Lifted connection was not resolved. Child = " + procedural.getURI(graph);
+ throw new DatabaseException(message);
+ }
+ result.add(new PairConnectionDescriptor(curConfiguration, cpzz));
+ }
+ }
+
+ @Override
+ public Collection<Variable> getConnectionPoints(ReadGraph graph, Resource relationType) throws DatabaseException {
+ Set<Variable> result = new THashSet<Variable>();
+ for (Pair<String, Resource> cp : cps) {
+ Variable component = cp.first == null ? procedural : procedural.getChild(graph, cp.first);
+ Variable cp2 = component.getPossibleProperty(graph, cp.second);
+ if (cp2 != null)
+ for (VariableConnectionPointDescriptor desc : ConnectionBrowser.flatten(graph, component, cp.second,
+ relationType)) {
+ result.add(desc.getVariable(graph));
+ }
+ else
+ LOGGER.warn("no cp " + cp.first + " for " + component.getURI(graph));
+ }
+ return result;
+ }
+
+ @Override
+ public Collection<String> getConnectionPointURIs(ReadGraph graph, Resource relationType) throws DatabaseException {
+ Set<String> result = new THashSet<String>();
+ for (Pair<String, Resource> cp : cps) {
+ Variable component = cp.first == null ? procedural : procedural.getChild(graph, cp.first);
+ Variable cp2 = component.getPossibleProperty(graph, cp.second);
+ if (cp2 != null)
+ for (VariableConnectionPointDescriptor desc : ConnectionBrowser.flatten(graph, component, cp.second,
+ relationType)) {
+ result.add(desc.getURI(graph));
+ }
+ else
+ LOGGER.warn("no cp " + cp.first + " for " + component.getURI(graph));
+ }
+ return result;
+ }
+
+ @Override
+ public Collection<VariableConnectionPointDescriptor> getConnectionPointDescriptors(ReadGraph graph,
+ Resource relationType) throws DatabaseException {
+ Set<VariableConnectionPointDescriptor> result = new THashSet<VariableConnectionPointDescriptor>();
+ for (Pair<String, Resource> cp : cps) {
+ Variable component = cp.first == null ? procedural : procedural.getChild(graph, cp.first);
+ Variable cp2 = component.getPossibleProperty(graph, cp.second);
+ if (cp2 != null)
+ result.addAll(ConnectionBrowser.flatten(graph, component, cp.second, relationType));
+ else
+ LOGGER.warn("no cp " + cp.first + " for " + component.getURI(graph));
+ }
+ return result;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((cps == null) ? 0 : cps.hashCode());
+ result = prime * result + ((procedural == null) ? 0 : procedural.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ FixedConnection other = (FixedConnection) obj;
+ if (cps == null) {
+ if (other.cps != null)
+ return false;
+ } else if (!cps.equals(other.cps))
+ return false;
+ if (procedural == null) {
+ if (other.procedural != null)
+ return false;
+ } else if (!procedural.equals(other.procedural))
+ return false;
+ return true;
+ }
+
+ @Override
+ public Collection<VariableConnectionPointDescriptor> getConnectionPointDescriptors(ReadGraph graph,
+ Variable component, Resource relationType) throws DatabaseException {
+ Set<VariableConnectionPointDescriptor> result = new THashSet<VariableConnectionPointDescriptor>();
+ for (Pair<String, Resource> cp : cps) {
+ Variable base = cp.first == null ? component.getParent(graph) : component;
+ Variable cp2 = base.getPossibleProperty(graph, cp.second);
+ if (cp2 != null)
+ result.addAll(ConnectionBrowser.flatten(graph, base, cp.second, relationType));
+ else
+ LOGGER.warn("no cp " + cp.first + " for " + base.getURI(graph));
+ }
+ return result;
+ }
+
+ @Override
+ public Collection<Variable> getConnectionPoints(ReadGraph graph, Variable component, Resource relationType)
+ throws DatabaseException {
+ Set<Variable> result = new THashSet<Variable>();
+ for (Pair<String, Resource> cp : cps) {
+ Variable base = cp.first == null ? component.getParent(graph) : component;
+ Variable cp2 = base.getPossibleProperty(graph, cp.second);
+ if (cp2 != null)
+ for (VariableConnectionPointDescriptor desc : ConnectionBrowser.flatten(graph, base, cp.second,
+ relationType)) {
+ result.add(desc.getVariable(graph));
+ }
+ else
+ LOGGER.warn("no cp " + cp.first + " for " + base.getURI(graph));
+ }
+ return result;
+ }
+
+ @Override
+ public Collection<String> getConnectionPointURIs(ReadGraph graph, Variable component, Resource relationType)
+ throws DatabaseException {
+ Set<String> result = new THashSet<String>();
+ for (Pair<String, Resource> cp : cps) {
+ Variable base = cp.first == null ? component.getParent(graph) : component;
+ Variable cp2 = base.getPossibleProperty(graph, cp.second);
+ if (cp2 != null)
+ for (VariableConnectionPointDescriptor desc : ConnectionBrowser.flatten(graph, base, cp.second,
+ relationType)) {
+ result.add(desc.getURI(graph));
+ }
+ else
+ LOGGER.warn("no cp " + cp.first + " for " + base.getURI(graph));
+ }
+ return result;
+ }
+
+ @Override
+ public Connection2 getConnection2() {
+ return this;
+ }
+
+}
\ No newline at end of file
package org.simantics.structural2.variables;
-import gnu.trove.map.hash.THashMap;
-import gnu.trove.set.hash.THashSet;
-
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import org.simantics.db.ReadGraph;
import org.simantics.db.Resource;
import org.simantics.db.Statement;
-import org.simantics.db.common.utils.Logger;
import org.simantics.db.exception.DatabaseException;
import org.simantics.db.exception.NoSingleResultException;
import org.simantics.db.layer0.function.All;
import org.simantics.utils.datastructures.Pair;
import org.slf4j.LoggerFactory;
+import gnu.trove.map.hash.THashMap;
+
public class StandardProceduralChildVariable extends AbstractChildVariable {
- private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(StandardProceduralChildVariable.class);
+ private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(StandardProceduralChildVariable.class);
+
/*
* Extension points
*
final private Map<String, Variable> properties;
final private List<Object> propertyIdentity;
- public static class FixedConnection implements org.simantics.structural2.variables.Connection {
-
- final public Collection<Pair<String,Resource>> cps = new ArrayList<Pair<String,Resource>>();
-
- final private Variable parent;
-
- public FixedConnection(Variable parent) {
- this.parent = parent;
- }
-
- @Override
- public Collection<Variable> getConnectionPoints(ReadGraph graph, Resource relationType) throws DatabaseException {
-
- Set<Variable> result = new THashSet<Variable>();
- for(Pair<String,Resource> cp : cps) {
- Variable component = cp.first == null ? parent : parent.getChild(graph, cp.first);
- Variable cp2 = component.getPossibleProperty(graph, cp.second);
- if(cp2 != null)
- for(VariableConnectionPointDescriptor desc : ConnectionBrowser.flatten(graph, component, cp.second, relationType)) {
- result.add(desc.getVariable(graph));
- }
- else
- LOGGER.warn("no cp " + cp.first + " for " + component.getURI(graph));
- }
- return result;
-
- }
-
- @Override
- public Collection<String> getConnectionPointURIs(ReadGraph graph, Resource relationType) throws DatabaseException {
-
- Set<String> result = new THashSet<String>();
- for(Pair<String,Resource> cp : cps) {
- Variable component = cp.first == null ? parent : parent.getChild(graph, cp.first);
- Variable cp2 = component.getPossibleProperty(graph, cp.second);
- if(cp2 != null)
- for(VariableConnectionPointDescriptor desc : ConnectionBrowser.flatten(graph, component, cp.second, relationType)) {
- result.add(desc.getURI(graph));
- }
- else
- LOGGER.warn("no cp " + cp.first + " for " + component.getURI(graph));
- }
- return result;
-
- }
-
- @Override
- public Collection<VariableConnectionPointDescriptor> getConnectionPointDescriptors(ReadGraph graph, Resource relationType) throws DatabaseException {
-
- Set<VariableConnectionPointDescriptor> result = new THashSet<VariableConnectionPointDescriptor>();
- for(Pair<String,Resource> cp : cps) {
- Variable component = cp.first == null ? parent : parent.getChild(graph, cp.first);
- Variable cp2 = component.getPossibleProperty(graph, cp.second);
- if(cp2 != null)
- result.addAll(ConnectionBrowser.flatten(graph, component, cp.second, relationType));
- else
- LOGGER.warn("no cp " + cp.first + " for " + component.getURI(graph));
- }
- return result;
-
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((cps == null) ? 0 : cps.hashCode());
- result = prime * result
- + ((parent == null) ? 0 : parent.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- FixedConnection other = (FixedConnection) obj;
- if (cps == null) {
- if (other.cps != null)
- return false;
- } else if (!cps.equals(other.cps))
- return false;
- if (parent == null) {
- if (other.parent != null)
- return false;
- } else if (!parent.equals(other.parent))
- return false;
- return true;
- }
-
- }
-
public StandardProceduralChildVariable(ReadGraph graph, Variable parent, VariableNode node, String name, Resource type, List<Property> properties, Collection<Connection> conns) throws DatabaseException {
super(node);
assert name != null;
for(Property p : properties) {
String pn = graph.getRelatedValue(p.relation, L0.HasName, Bindings.STRING);
if(p.value == null) {
- Logger.defaultLogError("StandardProceduralChildVariable " + getURI(graph) + ": null value for property " + pn);
+ LOGGER.error("StandardProceduralChildVariable " + getURI(graph) + ": null value for property " + pn);
} else if (p.value instanceof Expression) {
Expression expression = (Expression)p.value;
this.properties.put(pn, new StructuralProceduralExpressionPropertyVariable(graph, this, p.relation, expression.text) );
fc = new FixedConnection(parent);
map.put(p, fc);
}
- fc.cps.addAll(cps);
+ fc.addAll(cps);
}
}
for(Map.Entry<Resource, FixedConnection> entry : map.entrySet()) {