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