X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics%2Fsrc%2Forg%2Fsimantics%2FSimantics.java;h=c19efde85913a10c0ed6befba804d01f90b1fab7;hb=346cd36c02aad1e33652a67e03b1508cc58e723f;hp=9a1a354f17131b35e1fbfd7bfcc0565645b95616;hpb=53062e8f34c2d2a910e4e81835c81ebafef1a374;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..c19efde85 100644 --- a/bundles/org.simantics/src/org/simantics/Simantics.java +++ b/bundles/org.simantics/src/org/simantics/Simantics.java @@ -24,6 +24,8 @@ 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.RequestProcessorSpecific; import org.simantics.db.Resource; import org.simantics.db.Session; import org.simantics.db.WriteGraph; @@ -283,6 +285,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 +470,30 @@ 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) { + throw new DatabaseException(t); + } + } + @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 { + return applySCL(module, function, args); + } catch (DatabaseException dbe) { + throw dbe; + } catch (Throwable t) { + throw new DatabaseException(t); + } finally { + sclContext.put("graph", oldGraph); + } } @SuppressWarnings("unchecked")