]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Layer0Utils.addL0Identifier to prevent possible differentiation of code 64/664/2
authorjsimomaa <jani.simomaa@gmail.com>
Thu, 29 Jun 2017 10:59:41 +0000 (13:59 +0300)
committerJani Simomaa <jani.simomaa@semantum.fi>
Thu, 29 Jun 2017 12:45:55 +0000 (15:45 +0300)
refs #7339

Change-Id: Idfe7a61e1baacbeb782317f0cc0688ee5d0c4a9b

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 936eb58126f0b30563406cd404e1872889d54759..beec63aa1b5a3f928111097b08284f497ba96b43 100644 (file)
@@ -54,6 +54,7 @@ import org.simantics.databoard.type.StringType;
 import org.simantics.databoard.type.UnionType;
 import org.simantics.databoard.type.VariantType;
 import org.simantics.databoard.util.ObjectUtils;
+import org.simantics.datatypes.literal.GUID;
 import org.simantics.db.ChangeSetIdentifier;
 import org.simantics.db.Operation;
 import org.simantics.db.ReadGraph;
@@ -1387,4 +1388,16 @@ public class Layer0Utils {
         return PrettyPrintTG.print(tg, ignoreIdentifiers);
     }
 
+    /**
+     * Adds a random {@link GUID} as a value for <code>L0.identifier</code>
+     * 
+     * @param graph
+     * @param component
+     *            for which the identifier is added
+     * @throws DatabaseException
+     */
+    public static void addL0Identifier(WriteGraph graph, Resource component) throws DatabaseException {
+        Layer0 L0 = Layer0.getInstance(graph);
+        graph.addLiteral(component, L0.identifier, L0.identifier_Inverse, L0.GUID, GUID.random(), GUID.BINDING);
+    }
 }
index 8a5b92228a74f52dd5e4bf41665bf09a0567c88b..753a90292926f6221d002ba187ce51a3bfcd82d7 100644 (file)
@@ -2260,7 +2260,7 @@ public class ModelingUtils {
                Layer0 L0 = Layer0.getInstance(graph);
                while(!todo.isEmpty()) {
                        Resource resource = todo.remove(todo.size()-1);
-            graph.claimLiteral(resource, L0.identifier, L0.GUID, GUID.random(), GUID.BINDING);
+                       Layer0Utils.addL0Identifier(graph, resource);
             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) {
-                                       graph.addLiteral(r, L0.identifier, L0.identifier_Inverse, L0.GUID, GUID.random(), GUID.BINDING);
+                                   Layer0Utils.addL0Identifier(graph, r);
                                        madeChanges = true;
                                }
                                
index b58aef5ff395a13522e5ac3172079f11622cad9e..96aa3f134b7dff7e0aef854b24546f216618622f 100644 (file)
@@ -21,6 +21,7 @@ import org.simantics.datatypes.literal.GUID;
 import org.simantics.db.Resource;
 import org.simantics.db.WriteGraph;
 import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.util.Layer0Utils;
 import org.simantics.diagram.synchronization.ISynchronizationContext;
 import org.simantics.diagram.synchronization.SynchronizationException;
 import org.simantics.diagram.synchronization.SynchronizationHints;
@@ -73,7 +74,7 @@ public class ComponentCopyAdvisor extends GraphCopyAdvisor {
         if (graph.hasStatement(sourceContainer, L0.ConsistsOf, source))
             graph.claim(targetContainer, L0.ConsistsOf, copy);
 
-        graph.claimLiteral(copy, L0.identifier, L0.identifier_Inverse, L0.GUID, GUID.random(), GUID.BINDING);
+        Layer0Utils.addL0Identifier(graph, copy);
         if (context.get(SynchronizationHints.NO_RENAME) == null)
             renameComponent(context, graph, source, copy, sourceContainer, targetContainer);
         return copy;
index 2dda48dff77447087d4331e40ba173e5df7c57d3..3330587b934f5e9c233b997e6b96745aff8e9168 100644 (file)
@@ -19,6 +19,7 @@ import org.simantics.db.Resource;
 import org.simantics.db.WriteGraph;
 import org.simantics.db.common.utils.CommonDBUtils;
 import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.util.Layer0Utils;
 import org.simantics.layer0.Layer0;
 import org.simantics.layer0.utils.direct.GraphUtils;
 import org.simantics.mapping.constraint.instructions.TypedBracketInstruction.CreationInstruction;
@@ -54,7 +55,7 @@ public class NamingCreationInstruction extends CreationInstruction {
             Resource result = GraphUtils.create(g,
                     b.HasName, proposition
             );
-            g.addLiteral(result, b.identifier, b.identifier_Inverse, b.GUID, GUID.random(), GUID.BINDING);
+            Layer0Utils.addL0Identifier(g, result);
             return result;
         } catch (NamingException e1) {
             throw new DatabaseException(e1);
index 3bc7295e75eb37b403523c549c60a32d296b73d5..905305bc3087f657ec6e70739eafdcf8eb4867cb 100644 (file)
@@ -113,7 +113,7 @@ public class OntologicalRequirementEnforceRequest extends WriteRequest {
                for (Resource r : ids) {
                        if (!graph.hasStatement(r, L0.identifier)) {
                                CommonDBUtils.selectClusterSet(graph, r);
-                   graph.addLiteral(r, L0.identifier, L0.identifier_Inverse, L0.GUID, GUID.random(), GUID.BINDING);
+                               Layer0Utils.addL0Identifier(graph, r);
                        }
                }
 
index 9f5897f06a24d476a44d2b4424ac7d58444170a8..9b9dc6cb67ec862501598cc4e10252e7d2c3469f 100644 (file)
@@ -141,8 +141,9 @@ public class StructuralUtils {
         Resource component = ir.perform(g);        
         g.claim(component, L0.HasName, Layer0Utils.literal(g, name));
         g.claim(component, L0.HasLabel, Layer0Utils.literal(g, ""));
-        g.addLiteral(component, L0.identifier, L0.identifier_Inverse, L0.GUID, GUID.random(), GUID.BINDING);
         g.claim(parent, L0.ConsistsOf, component);
+        // Add identifier
+        Layer0Utils.addL0Identifier(g, component);
         // Add comment to change set.
         CommentMetadata cm = g.getMetadata(CommentMetadata.class);
         g.addMetadata(cm.add("Created component " + component));