1 package org.simantics.db.tests.api.support.clusterBuilder;
4 import org.simantics.db.ReadGraph;
5 import org.simantics.db.Resource;
6 import org.simantics.db.Session;
7 import org.simantics.db.WriteOnlyGraph;
8 import org.simantics.db.common.request.WriteOnlyResultRequest;
9 import org.simantics.db.exception.DatabaseException;
10 import org.simantics.db.request.Read;
11 import org.simantics.db.service.ClusterBuilder;
12 import org.simantics.db.service.SerialisationSupport;
13 import org.simantics.db.service.ClusterBuilder.ResourceHandle;
14 import org.simantics.db.service.ClusterBuilder.StatementHandle;
15 import org.simantics.db.testing.annotation.Fails;
16 import org.simantics.db.testing.base.ExistingDatabaseTest;
17 import org.simantics.layer0.Layer0;
19 public class WriteOrderTest extends ExistingDatabaseTest {
23 public void test() throws DatabaseException {
25 Session session = getSession();
27 final Layer0 b = Layer0.getInstance(session);
29 final Resource res = session.syncRequest(new WriteOnlyResultRequest<Resource>() {
32 public Resource perform(WriteOnlyGraph graph) throws DatabaseException {
34 ClusterBuilder builder = graph.getService(ClusterBuilder.class);
35 SerialisationSupport ss = graph.getService(SerialisationSupport.class);
37 ResourceHandle hasNameR = builder.resource(b.HasName);
38 ResourceHandle nameOfR = builder.resource(b.NameOf);
40 System.out.println("Name of resource is " + nameOfR);
41 ResourceHandle instanceOfR = builder.resource(b.InstanceOf);
42 ResourceHandle libraryR = builder.resource(b.Library);
43 ResourceHandle stringR = builder.resource(b.String);
44 ResourceHandle consistsOf = builder.resource(b.ConsistsOf);
46 System.out.println("ConsistsOf resource is " + consistsOf);
47 ResourceHandle partOf = builder.resource(b.PartOf);
49 StatementHandle instanceOf = builder.newStatement(instanceOfR, libraryR);
50 StatementHandle instanceOfString = builder.newStatement(instanceOfR, stringR);
52 System.out.println("Instance of string is " + instanceOfString);
54 // ResourceHandle root = builder.newResource();
55 // root.addStatement(instanceOf);
57 // ResourceHandle rootLiteral = builder.newResource();
58 // rootLiteral.addStatement(instanceOfString);
59 // rootLiteral.addStatement(nameOf, root);
60 // rootLiteral.addValue(name, binding);
61 // root.addStatement(hasName, rootLiteral);
63 // System.out.println("root: " + root.resource());
64 // System.out.println("literal: " + rootLiteral.resource());
66 // graph.addLiteral(root, b.HasName, b.NameOf, b.String, name, binding);
67 // graph.claim(root, b.InstanceOf, null, b.Library);
69 // StatementHandle rootPart = builder.newStatement(b.PartOf, root);
71 ResourceHandle level1 = builder.newResource();
72 level1.addStatement(instanceOf);
73 level1.addStatement(partOf, level1);
74 // root.addStatement(consistsOf, level1);
75 // ResourceHandle level1Literal = builder.newResource();
76 // level1Literal.addStatement(instanceOfString);
77 // level1Literal.addStatement(nameOf, level1);
78 // level1Literal.addValue(name, binding);
79 level1.addStatement(hasNameR, level1);
81 StatementHandle level1Part = builder.newStatement(partOf, level1);
83 System.out.println("Level1Part is " + level1Part);
85 // System.out.println("root: " + root.resource());
86 // System.out.println("literal: " + rootLiteral.resource());
88 // graph.addLiteral(root, b.HasName, b.NameOf, b.String, name, binding);
89 // graph.claim(root, b.InstanceOf, null, b.Library);
91 return level1.resource(ss);
93 // Resource parent = graph.newResource();
94 // Resource res = graph.newResource();
95 // Resource child = graph.newResource();
96 // Resource literal = graph.newResource();
97 // graph.claim(parent, L0.ConsistsOf, L0.PartOf, res);
98 // graph.claim(res, L0.HasName, L0.NameOf, literal);
99 // graph.claim(res, L0.ConsistsOf, L0.PartOf, child);
100 // graph.claim(res, L0.InstanceOf, null, L0.Library);
101 // graph.claim(literal, L0.InstanceOf, null, L0.String);
102 // graph.claimValue(literal, "A", Bindings.STRING);
109 Resource name = session.syncRequest(new Read<Resource>() {
112 public Resource perform(ReadGraph graph) throws DatabaseException {
113 return graph.getSingleObject(res, L0.HasName);
114 // return graph.getRelatedValue(res, L0.HasName);
119 System.err.println("name: " + name);