]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Removed extra modules OntologyModule imported to namespace 27/2327/2
authorHannu Niemistö <hannu.niemisto@semantum.fi>
Thu, 18 Oct 2018 07:49:37 +0000 (10:49 +0300)
committerHannu Niemistö <hannu.niemisto@semantum.fi>
Thu, 18 Oct 2018 10:21:00 +0000 (13:21 +0300)
While fixing the problem, added some error logging in OntologyModule
implementation

gitlab #131

Change-Id: Ib36590f0901ed8a542afe4c9a225606c1f2109d8

bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/EnvironmentRequest.java
bundles/org.simantics.modeling/src/org/simantics/modeling/scl/ontologymodule/OntologyModule.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/ImportDeclaration.java

index 2e37adee82f5fa26c98b68e767e3fe9bb346481c..f1f235a887d867cb85cbd75daec743256900bf94 100644 (file)
@@ -15,11 +15,14 @@ import org.simantics.scl.compiler.module.repository.UpdateListener;
 import org.simantics.scl.osgi.SCLOsgi;
 import org.simantics.scl.runtime.SCLContext;
 import org.simantics.utils.datastructures.Pair;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * Finds the environment of a model or other index root.
  */
 public abstract class EnvironmentRequest extends UnaryRead<Resource, Pair<EnvironmentSpecification, Environment>> {
+    private static final Logger LOGGER = LoggerFactory.getLogger(EnvironmentRequest.class);
 
     public EnvironmentRequest(Resource parameter) {
         super(parameter);
@@ -78,6 +81,7 @@ public abstract class EnvironmentRequest extends UnaryRead<Resource, Pair<Enviro
                         }
                     });
                 } catch (DatabaseException e) {
+                    LOGGER.error("Finding environment failed", e);
                     callback.exception(e);
                     return;
                 }
@@ -86,6 +90,7 @@ public abstract class EnvironmentRequest extends UnaryRead<Resource, Pair<Enviro
                         environmentSpecification, listener);
             callback.execute(env);
         } catch (ImportFailureException e) {
+            LOGGER.error("Finding environment failed", e);
             callback.exception(new DatabaseException(e));
         }
 
@@ -107,37 +112,42 @@ public abstract class EnvironmentRequest extends UnaryRead<Resource, Pair<Enviro
         else
             mainModuleUri = graph.getURI(parameter) + "/#"; // Add something dummy to the model uri that cannot be in a real URI
 
