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 package org.simantics.db.tests.api.request.misc;
14 import java.util.ArrayList;
15 import java.util.concurrent.ConcurrentSkipListSet;
17 import org.junit.Test;
18 import org.simantics.db.AsyncReadGraph;
19 import org.simantics.db.ReadGraph;
20 import org.simantics.db.Resource;
21 import org.simantics.db.Session;
22 import org.simantics.db.exception.DatabaseException;
23 import org.simantics.db.procedure.AsyncProcedure;
24 import org.simantics.db.procedure.Procedure;
25 import org.simantics.db.request.AsyncRead;
26 import org.simantics.db.request.Read;
27 import org.simantics.db.testing.base.ExistingDatabaseTest;
28 import org.simantics.layer0.Layer0;
30 public class SyncAsyncSyncTest4 extends ExistingDatabaseTest {
33 public void test() throws Exception {
35 Session session = getSession();
37 final ConcurrentSkipListSet<String> names = new ConcurrentSkipListSet<String>();
38 final ArrayList<Resource> resources = new ArrayList<Resource>();
39 final Resource root = SyncAsyncSyncUtils.createNames(session, names, resources);
40 final Layer0 b = Layer0.getInstance(getSession());
42 session.syncRequest(new AsyncRead<Resource>() {
45 public int threadHash() {
50 public void perform(AsyncReadGraph graph, final AsyncProcedure<Resource> procedure) {
52 graph.forPossibleObject(root, b.InstanceOf, new AsyncProcedure<Resource>() {
55 public void exception(AsyncReadGraph graph, Throwable throwable) {
59 public void execute(AsyncReadGraph graph, Resource result) {
61 procedure.execute(graph, result);
63 for(final Resource r : resources) {
65 graph.asyncRequest(new Read<String>() {
68 public String perform(ReadGraph graph) throws DatabaseException {
69 return graph.getRelatedValue(r, b.HasName);
73 public String toString() {
74 return "Read " + r.getResourceId();
77 }, new Procedure<String>() {
80 public void exception(Throwable t) {
85 public void execute(String result) {
99 public int getFlags() {
105 assert(names.isEmpty());