X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics%2Fsrc%2Forg%2Fsimantics%2FSimantics.java;h=cbe17e940d9436223aa6c2b62127872963a7b769;hb=refs%2Fchanges%2F35%2F1235%2F4;hp=9a1a354f17131b35e1fbfd7bfcc0565645b95616;hpb=e3f78a075fb589c0c940f6e13d92a45a39a3ac0f;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics/src/org/simantics/Simantics.java b/bundles/org.simantics/src/org/simantics/Simantics.java index 9a1a354f1..cbe17e940 100644 --- a/bundles/org.simantics/src/org/simantics/Simantics.java +++ b/bundles/org.simantics/src/org/simantics/Simantics.java @@ -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. @@ -460,20 +469,31 @@ public class Simantics { @SuppressWarnings({ "unchecked", "rawtypes" }) - public static T applySCL(String module, String function, ReadGraph graph, Object ... args) throws DatabaseException { - SCLContext sclContext = SCLContext.getCurrent(); - Object oldGraph = sclContext.put("graph", graph); - try { - T t = (T)((Function)SCLOsgi.MODULE_REPOSITORY.getValue(module, function)).applyArray(args); - return t; - } catch (ValueNotFound e) { - throw new DatabaseException("SCL Value not found: " + e.name); - } catch (Throwable t) { - throw new DatabaseException(t); - } finally { - sclContext.put("graph", oldGraph); - } + public static T applySCL(String module, String function, Object ... args) throws DatabaseException { + try { + T t = (T)((Function)SCLOsgi.MODULE_REPOSITORY.getValue(module, function)).applyArray(args); + return t; + } 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); + } + } + public static T applySCL(String module, String function, ReadGraph graph, Object ... args) throws DatabaseException { + SCLContext sclContext = SCLContext.getCurrent(); + Object oldGraph = sclContext.put("graph", graph); + try { + return applySCL(module, function, args); + } catch (DatabaseException dbe) { + throw dbe; + } catch (Throwable t) { + throw new DatabaseException(t); + } finally { + sclContext.put("graph", oldGraph); + } } @SuppressWarnings("unchecked") @@ -483,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); @@ -496,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); @@ -508,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); @@ -520,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); @@ -532,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);