From: jsimomaa Date: Thu, 29 Jun 2017 10:59:41 +0000 (+0300) Subject: Layer0Utils.addL0Identifier to prevent possible differentiation of code X-Git-Tag: v1.31.0~288 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=3a10ce85;p=simantics%2Fplatform.git Layer0Utils.addL0Identifier to prevent possible differentiation of code refs #7339 Change-Id: Idfe7a61e1baacbeb782317f0cc0688ee5d0c4a9b --- 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 936eb5812..beec63aa1 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 @@ -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 L0.identifier + * + * @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); + } } diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/ModelingUtils.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/ModelingUtils.java index 8a5b92228..753a90292 100644 --- a/bundles/org.simantics.modeling/src/org/simantics/modeling/ModelingUtils.java +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/ModelingUtils.java @@ -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; } diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/mapping/ComponentCopyAdvisor.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/mapping/ComponentCopyAdvisor.java index b58aef5ff..96aa3f134 100644 --- a/bundles/org.simantics.modeling/src/org/simantics/modeling/mapping/ComponentCopyAdvisor.java +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/mapping/ComponentCopyAdvisor.java @@ -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; diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/mapping/NamingCreationInstruction.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/mapping/NamingCreationInstruction.java index 2dda48dff..3330587b9 100644 --- a/bundles/org.simantics.modeling/src/org/simantics/modeling/mapping/NamingCreationInstruction.java +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/mapping/NamingCreationInstruction.java @@ -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); diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/utils/OntologicalRequirementEnforceRequest.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/utils/OntologicalRequirementEnforceRequest.java index 3bc7295e7..905305bc3 100644 --- a/bundles/org.simantics.modeling/src/org/simantics/modeling/utils/OntologicalRequirementEnforceRequest.java +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/utils/OntologicalRequirementEnforceRequest.java @@ -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); } } diff --git a/bundles/org.simantics.structural2/src/org/simantics/structural2/utils/StructuralUtils.java b/bundles/org.simantics.structural2/src/org/simantics/structural2/utils/StructuralUtils.java index 9f5897f06..9b9dc6cb6 100644 --- a/bundles/org.simantics.structural2/src/org/simantics/structural2/utils/StructuralUtils.java +++ b/bundles/org.simantics.structural2/src/org/simantics/structural2/utils/StructuralUtils.java @@ -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));