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.db.ReadGraph;
15 import org.simantics.db.Resource;
16 import org.simantics.db.Session;
17 import org.simantics.db.WriteGraph;
18 import org.simantics.db.common.request.ReadRequest;
19 import org.simantics.db.common.request.WriteRequest;
20 import org.simantics.db.exception.DatabaseException;
21 import org.simantics.db.exception.ValidationException;
22 import org.simantics.db.service.LifecycleSupport;
23 import org.simantics.db.testing.common.Tests;
24 import org.simantics.layer0.Layer0;
27 public class HeadlessClientToRunningCore {
28 static String newInstanceName ="HeadlessClientTestInstanceName";
29 static Session session = null;
30 public static void main(String[] args) {
32 session = Tests.getTestHandler().getSession();
33 session.syncRequest(new WriteRequest() {
35 public void perform(WriteGraph g) throws DatabaseException {
36 Layer0 b = Layer0.getInstance(g);
37 Resource newResource = g.newResource();
38 g.claim(newResource, b.InstanceOf, null, b.Type);
39 g.claimLiteral(newResource, b.HasName, newInstanceName);
40 g.claim(g.getRootLibrary(), b.ConsistsOf, newResource);
44 session.syncRequest(new ReadRequest() {
46 public void run(ReadGraph g) throws DatabaseException {
47 Layer0 b = Layer0.getInstance(g);
48 Collection<Resource> resources = g.getObjects(g.getRootLibrary(), b.ConsistsOf);
49 Resource newResource = null;
50 for (Resource r : resources) {
51 String value = g.getPossibleRelatedValue(r, b.HasName);
52 if (null != value && value.equals(newInstanceName)) {
57 if (newResource == null) {
58 throw new ValidationException("Could not find created resource");
60 if (!g.isInstanceOf(newResource, b.Type))
61 throw new ValidationException("Created resource is not an instance of Type");
65 session.syncRequest(new ReadRequest() {
67 public void run(ReadGraph g) throws DatabaseException {
68 Layer0 b = Layer0.getInstance(g);
70 Collection<Resource> resources = g.getObjects(g.getRootLibrary(), b.ConsistsOf);
71 for (Resource r : resources) {
72 String value = g.getPossibleRelatedValue(r, b.HasName);
73 if (null != value && value.equals(newInstanceName)) {
77 System.out.println("instance count = " + count);
81 LifecycleSupport ls = session.getService(LifecycleSupport.class);
83 System.out.println("Ok.");
85 // } catch (ClassNotFoundException e) {
86 // e.printStackTrace();
87 } catch (DatabaseException e) {