X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.structural2%2Fsrc%2Forg%2Fsimantics%2Fstructural2%2Fscl%2FCompileProceduralExpressionValueRequest.java;h=b402520d74cbe0bb5487e2d96ed15c35c8196af6;hp=753d06bba2df04835abe1ae0d83efb0bad2c7bc1;hb=27cae6bcf184f7e27822886f5a7320f771913b71;hpb=969bd23cab98a79ca9101af33334000879fb60c5 diff --git a/bundles/org.simantics.structural2/src/org/simantics/structural2/scl/CompileProceduralExpressionValueRequest.java b/bundles/org.simantics.structural2/src/org/simantics/structural2/scl/CompileProceduralExpressionValueRequest.java index 753d06bba..b402520d7 100644 --- a/bundles/org.simantics.structural2/src/org/simantics/structural2/scl/CompileProceduralExpressionValueRequest.java +++ b/bundles/org.simantics.structural2/src/org/simantics/structural2/scl/CompileProceduralExpressionValueRequest.java @@ -1,62 +1,100 @@ -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 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; - } - -} +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 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 + ((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 (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; + } + + +}