X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;ds=inline;f=bundles%2Forg.simantics.event%2Fsrc%2Forg%2Fsimantics%2Fevent%2Futil%2FEventUtils.java;h=9f29cc7ab15da399c97a55c3485c0d0402b8b49f;hb=7ddecc6d133eff61144784e1b67013a4ed19fc90;hp=bb85be21fe878143cb864547df0576043625efc3;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.event/src/org/simantics/event/util/EventUtils.java b/bundles/org.simantics.event/src/org/simantics/event/util/EventUtils.java index bb85be21f..9f29cc7ab 100644 --- a/bundles/org.simantics.event/src/org/simantics/event/util/EventUtils.java +++ b/bundles/org.simantics.event/src/org/simantics/event/util/EventUtils.java @@ -1,29 +1,72 @@ -package org.simantics.event.util; - -import java.util.UUID; - -import org.simantics.databoard.Bindings; -import org.simantics.db.Resource; -import org.simantics.db.WriteGraph; -import org.simantics.db.exception.DatabaseException; -import org.simantics.event.ontology.EventResource; -import org.simantics.layer0.Layer0; - -public class EventUtils { - - public static final int MAX_EVENTS = 1000; - public static final int SLICE_SIZE = 64; - public static final int KEEPS_SLICES = (MAX_EVENTS / SLICE_SIZE) + 2; - public static final String MAX_SLICE_NAME = "" + (SLICE_SIZE-1); - - public static Resource createLog(WriteGraph graph) throws DatabaseException { - Layer0 L0 = Layer0.getInstance(graph); - EventResource EVENT = EventResource.getInstance(graph); - Resource log = graph.newResource(); - graph.claim(log, L0.InstanceOf, null, EVENT.EventLog); - graph.claimLiteral(log, L0.HasName, UUID.randomUUID().toString(), Bindings.STRING); - graph.claimLiteral(log, EVENT.HasModificationCounter, 0, Bindings.INTEGER); - return log; - } - -} +package org.simantics.event.util; + +import java.util.List; +import java.util.UUID; + +import org.simantics.databoard.Bindings; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.PossibleTypedParent; +import org.simantics.db.exception.DatabaseException; +import org.simantics.event.ontology.EventResource; +import org.simantics.layer0.Layer0; + +public class EventUtils { + + public static final int MAX_EVENTS = 1000; + public static final int SLICE_SIZE = 64; + public static final int KEEPS_SLICES = (MAX_EVENTS / SLICE_SIZE) + 2; + public static final String MAX_SLICE_NAME = "" + (SLICE_SIZE-1); + + public static Resource createLog(WriteGraph graph) throws DatabaseException { + Layer0 L0 = Layer0.getInstance(graph); + EventResource EVENT = EventResource.getInstance(graph); + Resource log = graph.newResource(); + graph.claim(log, L0.InstanceOf, null, EVENT.EventLog); + graph.claimLiteral(log, L0.HasName, UUID.randomUUID().toString(), Bindings.STRING); + graph.claimLiteral(log, EVENT.HasModificationCounter, 0, Bindings.INTEGER); + return log; + } + + /** + * Bumps the modification counter value of the event log of the specified + * events using {@link #bumpModificationCounter(WriteGraph, Resource)}. + *
+ * The code assumes that all events are from the same log.
+ *
+ * @param graph
+ * @param forLogOfEvents
+ * @throws DatabaseException
+ */
+ public static void bumpModificationCounter(WriteGraph graph, List