]> gerrit.simantics Code Review - simantics/platform.git/blob - tests/org.simantics.db.tests/tutorial/Local2.java
(refs #7358) Mars to Oxygen updates
[simantics/platform.git] / tests / org.simantics.db.tests / tutorial / Local2.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 import java.util.Collection;
13
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;
22
23
24 public class Local2 {
25         static String newInstanceName ="Local1InstanceName";
26         static Session session = null;
27         public static void main(String[] args) {
28                 try {
29                         session = Tests.getTestHandler().getSession();
30                 session.syncRequest(new ReadRequest() {
31                     @Override
32                     public void run(ReadGraph g) throws DatabaseException {
33                         Layer0 b = Layer0.getInstance(g);
34                         int count = 0;
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)) {
39                                                     count++;
40                                                 }
41                                         }
42                                         System.out.println("instance count = " + count);
43                                 }
44                 });
45
46                 LifecycleSupport ls = session.getService(LifecycleSupport.class);
47 //            PublishSynchroniseSupport pss = session.getService(PublishSynchroniseSupport.class);
48 //            pss.synchronize();
49
50                 session.syncRequest(new ReadRequest() {
51                     @Override
52                     public void run(ReadGraph g) throws DatabaseException {
53                         Layer0 b = Layer0.getInstance(g);
54                         int count = 0;
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)) {
59                                                     count++;
60                                                 }
61                                         }
62                                         System.out.println("instance count = " + count);
63                                 }
64                 });
65
66             ls.close();
67             System.out.println("Ok.");
68 //              } catch (ClassNotFoundException e) {
69 //                      e.printStackTrace();
70                 } catch (DatabaseException e) {
71                         e.printStackTrace();
72                 }
73         }
74 }