X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.db.layer0%2Fsrc%2Forg%2Fsimantics%2Fdb%2Flayer0%2Futil%2FLayer0Utils.java;h=ad8676f813bdb83d4da1adde8aed547c31541ddb;hp=610c8c8bd42d8735868cf1f80e4603ae5e63b7d8;hb=06aeb7cad707d1fed2c21c1ad9413aa97e901da7;hpb=c61c54a6d841c663bd43b40577fe469bffa15453 diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/Layer0Utils.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/Layer0Utils.java index 610c8c8bd..ad8676f81 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/Layer0Utils.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/Layer0Utils.java @@ -71,7 +71,6 @@ import org.simantics.db.common.primitiverequest.PossibleRelatedValue; 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; @@ -116,9 +115,7 @@ import org.simantics.graph.representation.PrettyPrintTG; 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; @@ -1205,6 +1202,10 @@ public class Layer0Utils { } + public static boolean isMarkedReadOnly(ReadGraph graph, Resource r) throws DatabaseException { + return Boolean.TRUE.equals( graph.getPossibleRelatedValue(r, graph.l0().readOnly, Bindings.BOOLEAN) ); + } + private static TransferableGraph1 makeTG(ReadGraph graph, Resource r) throws DatabaseException { SimanticsClipboardImpl cp = new SimanticsClipboardImpl(); @@ -1382,6 +1383,41 @@ public class Layer0Utils { 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 found = objectsForTypeNonFunctional(graph, type, relation, new HashSet<>()); + return found.size() == 1 ? found.iterator().next() : null; + } + } + + private static Set objectsForTypeNonFunctional(ReadGraph graph, Resource type, Resource relation, Set 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 domain = getDomainOf(graph, type); return domain.get(name);