-        return Pair.make(environmentSpecification, graph.syncRequest(new ParametrizedPrimitiveRead<String, Environment>(mainModuleUri) {
-
-            UpdateListenerImpl sclListener;
-
-            @Override
-            public void register(ReadGraph graph, Listener<Environment> procedure) {
-
-                SCLContext context = SCLContext.getCurrent();
-                Object oldGraph = context.put("graph", graph);
-                try {
-
-                    if(procedure.isDisposed()) {
-                        getEnvironment(environmentSpecification, procedure, null);
-                    } else {
-                        sclListener = new UpdateListenerImpl(environmentSpecification, procedure);
-                        sclListener.notifyAboutUpdate();
+        try {
+            return Pair.make(environmentSpecification, graph.syncRequest(new ParametrizedPrimitiveRead<String, Environment>(mainModuleUri) {
+    
+                UpdateListenerImpl sclListener;
+    
+                @Override
+                public void register(ReadGraph graph, Listener<Environment> procedure) {
+    
+                    SCLContext context = SCLContext.getCurrent();
+                    Object oldGraph = context.put("graph", graph);
+                    try {
+    
+                        if(procedure.isDisposed()) {
+                            getEnvironment(environmentSpecification, procedure, null);
+                        } else {
+                            sclListener = new UpdateListenerImpl(environmentSpecification, procedure);
+                            sclListener.notifyAboutUpdate();
+                        }
+    
+                    } finally {
+                        context.put("graph", oldGraph);
                     }
-
-                } finally {
-                    context.put("graph", oldGraph);
+    
                 }
-
-            }
-
-            @Override
-            public void unregistered() {
-                if(sclListener != null)
-                    sclListener.stopListening();
-            }
-
-        }));
+    
+                @Override
+                public void unregistered() {
+                    if(sclListener != null)
+                        sclListener.stopListening();
+                }
+    
+            }));
+        } catch(DatabaseException e) {
+            LOGGER.error("Environment request failed", e);
+            throw e;
+        }
     }
 
     @Override
index 96ee4218236f1719a9888657c4a3b3ed5111b8a8..aa1cffe23508cc2d51b32cb9a9222ac09edded53 100644 (file)
@@ -1,5 +1,6 @@
 package org.simantics.modeling.scl.ontologymodule;
 
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.HashMap;
@@ -15,7 +16,6 @@ import org.simantics.db.common.request.IndexRoot;
 import org.simantics.db.common.uri.UnescapedChildMapOfResource;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.layer0.util.EnvironmentRequest;
-import org.simantics.db.layer0.util.RuntimeEnvironmentRequest;
 import org.simantics.db.request.Read;
 import org.simantics.layer0.Layer0;
 import org.simantics.scl.compiler.common.names.Name;
@@ -58,18 +58,14 @@ public class OntologyModule extends LazyModule {
     public static final String SCL_TYPES_NAME = "SCLTypes";
     private static final String DB_MODULE = "Simantics/DB";
     private static final String VARIABLE_MODULE = "Simantics/Variable";
-    private static final Collection<ImportDeclaration> DEPENDENCIES = Arrays.asList(
-            new ImportDeclaration(DB_MODULE, null),
-            new ImportDeclaration(VARIABLE_MODULE, null)
-            );
     private static final TCon RESOURCE = Types.con(DB_MODULE, "Resource");
     private static final TCon BROWSABLE = Types.con(DB_MODULE, "Browsable");
     private static final TCon VARIABLE = Types.con(VARIABLE_MODULE, "Variable");
     
     private Resource ontology;
     private String defaultLocalName;
-    private THashMap<Resource,Map<String,Resource>> childMaps = new THashMap<Resource,Map<String,Resource>>();
-    private List<ImportDeclaration> importDeclarations;
+    private THashMap<Resource,Map<String,Resource>> childMaps = new THashMap<>();
+    private ArrayList<ImportDeclaration> importDeclarations = new ArrayList<>();
     private Environment environment;
     
     public OntologyModule(ReadGraph graph, String moduleName) throws DatabaseException {
@@ -96,7 +92,8 @@ public class OntologyModule extends LazyModule {
                 });
             }
         });
-        this.importDeclarations = pair.first.imports;
+        for(ImportDeclaration decl : pair.first.imports)
+            importDeclarations.add(decl.hidden());
         this.environment = pair.second;
     }
     
@@ -122,7 +119,11 @@ public class OntologyModule extends LazyModule {
         public final Resource resource;
         public JustResource(Resource resource) {
             this.resource = resource;
-        }   
+        }
+        @Override
+        public String toString() {
+            return "JustResource(" + resource + ")";
+        }
     }
     private static class ResourceAndSuffix implements ResourceSearchResult {
         public final Resource resource;
@@ -130,7 +131,11 @@ public class OntologyModule extends LazyModule {
         public ResourceAndSuffix(Resource resource, String suffix) {
             this.resource = resource;
             this.suffix = suffix;
-        }  
+        }
+        @Override
+        public String toString() {
+            return "ResourceAndSuffix(" + resource + ", " + suffix + ")";
+        }
     }
     
     private ResourceSearchResult getResourceOrSuffixedResource(String name) {
index 77ac5e78e21bae50d2edf8a175427b35c59758ab..8fe903f515ff18b3d5e7d29bcec08399621d47f5 100644 (file)
@@ -122,6 +122,10 @@ public class ImportDeclaration extends DeclarationAst {
         if (reexport != other.reexport)
             return false;
         return true;
+    }
+
+    public ImportDeclaration hidden() {
+        return new ImportDeclaration(moduleName, null);
     }    
     
 }