-package org.simantics.structural2.scl;\r
-\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.common.procedure.adapter.TransientCacheListener;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.layer0.variable.Variable;\r
-import org.simantics.scl.runtime.SCLContext;\r
-import org.simantics.scl.runtime.function.Function1;\r
-\r
-public class CompileProceduralExpressionValueRequest extends AbstractCompileStructuralValueRequest {\r
- \r
- protected final String expression;\r
- protected final Resource componentType;\r
- protected final Resource indexRoot;\r
- \r
- public CompileProceduralExpressionValueRequest(String expression, Resource componentType, Resource relation, Resource indexRoot) {\r
- super(relation);\r
- this.expression = expression;\r
- this.componentType = componentType;\r
- this.indexRoot = indexRoot;\r
- }\r
- \r
- public CompileProceduralExpressionValueRequest(ReadGraph graph, String expression, Variable context) throws DatabaseException {\r
- this(expression, context.getParent(graph).getType(graph),\r
- context.getPredicateResource(graph),\r
- context.getIndexRoot(graph));\r
- }\r
- \r
- public static Object compileAndEvaluate(ReadGraph graph, String expression, Variable context) throws DatabaseException {\r
- SCLContext sclContext = SCLContext.getCurrent();\r
- Object oldGraph = sclContext.get("graph");\r
- try {\r
- Function1<Variable,Object> exp = graph.syncRequest(new CompileProceduralExpressionValueRequest(graph, expression, context),\r
- TransientCacheListener.<Function1<Variable,Object>>instance());\r
- sclContext.put("graph", graph);\r
- return exp.apply(context);\r
- } catch (DatabaseException e) {\r
- throw (DatabaseException)e;\r
- } catch (Throwable t) {\r
- throw new DatabaseException(t);\r
- } finally {\r
- sclContext.put("graph", oldGraph);\r
- }\r
- }\r
- \r
- @Override\r
- protected String getExpressionText(ReadGraph graph) throws DatabaseException {\r
- return expression;\r
- }\r
-\r
- @Override\r
- protected Resource getIndexRoot(ReadGraph graph) throws DatabaseException {\r
- return indexRoot;\r
- }\r
-\r
- @Override\r
- protected Resource getComponentType(ReadGraph graph) throws DatabaseException {\r
- return componentType;\r
- }\r
-\r
-}\r
+package org.simantics.structural2.scl;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.common.procedure.adapter.TransientCacheListener;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.variable.Variable;
+import org.simantics.scl.runtime.SCLContext;
+import org.simantics.scl.runtime.function.Function1;
+
+public class CompileProceduralExpressionValueRequest extends AbstractCompileStructuralValueRequest {
+
+ protected final String expression;
+ protected final Resource componentType;
+ protected final Resource indexRoot;
+
+ public CompileProceduralExpressionValueRequest(String expression, Resource componentType, Resource relation, Resource indexRoot) {
+ super(relation);
+ this.expression = expression;
+ this.componentType = componentType;
+ this.indexRoot = indexRoot;
+ }
+
+ public CompileProceduralExpressionValueRequest(ReadGraph graph, String expression, Variable context) throws DatabaseException {
+ this(expression, context.getParent(graph).getType(graph),
+ context.getPredicateResource(graph),
+ context.getIndexRoot(graph));
+ }
+
+ public static Object compileAndEvaluate(ReadGraph graph, String expression, Variable context) throws DatabaseException {
+ SCLContext sclContext = SCLContext.getCurrent();
+ Object oldGraph = sclContext.get("graph");
+ try {
+ Function1<Object,Object> exp = graph.syncRequest(new CompileProceduralExpressionValueRequest(graph, expression, context),
+ TransientCacheListener.instance());
+ sclContext.put("graph", graph);
+ return exp.apply(context);
+ } catch (DatabaseException e) {
+ throw (DatabaseException)e;
+ } catch (Throwable t) {
+ throw new DatabaseException(t);
+ } finally {
+ sclContext.put("graph", oldGraph);
+ }
+ }
+
+ @Override
+ protected String getExpressionText(ReadGraph graph) throws DatabaseException {
+ return expression;
+ }
+
+ @Override
+ protected Resource getIndexRoot(ReadGraph graph) throws DatabaseException {
+ return indexRoot;
+ }
+
+ @Override
+ protected Resource getComponentType(ReadGraph graph) throws DatabaseException {
+ return componentType;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((relation == null) ? 0 : relation.hashCode());
+ result = prime * result + ((componentType == null) ? 0 : componentType.hashCode());
+ result = prime * result + ((expression == null) ? 0 : expression.hashCode());
+ result = prime * result + ((indexRoot == null) ? 0 : indexRoot.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ CompileProceduralExpressionValueRequest other = (CompileProceduralExpressionValueRequest) obj;
+ if (relation == null) {
+ if (other.relation != null)
+ return false;
+ } else if (!relation.equals(other.relation))
+ return false;
+ if (componentType == null) {
+ if (other.componentType != null)
+ return false;
+ } else if (!componentType.equals(other.componentType))
+ return false;
+ if (expression == null) {
+ if (other.expression != null)
+ return false;
+ } else if (!expression.equals(other.expression))
+ return false;
+ if (indexRoot == null) {
+ if (other.indexRoot != null)
+ return false;
+ } else if (!indexRoot.equals(other.indexRoot))
+ return false;
+ return true;
+ }
+
+
+}