]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.common/src/org/simantics/db/common/procedure/wrapper/SyncToAsyncProcedure.java
Add logging by default to adapters exception-methods
[simantics/platform.git] / bundles / org.simantics.db.common / src / org / simantics / db / common / procedure / wrapper / SyncToAsyncProcedure.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 package org.simantics.db.common.procedure.wrapper;
13
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.AsyncProcedure;
19 import org.simantics.db.procedure.SyncProcedure;
20
21 final public class SyncToAsyncProcedure<T> implements AsyncProcedure<T> {
22
23         final private SyncProcedure<T> procedure;
24
25         public SyncToAsyncProcedure(SyncProcedure<T> procedure) {
26                 this.procedure = procedure;
27         }
28         
29         @Override
30         final public void execute(AsyncReadGraph graph, final T result) {
31                 graph.asyncRequest(new ReadRequest() {
32
33                         @Override
34                         public void run(ReadGraph graph) throws DatabaseException {
35                                 procedure.execute(graph, result);
36                         }
37                         
38                 });
39         }
40
41         @Override
42         final public void exception(AsyncReadGraph graph, final Throwable t) {
43         graph.asyncRequest(new ReadRequest() {
44
45             @Override
46             public void run(ReadGraph graph) throws DatabaseException {
47                 procedure.exception(graph, t);
48             }
49             
50         });
51         }
52         
53     @Override
54     public String toString() {
55         return "SyncToAsyncProcedure -> " + procedure;
56    }
57
58 }