1 package org.simantics.event.util;
\r
3 import java.util.List;
\r
4 import java.util.UUID;
\r
6 import org.simantics.databoard.Bindings;
\r
7 import org.simantics.db.Resource;
\r
8 import org.simantics.db.WriteGraph;
\r
9 import org.simantics.db.common.request.PossibleTypedParent;
\r
10 import org.simantics.db.exception.DatabaseException;
\r
11 import org.simantics.event.ontology.EventResource;
\r
12 import org.simantics.layer0.Layer0;
\r
14 public class EventUtils {
\r
16 public static final int MAX_EVENTS = 1000;
\r
17 public static final int SLICE_SIZE = 64;
\r
18 public static final int KEEPS_SLICES = (MAX_EVENTS / SLICE_SIZE) + 2;
\r
19 public static final String MAX_SLICE_NAME = "" + (SLICE_SIZE-1);
\r
21 public static Resource createLog(WriteGraph graph) throws DatabaseException {
\r
22 Layer0 L0 = Layer0.getInstance(graph);
\r
23 EventResource EVENT = EventResource.getInstance(graph);
\r
24 Resource log = graph.newResource();
\r
25 graph.claim(log, L0.InstanceOf, null, EVENT.EventLog);
\r
26 graph.claimLiteral(log, L0.HasName, UUID.randomUUID().toString(), Bindings.STRING);
\r
27 graph.claimLiteral(log, EVENT.HasModificationCounter, 0, Bindings.INTEGER);
\r
32 * Bumps the modification counter value of the event log of the specified
\r
33 * events using {@link #bumpModificationCounter(WriteGraph, Resource)}.
\r
35 * The code assumes that all events are from the same log.
\r
38 * @param forLogOfEvents
\r
39 * @throws DatabaseException
\r
41 public static void bumpModificationCounter(WriteGraph graph, List<Resource> forLogOfEvents) throws DatabaseException {
\r
42 EventResource EVENT = EventResource.getInstance(graph);
\r
43 for (Resource event : forLogOfEvents) {
\r
44 Resource log = graph.syncRequest(new PossibleTypedParent(event, EVENT.EventLog));
\r
46 bumpModificationCounter(graph, log);
\r
53 * Bumps the modification counter of the specified event log by 1.
\r
57 * @return new modification counter value
\r
58 * @throws DatabaseException
\r
60 public static int bumpModificationCounter(WriteGraph graph, Resource eventLog) throws DatabaseException {
\r
61 EventResource EVENT = EventResource.getInstance(graph);
\r
62 Resource counter = graph.getPossibleObject(eventLog, EVENT.HasModificationCounter);
\r
63 if (counter != null) {
\r
64 Integer c = graph.getValue(counter, Bindings.INTEGER);
\r
65 c = c == null ? 1 : c+1;
\r
66 graph.claimValue(counter, c, Bindings.INTEGER);
\r