]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.document.server/src/org/simantics/document/server/request/ServerSCLValueRequest.java
Fixed multiple issues causing dangling references to discarded queries
[simantics/platform.git] / bundles / org.simantics.document.server / src / org / simantics / document / server / request / ServerSCLValueRequest.java
index adff8dab5b9ec87d1271e1ca02d1d3bea58e49a3..37d60a4439b90b1e79314a7ae5de48702629d4f2 100644 (file)
@@ -9,16 +9,12 @@ import org.simantics.db.Resource;
 import org.simantics.db.Statement;
 import org.simantics.db.common.procedure.adapter.TransientCacheListener;
 import org.simantics.db.common.request.IndexRoot;
-import org.simantics.db.common.request.PossibleTypedParent;
 import org.simantics.db.common.request.UnaryRead;
 import org.simantics.db.common.utils.NameUtils;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.layer0.scl.AbstractExpressionCompilationContext;
-import org.simantics.db.layer0.scl.AbstractExpressionCompilationRequest;
 import org.simantics.db.layer0.util.RuntimeEnvironmentRequest2;
 import org.simantics.db.layer0.variable.Variable;
-import org.simantics.document.base.ontology.DocumentationResource;
-import org.simantics.document.server.request.ServerSCLValueRequest.CompilationContext;
 import org.simantics.layer0.Layer0;
 import org.simantics.scl.compiler.common.names.Name;
 import org.simantics.scl.compiler.constants.StringConstant;
@@ -45,7 +41,7 @@ import org.simantics.utils.datastructures.Pair;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class ServerSCLValueRequest extends AbstractExpressionCompilationRequest<CompilationContext, Object> {
+public class ServerSCLValueRequest extends ServerSCLValueRequestBase<org.simantics.document.server.request.ServerSCLValueRequest.CompilationContext> {
 
        private final Pair<Resource,Resource> componentTypeAndRoot;
        private final Resource literal;
@@ -91,39 +87,9 @@ public class ServerSCLValueRequest extends AbstractExpressionCompilationRequest<
                return Pair.make(parent.getType(graph), root);
        }
 
-       private static Pair<Resource,Resource> getComponentTypeAndRoot(ReadGraph graph, Resource component, Resource literal)  throws DatabaseException {
-               if(component != null) {
-                       Resource type = graph.syncRequest(new FindPossibleComponentTypeRequest(component));
-                       if(type != null) {
-                               Resource root = graph.syncRequest(new IndexRoot(type));
-                               //      System.err.println("getComponentTypeAndRoot3 " + graph.getPossibleURI(component) + " => " + graph.getPossibleURI(type) + " " + graph.getPossibleURI(root));
-                               return Pair.make(type, root);
-                       } else {
-                               Resource doc = graph.syncRequest(new PossibleTypedParent(component, DocumentationResource.getInstance(graph).Document));
-                               if(doc != null) {
-                                       Resource componentType = graph.getSingleType(doc);
-                                       Resource root = graph.syncRequest(new IndexRoot(doc));
-                                       return Pair.make(componentType, root);
-                               } else {
-                                       //System.err.println("component = " + component);
-                                       Resource root = graph.syncRequest(new IndexRoot(component));
-//                                     Resource componentType = graph.getSingleType(doc);
-                                       return Pair.make(null, root);
-                               }
-                       }
-        // TODO: For Antti to consider and fix later
-        // Introduced to handle procedural user components where component == null
-        } else if (literal != null) {
-            Resource root = graph.syncRequest(new IndexRoot(literal));
-            return Pair.make(null, root);
-        } else {
-            throw new DatabaseException("Couldn't resolve component type and root for component == null && literal == null");
-        }
-       }
-
        public static Object compileAndEvaluate(ReadGraph graph, Variable context) throws DatabaseException {
                SCLContext sclContext = SCLContext.getCurrent();
-        Object oldGraph = sclContext.get("graph");
+               Object oldGraph = sclContext.get("graph");
                try {
                        Function1<Object,Object> exp = compile(graph, context);
                        sclContext.put("graph", graph);
@@ -133,7 +99,7 @@ public class ServerSCLValueRequest extends AbstractExpressionCompilationRequest<
                } catch (Throwable t) {
                        throw new DatabaseException(t);
                } finally {
-            sclContext.put("graph", oldGraph);
+                       sclContext.put("graph", oldGraph);
                }
        }