1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 import java.util.Collection;
14 import org.simantics.databoard.Bindings;
15 import org.simantics.db.ReadGraph;
16 import org.simantics.db.Resource;
17 import org.simantics.db.Session;
18 import org.simantics.db.WriteGraph;
19 import org.simantics.db.common.request.ReadRequest;
20 import org.simantics.db.common.request.WriteRequest;
21 import org.simantics.db.exception.DatabaseException;
22 import org.simantics.db.exception.ValidationException;
23 import org.simantics.db.testing.common.Tests;
24 import org.simantics.layer0.Layer0;
27 public class AdvancedHeadless {
28 static String newInstanceName ="AdvancedClientTestInstanceName";
29 static Session session = null;
30 static Resource newResource;
32 public static void main(String[] args) throws InterruptedException {
34 session = Tests.getTestHandler().getSession();
35 session.syncRequest(new WriteRequest() {
37 public void perform(WriteGraph g) throws DatabaseException {
38 Layer0 b = Layer0.getInstance(g);
39 newResource = g.newResource();
40 g.claim(newResource, b.InstanceOf, null, b.Type);
41 g.claimLiteral(newResource, b.HasName, newInstanceName);
42 g.claim(g.getRootLibrary(), b.ConsistsOf, newResource);
43 g.claimLiteral(newResource, b.HasDescription, "1");
46 session.syncRequest(new WriteRequest() {
49 public void perform(WriteGraph g) throws DatabaseException {
50 Layer0 b = Layer0.getInstance(g);
51 g.claimLiteral(newResource, b.HasDescription, "11");
57 // Thread.sleep(5000);
59 session.syncRequest(new WriteRequest() {
62 public void perform(WriteGraph g) throws DatabaseException {
63 Layer0 b = Layer0.getInstance(g);
64 g.claimLiteral(newResource, b.HasDescription, "111");
70 // Thread.sleep(5000);
72 session.syncRequest(new WriteRequest() {
75 public void perform(WriteGraph g) throws DatabaseException {
76 Layer0 b = Layer0.getInstance(g);
77 g.claimLiteral(newResource, b.HasDescription, "1111");
83 session.syncRequest(new ReadRequest() {
85 public void run(ReadGraph g) throws DatabaseException {
86 Layer0 b = Layer0.getInstance(g);
87 Collection<Resource> resources = g.getObjects(g.getRootLibrary(), b.ConsistsOf);
88 Resource newResource = null;
89 for (Resource r : resources) {
90 String value = g.getPossibleRelatedValue(r, b.HasName);
91 if (null != value && value.equals(newInstanceName)) {
93 String s = g.getRelatedValue(r, b.HasDescription, Bindings.STRING);
94 if (!s.equals("1111"))
95 throw new ValidationException("Value is not correct.");
99 if (newResource == null) {
100 throw new ValidationException("Could not find created resource");
102 if (!g.isInstanceOf(newResource, b.Type))
103 throw new ValidationException("Created resource is not an instance of Type");
107 session.syncRequest(new ReadRequest() {
109 public void run(ReadGraph g) throws DatabaseException {
110 Layer0 b = Layer0.getInstance(g);
112 Collection<Resource> resources = g.getObjects(g.getRootLibrary(), b.ConsistsOf);
113 for (Resource r : resources) {
114 String value = g.getPossibleRelatedValue(r, b.HasName);
115 if (null != value && value.equals(newInstanceName)) {
119 System.out.println("instance count = " + count);
123 //LifecycleSupport ls = session.getService(LifecycleSupport.class);
126 System.out.println("Ok. No ls.close()");
129 // } catch (ClassNotFoundException e) {
130 // e.printStackTrace();
131 } catch (DatabaseException e) {