]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.common/src/org/simantics/db/common/procedure/single/SyncReadProcedure.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.db.common / src / org / simantics / db / common / procedure / single / SyncReadProcedure.java
1 package org.simantics.db.common.procedure.single;\r
2 \r
3 import org.simantics.db.AsyncReadGraph;\r
4 import org.simantics.db.exception.DatabaseException;\r
5 import org.simantics.db.procedure.AsyncProcedure;\r
6 \r
7 final public class SyncReadProcedure<T> implements AsyncProcedure<T> {\r
8 \r
9         private Throwable exception = null;\r
10         public T result = null;\r
11         \r
12         @Override\r
13         public synchronized void execute(AsyncReadGraph graph, T t) {\r
14                 result = t;\r
15         }\r
16 \r
17         @Override\r
18         public void exception(AsyncReadGraph graph, Throwable t) {\r
19                 exception = t;\r
20         }\r
21         \r
22         public void checkAndThrow() throws DatabaseException {\r
23                 if(exception != null) {\r
24                         if (exception instanceof DatabaseException)\r
25                                 throw (DatabaseException) exception;\r
26                         else\r
27                                 throw new DatabaseException(\r
28                                                 "Unexpected exception in ReadGraph.syncRequest(AsyncRead)",\r
29                                                 exception);\r
30                 }\r
31         }\r
32         \r
33 }\r
34 \r