Layer0Utils.addL0Identifier to prevent possible differentiation of code
[simantics/platform.git] / bundles / org.simantics.db.layer0 / src / org / simantics / db / layer0 / util / Layer0Utils.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);
+    }
 }