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.db.common.utils.NameUtils;
import org.simantics.db.event.ChangeListener;
import org.simantics.db.exception.CancelTransactionException;
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;
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 {
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);