From: Tuukka Lehtonen Date: Thu, 28 May 2020 19:15:22 +0000 (+0300) Subject: Added system property for controlling writing of MOD.changed tags X-Git-Tag: v1.43.0~22 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=90d2a369e84615c68cd2ac8b77df438236761e6e;p=simantics%2Fplatform.git Added system property for controlling writing of MOD.changed tags You can set -Dorg.simantics.modeling.writeChangedTags=false to disable writing of MOD.changed tags. The property can be set dynamically at runtime also. gitlab #428 Change-Id: I4867c1742b62d2a4a449d5f98a115e4ce36e0257 (cherry picked from commit 162652c6b36097f0465c0fe13bff53b1a3b3d019) --- 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 1edf3cd31..516fe6231 100644 --- a/bundles/org.simantics.modeling/src/org/simantics/modeling/ModelingUtils.java +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/ModelingUtils.java @@ -70,6 +70,7 @@ import org.simantics.db.Session; import org.simantics.db.Statement; import org.simantics.db.VirtualGraph; import org.simantics.db.WriteGraph; +import org.simantics.db.WriteOnlyGraph; import org.simantics.db.common.Indexing; import org.simantics.db.common.NamedResource; import org.simantics.db.common.QueryMemoryWatcher; @@ -82,6 +83,7 @@ import org.simantics.db.common.request.ObjectsWithType; import org.simantics.db.common.request.PossibleIndexRoot; import org.simantics.db.common.request.ReadRequest; import org.simantics.db.common.request.ResourceRead2; +import org.simantics.db.common.request.WriteOnlyRequest; import org.simantics.db.common.request.WriteRequest; import org.simantics.db.common.request.WriteResultRequest; import org.simantics.db.common.utils.ListUtils; @@ -123,7 +125,6 @@ import org.simantics.db.layer0.util.SimanticsKeys; import org.simantics.db.layer0.util.TransferableGraphConfiguration2; import org.simantics.db.layer0.variable.Variable; import org.simantics.db.layer0.variable.Variables; -import org.simantics.db.request.Read; import org.simantics.db.service.ClusterControl; import org.simantics.db.service.CollectionSupport; import org.simantics.db.service.GraphChangeListenerSupport; @@ -2459,16 +2460,34 @@ public class ModelingUtils { return DiagramGraphUtil.getModelingRules(graph, diagramResource, null); } + //------------------------------------------------------------------------- + + private static final String VG_CHANGE_INFORMATION = "changeInformation"; //$NON-NLS-1$ + public static void markChanged(WriteGraph graph, Resource r) throws DatabaseException { - VirtualGraphSupport support = Simantics.getSession().getService(VirtualGraphSupport.class); - VirtualGraph vg = support.getWorkspacePersistent("changeInformation"); - graph.syncRequest(new WriteRequest(vg) { + VirtualGraph vg = Simantics.getSession().getService(VirtualGraphSupport.class) + .getWorkspacePersistent(VG_CHANGE_INFORMATION); + ModelingResources MOD = ModelingResources.getInstance(graph); + graph.syncRequest(new WriteOnlyRequest(vg) { @Override - public void perform(WriteGraph graph) throws DatabaseException { - ModelingResources MOD = ModelingResources.getInstance(graph); + public void perform(WriteOnlyGraph graph) throws DatabaseException { graph.claim(r, MOD.changed, MOD.changed, r); } }); } - + + public static void markChanged(RequestProcessor processor, Iterable rs) throws DatabaseException { + VirtualGraph vg = Simantics.getSession().getService(VirtualGraphSupport.class) + .getWorkspacePersistent(VG_CHANGE_INFORMATION); + ModelingResources MOD = ModelingResources.getInstance(processor); + processor.syncRequest(new WriteOnlyRequest(vg) { + @Override + public void perform(WriteOnlyGraph graph) throws DatabaseException { + for (Resource r : rs) { + graph.claim(r, MOD.changed, MOD.changed, r); + } + } + }); + } + } 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 3f8ffb15b..d8eed0a66 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 @@ -21,17 +21,28 @@ import org.simantics.modeling.adapters.ChangeInformation; */ public class OntologicalRequirementEnforceRequest extends WriteRequest { + private static final String PROP_WRITE_CHANGED_TAGS = "org.simantics.modeling.writeChangedTags"; //$NON-NLS-1$ + private Collection creates; private Collection modis; private Collection ids; private String author; private long time; + private static String getAuthor() { + return System.getProperty("user.name", ""); //$NON-NLS-1$ //$NON-NLS-2$ + } + + private static boolean writeChangedTags() { + return !System.getProperty(PROP_WRITE_CHANGED_TAGS, "") //$NON-NLS-1$ + .equalsIgnoreCase("false"); //$NON-NLS-1$ + } + public OntologicalRequirementEnforceRequest(Collection creates, Collection modis, Collection ids) { this(creates, modis, ids, - System.getProperty("user.name", ""), + getAuthor(), System.currentTimeMillis()); } @@ -45,7 +56,7 @@ public class OntologicalRequirementEnforceRequest extends WriteRequest { @Override public void perform(WriteGraph graph) throws DatabaseException { - update(graph, creates, modis, ids, true, author, time, true); + update(graph, creates, modis, ids, true, author, time, true, writeChangedTags()); } public static void update( @@ -61,7 +72,7 @@ public class OntologicalRequirementEnforceRequest extends WriteRequest { modis, ids, addComment, - System.getProperty("user.name", ""), + getAuthor(), System.currentTimeMillis(), disableDependencyIndexing); @@ -76,10 +87,24 @@ public class OntologicalRequirementEnforceRequest extends WriteRequest { String author, long time, boolean disableDependencyIndexing) throws DatabaseException + { + update(graph, creates, modis, ids, addComment, author, time, disableDependencyIndexing, writeChangedTags()); + } + + public static void update( + WriteGraph graph, + Collection creates, + Collection modis, + Collection ids, + boolean addComment, + String author, + long time, + boolean disableDependencyIndexing, + boolean writeChangedTags) throws DatabaseException { if (disableDependencyIndexing) Layer0Utils.setDependenciesIndexingDisabled(graph, true); - + ModelingResources MOD = ModelingResources.getInstance(graph); Layer0 L0 = Layer0.getInstance(graph); @@ -93,8 +118,9 @@ public class OntologicalRequirementEnforceRequest extends WriteRequest { for (Resource c : creates) { CommonDBUtils.selectClusterSet(graph, c); graph.claimLiteral(c, MOD.changeInformation, MOD.changeInformation_Inverse, MOD.ChangeInformation, info, ChangeInformation.BINDING); - ModelingUtils.markChanged(graph, c); } + if (writeChangedTags) + ModelingUtils.markChanged(graph, creates); } for (Resource m : modis) { @@ -109,9 +135,10 @@ public class OntologicalRequirementEnforceRequest extends WriteRequest { info.modifiedBy = author; CommonDBUtils.selectClusterSet(graph, m); graph.claimLiteral(m, MOD.changeInformation, MOD.changeInformation_Inverse, MOD.ChangeInformation, info, ChangeInformation.BINDING); - ModelingUtils.markChanged(graph, m); } - + if (writeChangedTags) + ModelingUtils.markChanged(graph, modis); + for (Resource r : ids) { if (!graph.hasStatement(r, L0.identifier)) { CommonDBUtils.selectClusterSet(graph, r); @@ -119,10 +146,8 @@ public class OntologicalRequirementEnforceRequest extends WriteRequest { } } - graph.addMetadata( graph.getMetadata(CommentMetadata.class).add("Updated change information") ); - + graph.addMetadata( graph.getMetadata(CommentMetadata.class).add("Updated change information") ); //$NON-NLS-1$ graph.addMetadata( graph.getMetadata(ChangeHistoryUpdated.class) ); - } } \ No newline at end of file