]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.common/src/org/simantics/db/common/request/AdaptValue.java
Fixed multiple issues causing dangling references to discarded queries
[simantics/platform.git] / bundles / org.simantics.db.common / src / org / simantics / db / common / request / AdaptValue.java
index 02877596b00d4423fac8387a31bdc73cdde76e87..aeea33f0276c8a1de7dc0736bda0e86f03b0f72f 100644 (file)
@@ -1,13 +1,12 @@
 package org.simantics.db.common.request;
 
+import org.simantics.db.ComputationalValue;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
 import org.simantics.db.common.utils.Functions;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.exception.RuntimeDatabaseException;
 import org.simantics.layer0.Layer0;
-import org.simantics.scl.reflection.ReflectionUtils;
-import org.simantics.scl.reflection.ValueNotFoundException;
 import org.simantics.scl.runtime.function.FunctionImpl3;
 
 /**
@@ -15,12 +14,12 @@ import org.simantics.scl.runtime.function.FunctionImpl3;
  * @author Hannu Niemistö
  */
 public class AdaptValue extends ResourceRead<Object> {
-    
+
     public AdaptValue(Resource resource) {
         super(resource);
     }
 
-    private static final FunctionImpl3<ReadGraph,Resource,Object,Object> functionApplication = new FunctionImpl3<ReadGraph,Resource,Object,Object>() {
+    public static final FunctionImpl3<ReadGraph,Resource,Object,Object> functionApplication = new FunctionImpl3<ReadGraph,Resource,Object,Object>() {
 
                @Override
                public Object apply(ReadGraph graph, Resource resource, Object context) {
@@ -32,16 +31,14 @@ public class AdaptValue extends ResourceRead<Object> {
                }
 
        };
-    
+
     @Override
     public Object perform(ReadGraph graph) throws DatabaseException {
-        String uri = graph.getURI(resource);        
-        try {
-                       if(Layer0.URIs.Functions_functionApplication.equals(uri)) return functionApplication;
-            return ReflectionUtils.getValue(uri).getValue();
-        } catch (ValueNotFoundException e) {
-            throw new DatabaseException("Couldn't adapt the value " + uri, e);
-        }
+        Layer0 L0 = graph.l0();
+        if (L0.Functions_functionApplication.equalsResource(resource))
+            return functionApplication;
+        ComputationalValue ev = graph.adapt(resource, ComputationalValue.class);
+        return ev.getValue(graph, resource);
     }
 
 }