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;
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.
@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);
- 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> 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> 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")