1 package org.simantics.structural2.scl;
3 import org.simantics.db.ReadGraph;
4 import org.simantics.db.Resource;
5 import org.simantics.db.common.procedure.adapter.TransientCacheListener;
6 import org.simantics.db.exception.DatabaseException;
7 import org.simantics.db.layer0.variable.Variable;
8 import org.simantics.scl.runtime.SCLContext;
9 import org.simantics.scl.runtime.function.Function1;
11 public class CompileProceduralExpressionValueRequest extends AbstractCompileStructuralValueRequest {
13 protected final String expression;
14 protected final Resource componentType;
15 protected final Resource indexRoot;
17 public CompileProceduralExpressionValueRequest(String expression, Resource componentType, Resource relation, Resource indexRoot) {
19 this.expression = expression;
20 this.componentType = componentType;
21 this.indexRoot = indexRoot;
24 public CompileProceduralExpressionValueRequest(ReadGraph graph, String expression, Variable context) throws DatabaseException {
25 this(expression, context.getParent(graph).getType(graph),
26 context.getPredicateResource(graph),
27 context.getIndexRoot(graph));
30 public static Object compileAndEvaluate(ReadGraph graph, String expression, Variable context) throws DatabaseException {
31 SCLContext sclContext = SCLContext.getCurrent();
32 Object oldGraph = sclContext.get("graph");
34 Function1<Variable,Object> exp = graph.syncRequest(new CompileProceduralExpressionValueRequest(graph, expression, context),
35 TransientCacheListener.<Function1<Variable,Object>>instance());
36 sclContext.put("graph", graph);
37 return exp.apply(context);
38 } catch (DatabaseException e) {
39 throw (DatabaseException)e;
40 } catch (Throwable t) {
41 throw new DatabaseException(t);
43 sclContext.put("graph", oldGraph);
48 protected String getExpressionText(ReadGraph graph) throws DatabaseException {
53 protected Resource getIndexRoot(ReadGraph graph) throws DatabaseException {
58 protected Resource getComponentType(ReadGraph graph) throws DatabaseException {