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