]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
ListUtils.create(g,elements) creates a list without element inverses 83/3083/1
authorMarko Luukkainen <marko.luukkainen@semantum.fi>
Fri, 9 Aug 2019 09:40:53 +0000 (12:40 +0300)
committerMarko Luukkainen <marko.luukkainen@semantum.fi>
Fri, 9 Aug 2019 10:34:03 +0000 (10:34 +0000)
Added new ListUtils.createWithInverses for lists with default element
inverse relations.

gitlab #336

Change-Id: I246d5bb170ff91d8f59aa656d6b0279f9b2b11b1
(cherry picked from commit d17ee3b8f3720f59c08780ced525d670a83844b0)

bundles/org.simantics.db.common/src/org/simantics/db/common/utils/ListUtils.java

index a197de88013dec935b1a46c3fb680c5fdf1831e9..656dfeb27550b8acfe8e1f1c8801cbebefe6e879 100644 (file)
@@ -55,9 +55,14 @@ public class ListUtils {
      */
     public static Resource create(WriteGraph g, Iterable<Resource> elements) throws DatabaseException {
        Layer0 L0 = Layer0.getInstance(g);
-       return ListUtils.create(g,L0.List, L0.List_ElementWithInverse, L0.List_ElementWithInverse_Inverse, elements);
+       return ListUtils.create(g,L0.List, L0.List_Element, null, elements);
     }
-
+    
+    public static Resource createWithInverses(WriteGraph g, Iterable<Resource> elements) throws DatabaseException {
+       Layer0 L0 = Layer0.getInstance(g);
+       return ListUtils.create(g,L0.ListWithInverses, L0.List_ElementWithInverse, L0.List_ElementWithInverse_Inverse, elements);
+    }
+    
     /**
      * Creates a list of the given list type containing the given {@code elements}.
      */
@@ -85,6 +90,8 @@ public class ListUtils {
         Layer0 L0 = g.getService(Layer0.class);
         Resource list = g.newResource();
         g.claim(list, L0.InstanceOf, null, type);
+        if (!elementPredicate.equals(L0.List_Element))
+               g.claim(list, L0.List_ElementPredicate, L0.List_ElementPredicate_Inverse, elementPredicate);
         createExisting(g, list, elementPredicate, elementPredicateInverse, elements);
         return list;
     }