]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.event/src/org/simantics/event/util/EventUtils.java
Sync git svn branch with SVN repository r33324.
[simantics/platform.git] / bundles / org.simantics.event / src / org / simantics / event / util / EventUtils.java
index bb85be21fe878143cb864547df0576043625efc3..c4b83aa994c3c3c9585b39f3a503fd28b9b95416 100644 (file)
@@ -1,10 +1,12 @@
 package org.simantics.event.util;\r
 \r
 package org.simantics.event.util;\r
 \r
+import java.util.List;\r
 import java.util.UUID;\r
 \r
 import org.simantics.databoard.Bindings;\r
 import org.simantics.db.Resource;\r
 import org.simantics.db.WriteGraph;\r
 import java.util.UUID;\r
 \r
 import org.simantics.databoard.Bindings;\r
 import org.simantics.db.Resource;\r
 import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.request.PossibleTypedParent;\r
 import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.event.ontology.EventResource;\r
 import org.simantics.layer0.Layer0;\r
 import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.event.ontology.EventResource;\r
 import org.simantics.layer0.Layer0;\r
@@ -25,5 +27,46 @@ public class EventUtils {
         graph.claimLiteral(log, EVENT.HasModificationCounter, 0, Bindings.INTEGER);\r
         return log;\r
        }\r
         graph.claimLiteral(log, EVENT.HasModificationCounter, 0, Bindings.INTEGER);\r
         return log;\r
        }\r
-       \r
+\r
+    /**\r
+     * Bumps the modification counter value of the event log of the specified\r
+     * events using {@link #bumpModificationCounter(WriteGraph, Resource)}.\r
+     * <p>\r
+     * The code assumes that all events are from the same log.\r
+     * \r
+     * @param graph\r
+     * @param forLogOfEvents\r
+     * @throws DatabaseException\r
+     */\r
+    public static void bumpModificationCounter(WriteGraph graph, List<Resource> forLogOfEvents) throws DatabaseException {\r
+        EventResource EVENT = EventResource.getInstance(graph);\r
+        for (Resource event : forLogOfEvents) {\r
+            Resource log = graph.syncRequest(new PossibleTypedParent(event, EVENT.EventLog));\r
+            if (log != null) {\r
+                bumpModificationCounter(graph, log);\r
+                return;\r
+            }\r
+        }\r
+    }\r
+\r
+    /**\r
+     * Bumps the modification counter of the specified event log by 1.\r
+     * \r
+     * @param graph\r
+     * @param eventLog\r
+     * @return new modification counter value\r
+     * @throws DatabaseException\r
+     */\r
+    public static int bumpModificationCounter(WriteGraph graph, Resource eventLog) throws DatabaseException {\r
+        EventResource EVENT = EventResource.getInstance(graph);\r
+        Resource counter = graph.getPossibleObject(eventLog, EVENT.HasModificationCounter);\r
+        if (counter != null) {\r
+            Integer c = graph.getValue(counter, Bindings.INTEGER);\r
+            c = c == null ? 1 : c+1;\r
+            graph.claimValue(counter, c, Bindings.INTEGER);\r
+            return c;\r
+        }\r
+        return 0;\r
+    }\r
+\r
 }\r
 }\r