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.common.request.ReadRequest;
18 import org.simantics.db.exception.DatabaseException;
19 import org.simantics.db.service.LifecycleSupport;
20 import org.simantics.db.testing.common.Tests;
21 import org.simantics.layer0.Layer0;
25 static String newInstanceName ="Local1InstanceName";
26 static Session session = null;
27 public static void main(String[] args) {
29 session = Tests.getTestHandler().getSession();
30 session.syncRequest(new ReadRequest() {
32 public void run(ReadGraph g) throws DatabaseException {
33 Layer0 b = Layer0.getInstance(g);
35 Collection<Resource> resources = g.getObjects(g.getRootLibrary(), b.ConsistsOf);
36 for (Resource r : resources) {
37 String value = g.getPossibleRelatedValue(r, b.HasName);
38 if (null != value && value.equals(newInstanceName)) {
42 System.out.println("instance count = " + count);
46 LifecycleSupport ls = session.getService(LifecycleSupport.class);
47 // PublishSynchroniseSupport pss = session.getService(PublishSynchroniseSupport.class);
50 session.syncRequest(new ReadRequest() {
52 public void run(ReadGraph g) throws DatabaseException {
53 Layer0 b = Layer0.getInstance(g);
55 Collection<Resource> resources = g.getObjects(g.getRootLibrary(), b.ConsistsOf);
56 for (Resource r : resources) {
57 String value = g.getPossibleRelatedValue(r, b.HasName);
58 if (null != value && value.equals(newInstanceName)) {
62 System.out.println("instance count = " + count);
67 System.out.println("Ok.");
68 // } catch (ClassNotFoundException e) {
69 // e.printStackTrace();
70 } catch (DatabaseException e) {