+/*******************************************************************************
+ * Copyright (c) 2019 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.request;
import java.util.Collection;
public final Resource predicate;
public final String name;
public final boolean isHasProperty;
+ public final boolean isFunctional;
public final Set<String> classifications;
public final VariableBuilder builder;
public final Resource literalRange;
public final Map<String,Pair<Resource, ChildReference>> subliteralPredicates;
public final ValueAccessor valueAccessor;
public final boolean hasEnumerationRange;
- public PropertyInfo(Resource predicate, String name, boolean isHasProperty, Set<String> classifications, VariableBuilder builder, Resource literalRange, Datatype requiredDatatype, String definedUnit, String requiredValueType, Binding defaultBinding, Map<String,Pair<Resource, ChildReference>> subliteralPredicates, ValueAccessor valueAccessor, boolean hasEnumerationRange) {
+ public PropertyInfo(Resource predicate, String name, boolean isFunctional, boolean isHasProperty, Set<String> classifications, VariableBuilder builder, Resource literalRange, Datatype requiredDatatype, String definedUnit, String requiredValueType, Binding defaultBinding, Map<String,Pair<Resource, ChildReference>> subliteralPredicates, ValueAccessor valueAccessor, boolean hasEnumerationRange) {
this.predicate = predicate;
this.name = name;
+ this.isFunctional = isFunctional;
this.isHasProperty = isHasProperty;
this.classifications = classifications;
this.builder = builder;
this.valueAccessor = valueAccessor;
this.hasEnumerationRange = hasEnumerationRange;
}
- public static PropertyInfo make(ReadGraph graph, Resource predicate, String name, boolean isHasProperty, Set<String> classifications, VariableBuilder builder, Resource literalRange, Datatype requiredDatatype, String definedUnit, String requiredValueType, Map<String,Pair<Resource, ChildReference>> subliteralPredicates, ValueAccessor valueAccessor, boolean hasEnumerationRange) throws DatabaseException {
+ public static PropertyInfo make(ReadGraph graph, Resource predicate, String name, boolean isFunctional, boolean isHasProperty, Set<String> classifications, VariableBuilder builder, Resource literalRange, Datatype requiredDatatype, String definedUnit, String requiredValueType, Map<String,Pair<Resource, ChildReference>> subliteralPredicates, ValueAccessor valueAccessor, boolean hasEnumerationRange) throws DatabaseException {
Layer0 L0 = Layer0.getInstance(graph);
if(literalRange != null) {
Binding defaultBinding = requiredDatatype != null ? Bindings.getBinding(requiredDatatype) : null;
- return new PropertyInfo(predicate, name, isHasProperty, classifications, builder, literalRange, requiredDatatype, definedUnit, requiredValueType, defaultBinding, subliteralPredicates, valueAccessor, hasEnumerationRange);
+ return new PropertyInfo(predicate, name, isFunctional, isHasProperty, classifications, builder, literalRange, requiredDatatype, definedUnit, requiredValueType, defaultBinding, subliteralPredicates, valueAccessor, hasEnumerationRange);
}
public boolean hasClassification(String classification) {
.append(requiredValueType)
.append(", predicate=")
.append(predicate)
+ .append(", isFunctional=")
+ .append(isFunctional)
.append(", isHasProperty=")
.append(isHasProperty)
.append(", hasEnumerationRange=")
String name = graph.getPossibleRelatedValue(resource, L0.HasName, Bindings.STRING);
if(name != null) name = name.intern();
+ boolean isFunctional = graph.isInstanceOf(resource, L0.FunctionalRelation);
+
Set<String> classifications = graph.sync(new ClassificationsRequest(graph.getPrincipalTypes(resource)));
VariableBuilder<?> variableBuilder = graph.getPossibleAdapter(resource, VariableBuilder.class);
}
}
- return PropertyInfo.make(graph, resource, name, isHasProperty, classifications, variableBuilder, literalRange, requiredDataType, definedUnit, requiredValueType, map, accessor, hasEnumerationRange);
+ return PropertyInfo.make(graph, resource, name, isFunctional, isHasProperty, classifications, variableBuilder, literalRange, requiredDataType, definedUnit, requiredValueType, map, accessor, hasEnumerationRange);
}
}
}
- return PropertyInfo.make(graph, resource, name, isHasProperty, classifications, variableBuilder, literalRange, requiredDataType, definedUnit, requiredValueType, Collections.<String,Pair<Resource,ChildReference>>emptyMap(), accessor, hasEnumerationRange);
+ return PropertyInfo.make(graph, resource, name, isFunctional, isHasProperty, classifications, variableBuilder, literalRange, requiredDataType, definedUnit, requiredValueType, Collections.<String,Pair<Resource,ChildReference>>emptyMap(), accessor, hasEnumerationRange);
}
import org.simantics.db.common.procedure.adapter.TransientCacheAsyncListener;
import org.simantics.db.common.request.DelayedWriteRequest;
import org.simantics.db.common.request.ObjectsWithType;
-import org.simantics.db.common.request.PossibleChild;
import org.simantics.db.common.request.PossibleIndexRoot;
import org.simantics.db.common.request.WriteRequest;
import org.simantics.db.common.utils.CommonDBUtils;
import org.simantics.graph.representation.TransferableGraph1;
import org.simantics.layer0.Layer0;
import org.simantics.operation.Layer0X;
-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.scl.osgi.SCLOsgi;
import org.simantics.scl.runtime.function.Function;
return result;
}
+ public static Resource possibleObjectForType(ReadGraph graph, Resource type, Resource relation) throws DatabaseException {
+ PropertyInfo pi = graph.syncRequest(new PropertyInfoRequest(relation));
+ return possibleObjectForType(graph, type, relation, pi.isFunctional);
+ }
+
+ public static Resource possibleObjectForType(ReadGraph graph, Resource type, Resource relation, boolean functional) throws DatabaseException {
+ if(functional) {
+ Layer0 L0 = Layer0.getInstance(graph);
+ Resource result = graph.getPossibleObject(type, relation);
+ if(result != null)
+ return result;
+ for(Resource su : graph.getObjects(L0.Inherits, type)) {
+ Resource r = possibleObjectForType(graph, su, relation, functional);
+ if(r != null) {
+ if(result != null)
+ return null;
+ result = r;
+ }
+ }
+ return result;
+ } else {
+ Set<Resource> found = objectsForTypeNonFunctional(graph, type, relation, new HashSet<>());
+ return found.size() == 1 ? found.iterator().next() : null;
+ }
+ }
+
+ private static Set<Resource> objectsForTypeNonFunctional(ReadGraph graph, Resource type, Resource relation, Set<Resource> found) throws DatabaseException {
+ Layer0 L0 = Layer0.getInstance(graph);
+ found.addAll(graph.getObjects(type, relation));
+ for(Resource su : graph.getObjects(L0.Inherits, type)) {
+ objectsForTypeNonFunctional(graph, su, relation, found);
+ }
+ return found;
+ }
+
public static Resource getPossiblePredicateByNameFromType(ReadGraph graph, Resource type, String name) throws DatabaseException {
Map<String,Resource> domain = getDomainOf(graph, type);
return domain.get(name);
private static final Logger LOGGER = LoggerFactory.getLogger(StandardGraphPropertyVariable.class);
protected static final PropertyInfo NO_PROPERTY = new PropertyInfo(null, null,
- false, Collections.<String> emptySet(), null, null, null, null, null, null,
+ false, false, Collections.<String> emptySet(), null, null, null, null, null, null,
Collections.<String, Pair<Resource, ChildReference>> emptyMap(),
null, false);