1 package org.simantics.modeling.tests.commands;
3 import java.util.concurrent.TimeUnit;
5 import org.simantics.Simantics;
6 import org.simantics.databoard.binding.Binding;
7 import org.simantics.db.ReadGraph;
8 import org.simantics.db.Resource;
9 import org.simantics.db.WriteGraph;
10 import org.simantics.db.common.request.ReadRequest;
11 import org.simantics.db.common.request.UniqueRead;
12 import org.simantics.db.common.request.WriteRequest;
13 import org.simantics.db.exception.DatabaseException;
14 import org.simantics.db.layer0.util.EvaluatingListener;
15 import org.simantics.db.layer0.util.EvaluatingListener.Criterion;
16 import org.simantics.db.layer0.variable.Variable;
17 import org.simantics.db.layer0.variable.Variables;
18 import org.simantics.modeling.tests.traits.SingleResourceTrait;
25 public static void waitMapping() throws DatabaseException {
31 public static void sync() throws DatabaseException {
33 // Multiple bugs here:
34 // -Model performs activation in separate write transactions because API does not support changing the virtual graph
35 // => activation & activation listener is delayed beyond this point
36 // -This should be fixed by the following code
37 // TransactionSupport ts = session.getService(TransactionSupport.class);
38 // ts.waitCompletion();
39 // but unfortunately this does not work either...
40 // so we synchronize by a familiar write transaction
43 // And then wait still some more
44 for(int i=0;i<3;i++) {
45 Simantics.getSession().syncRequest(new WriteRequest() {
48 public void perform(WriteGraph graph) throws DatabaseException {
53 public String toString() {
59 // And then wait still some more
60 Simantics.getSession().syncRequest(new ReadRequest() {
63 public void run(ReadGraph graph) throws DatabaseException {
72 public static void writeConfiguration(final Resource model, final String rvi, final Object value, final Binding binding) throws DatabaseException {
74 class WriteConfiguration extends WriteRequest {
77 public void perform(WriteGraph graph) throws DatabaseException {
78 Variable state = Variables.getVariable(graph, graph.getURI(model) + rvi);
79 state.setValue(graph, value, binding);
84 Simantics.getSession().syncRequest(new WriteConfiguration());
88 public static <T>T readValue(final SingleResourceTrait run, final String rvi, final Criterion<T> criterion) throws DatabaseException, InterruptedException {
90 return EvaluatingListener.<T>trySyncRequest(Simantics.getSession(),
92 @SuppressWarnings("unchecked")
94 public T perform(ReadGraph graph) throws DatabaseException{
95 Variable state = Variables.getPossibleVariable(graph, graph.getURI(run.getResource(graph)) + rvi);
96 return (T) (state != null ? state.getValue(graph) : null);
101 15, TimeUnit.SECONDS);