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.common.procedure.wrapper;
14 import org.simantics.db.AsyncReadGraph;
15 import org.simantics.db.ReadGraph;
16 import org.simantics.db.common.request.ReadRequest;
17 import org.simantics.db.exception.DatabaseException;
18 import org.simantics.db.procedure.AsyncMultiProcedure;
19 import org.simantics.db.procedure.SyncMultiProcedure;
21 final public class SyncToAsyncMultiProcedure<T> implements AsyncMultiProcedure<T> {
23 final private SyncMultiProcedure<T> procedure;
25 public SyncToAsyncMultiProcedure(SyncMultiProcedure<T> procedure) {
26 this.procedure = procedure;
30 final public void execute(AsyncReadGraph graph, final T result) {
31 graph.asyncRequest(new ReadRequest() {
34 public void run(ReadGraph graph) throws DatabaseException {
35 procedure.execute(graph, result);
42 final public void finished(AsyncReadGraph graph) {
43 graph.asyncRequest(new ReadRequest() {
46 public void run(ReadGraph graph) throws DatabaseException {
47 procedure.finished(graph);
54 public void exception(AsyncReadGraph graph, final Throwable t) {
55 graph.asyncRequest(new ReadRequest() {
58 public void run(ReadGraph graph) throws DatabaseException {
59 procedure.exception(graph, t);
66 public String toString() {
67 return "SyncToAsyncMultiProcedure -> " + procedure;