]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics/src/org/simantics/Simantics.java
Graph bookkeeping gets broken in SCL request API
[simantics/platform.git] / bundles / org.simantics / src / org / simantics / Simantics.java
index b382fba9151798aa6f414b6b1f65071ebcc21212..cbe17e940d9436223aa6c2b62127872963a7b769 100644 (file)
@@ -24,6 +24,7 @@ import org.simantics.SimanticsPlatform.RecoveryPolicy;
 import org.simantics.application.arguments.IArguments;
 import org.simantics.application.arguments.SimanticsArguments;
 import org.simantics.db.ReadGraph;
+import org.simantics.db.RequestProcessor;
 import org.simantics.db.Resource;
 import org.simantics.db.Session;
 import org.simantics.db.WriteGraph;
@@ -283,6 +284,14 @@ public class Simantics {
             throw new IllegalStateException("Session unavailable, no database session open");
         return ctx.getSession();
     }
+    
+    public static RequestProcessor getAvailableRequestProcessor() {
+        Object graph = SCLContext.getCurrent().get("graph");
+        if(graph instanceof ReadGraph)
+            return (RequestProcessor)graph;
+        else
+            return Simantics.getSession();
+    }
 
     /**
      * Returns the database Session bound to the currently active context.
@@ -467,11 +476,12 @@ public class Simantics {
         } catch (ValueNotFound e) {
             throw new DatabaseException("SCL Value not found: " + e.name);
         } catch (Throwable t) {
+            if (t instanceof DatabaseException)
+                throw (DatabaseException) t;
             throw new DatabaseException(t);
         }
     }
 
-    @SuppressWarnings({ "unchecked", "rawtypes" })
     public static <T> T applySCL(String module, String function, ReadGraph graph, Object ... args) throws DatabaseException {
         SCLContext sclContext = SCLContext.getCurrent();
         Object oldGraph = sclContext.put("graph", graph);
@@ -493,6 +503,8 @@ public class Simantics {
         try {
             return (T)f.applyArray(args);
         } catch (Throwable t) {
+            if (t instanceof DatabaseException)
+                throw (DatabaseException) t;
             throw new DatabaseException(t);
         } finally {
             sclContext.put("graph", oldGraph);
@@ -506,6 +518,8 @@ public class Simantics {
         try {
             return (T)f.applyArray(args);
         } catch (Throwable t) {
+            if (t instanceof DatabaseException)
+                throw (DatabaseException) t;
             throw new DatabaseException(t);
         } finally {
             sclContext.put("graph", oldGraph);
@@ -518,6 +532,8 @@ public class Simantics {
         try {
             return function.apply(p0);
         } catch (Throwable t) {
+            if (t instanceof DatabaseException)
+                throw (DatabaseException) t;
             throw new DatabaseException(t);
         } finally {
             sclContext.put("graph", oldGraph);
@@ -530,6 +546,8 @@ public class Simantics {
         try {
             return function.apply(p0);
         } catch (Throwable t) {
+            if (t instanceof DatabaseException)
+                throw (DatabaseException) t;
             throw new DatabaseException(t);
         } finally {
             sclContext.put("graph", oldGraph);
@@ -542,6 +560,8 @@ public class Simantics {
         try {
             return function.apply(p0, p1);
         } catch (Throwable t) {
+            if (t instanceof DatabaseException)
+                throw (DatabaseException) t;
             throw new DatabaseException(t);
         } finally {
             sclContext.put("graph", oldGraph);