]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Fixed changes made in commit 3a10ce85. 75/675/2
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Mon, 3 Jul 2017 20:46:20 +0000 (23:46 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Mon, 3 Jul 2017 21:31:20 +0000 (00:31 +0300)
refs #7339

Change-Id: Ib47a5eb67c83a716d82526a5f61c303d9e34f235

bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/Layer0Utils.java
bundles/org.simantics.modeling/src/org/simantics/modeling/ModelingUtils.java
bundles/org.simantics.modeling/src/org/simantics/modeling/mapping/ComponentCopyAdvisor.java
bundles/org.simantics.modeling/src/org/simantics/modeling/mapping/NamingCreationInstruction.java
bundles/org.simantics.modeling/src/org/simantics/modeling/utils/OntologicalRequirementEnforceRequest.java
bundles/org.simantics.structural2/src/org/simantics/structural2/utils/StructuralUtils.java

index beec63aa1b5a3f928111097b08284f497ba96b43..3da57809ae0f381debf8e6520c017855b2ad7144 100644 (file)
@@ -1394,10 +1394,17 @@ public class Layer0Utils {
      * @param graph
      * @param component
      *            for which the identifier is added
+     * @param add
+     *            <code>true</code> to invoke addLiteral, <code>false</code> to
+     *            invoke claimLiteral
      * @throws DatabaseException
      */
-    public static void addL0Identifier(WriteGraph graph, Resource component) throws DatabaseException {
+    public static void claimNewIdentifier(WriteGraph graph, Resource component, boolean add) throws DatabaseException {
         Layer0 L0 = Layer0.getInstance(graph);
-        graph.addLiteral(component, L0.identifier, L0.identifier_Inverse, L0.GUID, GUID.random(), GUID.BINDING);
+        GUID guid = GUID.random();
+        if (add)
+            graph.addLiteral(component, L0.identifier, L0.identifier_Inverse, L0.GUID, guid, GUID.BINDING);
+        else
+            graph.claimLiteral(component, L0.identifier, L0.identifier_Inverse, L0.GUID, guid, GUID.BINDING);
     }
 }
index 753a90292926f6221d002ba187ce51a3bfcd82d7..385947d0ccfbc4616f1729b95eab02f8a0ea77f0 100644 (file)
@@ -2260,7 +2260,7 @@ public class ModelingUtils {
                Layer0 L0 = Layer0.getInstance(graph);
                while(!todo.isEmpty()) {
                        Resource resource = todo.remove(todo.size()-1);
-                       Layer0Utils.addL0Identifier(graph, resource);
+                       Layer0Utils.claimNewIdentifier(graph, resource, false);
             if(deep)
                todo.addAll(graph.getObjects(resource, L0.ConsistsOf));
                }
@@ -2291,7 +2291,7 @@ public class ModelingUtils {
                                
                                GUID existing = graph.getPossibleRelatedValue(r, L0.identifier, GUID.BINDING);
                                if(existing == null) {
-                                   Layer0Utils.addL0Identifier(graph, r);
+                                   Layer0Utils.claimNewIdentifier(graph, r, true);
                                        madeChanges = true;
                                }
                                
index 96aa3f134b7dff7e0aef854b24546f216618622f..6b4e59d176860bdeb53387818a00a8d1d696e6db 100644 (file)
@@ -17,7 +17,6 @@ import java.util.Map;
 
 import org.simantics.Simantics;
 import org.simantics.databoard.Bindings;
-import org.simantics.datatypes.literal.GUID;
 import org.simantics.db.Resource;
 import org.simantics.db.WriteGraph;
 import org.simantics.db.exception.DatabaseException;
@@ -74,7 +73,7 @@ public class ComponentCopyAdvisor extends GraphCopyAdvisor {
         if (graph.hasStatement(sourceContainer, L0.ConsistsOf, source))
             graph.claim(targetContainer, L0.ConsistsOf, copy);
 
-        Layer0Utils.addL0Identifier(graph, copy);
+        Layer0Utils.claimNewIdentifier(graph, copy, false);
         if (context.get(SynchronizationHints.NO_RENAME) == null)
             renameComponent(context, graph, source, copy, sourceContainer, targetContainer);
         return copy;
index 3330587b934f5e9c233b997e6b96745aff8e9168..0796e6879622b15d05a12e50bfe1271d4061774a 100644 (file)
@@ -14,7 +14,6 @@ package org.simantics.modeling.mapping;
 import gnu.trove.map.hash.TIntIntHashMap;
 import gnu.trove.set.hash.TIntHashSet;
 
-import org.simantics.datatypes.literal.GUID;
 import org.simantics.db.Resource;
 import org.simantics.db.WriteGraph;
 import org.simantics.db.common.utils.CommonDBUtils;
@@ -55,7 +54,7 @@ public class NamingCreationInstruction extends CreationInstruction {
             Resource result = GraphUtils.create(g,
                     b.HasName, proposition
             );
-            Layer0Utils.addL0Identifier(g, result);
+            Layer0Utils.claimNewIdentifier(g, result, true);
             return result;
         } catch (NamingException e1) {
             throw new DatabaseException(e1);
index 905305bc3087f657ec6e70739eafdcf8eb4867cb..dd547ffe382bf7bc1dd47c8f31bd3df2c62f6d4e 100644 (file)
@@ -2,7 +2,6 @@ package org.simantics.modeling.utils;
 
 import java.util.Collection;
 
-import org.simantics.datatypes.literal.GUID;
 import org.simantics.db.Resource;
 import org.simantics.db.WriteGraph;
 import org.simantics.db.common.CommentMetadata;
@@ -113,7 +112,7 @@ public class OntologicalRequirementEnforceRequest extends WriteRequest {
                for (Resource r : ids) {
                        if (!graph.hasStatement(r, L0.identifier)) {
                                CommonDBUtils.selectClusterSet(graph, r);
-                               Layer0Utils.addL0Identifier(graph, r);
+                               Layer0Utils.claimNewIdentifier(graph, r, true);
                        }
                }
 
index 9b9dc6cb67ec862501598cc4e10252e7d2c3469f..9a77d100fca3ded3b6924aee9915d05119f52ecb 100644 (file)
@@ -7,7 +7,6 @@ import java.util.List;
 import java.util.Set;
 
 import org.simantics.databoard.Bindings;
-import org.simantics.datatypes.literal.GUID;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.RequestProcessor;
 import org.simantics.db.Resource;
@@ -142,8 +141,7 @@ public class StructuralUtils {
         g.claim(component, L0.HasName, Layer0Utils.literal(g, name));
         g.claim(component, L0.HasLabel, Layer0Utils.literal(g, ""));
         g.claim(parent, L0.ConsistsOf, component);
-        // Add identifier
-        Layer0Utils.addL0Identifier(g, component);
+        Layer0Utils.claimNewIdentifier(g, component, true);
         // Add comment to change set.
         CommentMetadata cm = g.getMetadata(CommentMetadata.class);
         g.addMetadata(cm.add("Created component " + component));