]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.impl/src/org/simantics/db/impl/BlockingAsyncProcedure.java
Generate parts of db client query code
[simantics/platform.git] / bundles / org.simantics.db.impl / src / org / simantics / db / impl / BlockingAsyncProcedure.java
index 943322cd9dc8f6af1aadf710aac387312de652ea..b751e8f70d5771f8bd0994e58dbaa1d890b53b93 100644 (file)
@@ -22,6 +22,7 @@ import org.simantics.db.impl.graph.ReadGraphImpl;
 import org.simantics.db.procedure.AsyncProcedure;
 
 public class BlockingAsyncProcedure<Result> implements AsyncProcedure<Result> {
+<<<<<<< Upstream, based on branch 'private/antti_threads' of ssh://villberg@gerrit.simantics.org:29418/simantics/platform.git
 
        final private Object key;
     final private ReadGraphImpl graph;
@@ -75,6 +76,63 @@ public class BlockingAsyncProcedure<Result> implements AsyncProcedure<Result> {
     
     public Result getResult() {
         return result;
+=======
+       
+       final private static Object NO_RESULT = new Object();
+
+       final private Object key;
+    final private ReadGraphImpl graph;
+       final private AsyncProcedure<Result> procedure;
+       
+    private Object result = NO_RESULT;
+    private Throwable exception = null;
+    
+    public BlockingAsyncProcedure(ReadGraphImpl graph, AsyncProcedure<Result> procedure, Object key) {
+       this.procedure = procedure;
+       this.key = key;
+       this.graph = ReadGraphImpl.newAsync(graph);
+        this.graph.asyncBarrier.inc();
+    }
+    
+    @Override
+    public void execute(AsyncReadGraph graph, Result result) {
+        this.result = result;
+        this.graph.asyncBarrier.dec();
+        try {
+               if(procedure != null) procedure.execute(graph, result);
+        } catch (Throwable throwable) {
+               Logger.defaultLogError("AsyncProcedure.execute threw for " + procedure, throwable);
+        }
+    }
+
+    @Override
+    public void exception(AsyncReadGraph graph, Throwable t) {
+        this.exception = t;
+        try {
+               if(procedure != null) procedure.exception(graph, t);
+        } catch (Throwable throwable) {
+               Logger.defaultLogError("AsyncProcedure.exception threw for " + procedure, throwable);
+        } finally {
+        }
+        this.graph.asyncBarrier.dec();
+    }
+    
+    public Result get() throws DatabaseException {
+       
+       graph.asyncBarrier.waitBarrier(key, graph);
+       
+       if(exception != null) {
+               if(exception instanceof DatabaseException) throw (DatabaseException)exception;
+               throw new DatabaseException(exception);
+       } else {
+               return (Result)result;
+       }
+       
+    }
+    
+    public Result getResult() {
+        return (Result)result;
+>>>>>>> 82fa68e Generate parts of db client query code
     }
     
     public Throwable getException() {