1 package org.simantics.db.tests.regression.bugs;
4 import org.simantics.databoard.Bindings;
5 import org.simantics.db.ReadGraph;
6 import org.simantics.db.Resource;
7 import org.simantics.db.Session;
8 import org.simantics.db.WriteGraph;
9 import org.simantics.db.WriteOnlyGraph;
10 import org.simantics.db.common.request.UniqueRead;
11 import org.simantics.db.common.request.WriteOnlyRequest;
12 import org.simantics.db.common.request.WriteRequest;
13 import org.simantics.db.event.ChangeEvent;
14 import org.simantics.db.event.ChangeListener;
15 import org.simantics.db.exception.DatabaseException;
16 import org.simantics.db.service.GraphChangeListenerSupport;
17 import org.simantics.db.service.VirtualGraphSupport;
18 import org.simantics.db.testing.base.ExistingDatabaseTest;
20 public class SimanticsBug3114Test extends ExistingDatabaseTest {
22 private Resource newResource;
25 public void test() throws Exception {
27 Session session = getSession();
28 GraphChangeListenerSupport support = session.getService(GraphChangeListenerSupport.class);
30 // This listener writes 2 versions of a functional property into the same resource. The resulting model is broken if queries are not updated correctly.
31 support.addMetadataListener(new ChangeListener() {
34 public void graphChanged(ChangeEvent e) throws DatabaseException {
35 WriteGraph graph = (WriteGraph)e.getGraph();
36 graph.sync(new WriteRequest(graph.getService(VirtualGraphSupport.class).getMemoryPersistent("mem")) {
39 public void perform(WriteGraph graph) throws DatabaseException {
40 graph.claimLiteral(newResource, L0.HasName, "name", Bindings.STRING);
41 graph.claimLiteral(newResource, L0.HasName, "name2", Bindings.STRING);
50 // Perform host request as write only.
51 session.sync(new WriteOnlyRequest() {
54 public void perform(WriteOnlyGraph graph) throws DatabaseException {
55 newResource = graph.newResource();
56 graph.claim(newResource, L0.InstanceOf, null, L0.Entity);
61 // Ensure correct results
62 assertEquals("name2", getSession().sync(new UniqueRead<String>() {
64 public String perform(ReadGraph graph) throws DatabaseException {
65 return graph.getRelatedValue(newResource, L0.HasName, Bindings.STRING);