1 package org.simantics.modeling.scl;
3 import org.simantics.db.ReadGraph;
4 import org.simantics.db.common.procedure.adapter.TransientCacheListener;
5 import org.simantics.db.exception.DatabaseException;
6 import org.simantics.db.layer0.variable.Variable;
7 import org.simantics.scl.runtime.SCLContext;
8 import org.simantics.scl.runtime.function.Function1;
9 import org.simantics.structural2.scl.CompileStructuralValueRequest;
11 public class CompileSCLValueRequest extends CompileStructuralValueRequest {
13 public CompileSCLValueRequest(ReadGraph graph, Variable context)
14 throws DatabaseException {
15 super(graph, context);
18 public static Object compileAndEvaluate(ReadGraph graph, Variable context) throws DatabaseException {
19 SCLContext sclContext = SCLContext.getCurrent();
20 Object oldGraph = sclContext.get("graph");
22 Function1<Variable,Object> exp = graph.syncRequest(new CompileSCLValueRequest(graph, context),
23 TransientCacheListener.<Function1<Variable,Object>>instance());
24 sclContext.put("graph", graph);
25 return exp.apply(context);
26 } catch (DatabaseException e) {
27 throw (DatabaseException)e;
28 } catch (Throwable t) {
29 throw new DatabaseException(t);
31 sclContext.put("graph", oldGraph);