]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/SpreadsheetSessionManager.java
Some fixes for resource cleaning spreadsheets in simupedia
[simantics/platform.git] / bundles / org.simantics.spreadsheet.graph / src / org / simantics / spreadsheet / graph / SpreadsheetSessionManager.java
index 659eddf7458bbf9648ec2d8321cbd453104c4003..d90fe3106613fbad5907920a5711f00492c4bc51 100644 (file)
@@ -13,18 +13,24 @@ import java.util.Set;
 
 import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
+import org.simantics.db.WriteGraph;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.layer0.StandardRealm;
 import org.simantics.db.layer0.StandardSessionManager;
 import org.simantics.db.layer0.variable.ProxyVariables;
 import org.simantics.db.layer0.variable.Variable;
 import org.simantics.db.layer0.variable.Variables;
+import org.simantics.spreadsheet.graph.formula.SpreadsheetEvaluationEnvironment;
 import org.simantics.spreadsheet.graph.synchronization.SpreadsheetSynchronizationEventHandler;
 import org.simantics.spreadsheet.resource.SpreadsheetResource;
 import org.simantics.structural.synchronization.Synchronizer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class SpreadsheetSessionManager extends StandardSessionManager<SheetNode, SpreadsheetBook> {
 
+    private static final Logger LOGGER = LoggerFactory.getLogger(SpreadsheetSessionManager.class);
+    
        private static SpreadsheetSessionManager INSTANCE;
        
        public static SpreadsheetSessionManager getInstance() {
@@ -148,56 +154,18 @@ public class SpreadsheetSessionManager extends StandardSessionManager<SheetNode,
        protected StandardRealm<SheetNode, SpreadsheetBook> createRealm(SpreadsheetBook engine, String id) {
                return new SpreadsheetRealm(engine, id);
        }
-       
-//    static ConcurrentHashMap<String, SpreadsheetRealm> REALMS =
-//            new ConcurrentHashMap<String, SpreadsheetRealm>(); 
-//    
-//    static ConcurrentHashMap<String, NodeSupport<String>> SUPPORTS =
-//            new ConcurrentHashMap<String, NodeSupport<String>>(); 
-//    
-//    public static SpreadsheetRealm sclRealmById(String id) {
-//        // CONNECTIONS is ConcurrentHashMap so no synchronization is needed here
-//        return REALMS.get(id);
-//    }
-//    
-//    public static NodeSupport<String> getOrCreateNodeSupport(String id) {
-//        synchronized(SUPPORTS) {
-//             NodeSupport<String> result = SUPPORTS.get(id);
-//             if(result == null) {
-//                     SpreadsheetRealm realm = getOrCreateSCLRealm(id);
-//                     result = new NodeSupport<String>(realm.getNodeManager());
-//                     SUPPORTS.put(id, result);
-//             }
-//             return result;
-//        }
-//    }
-//    
-//    public static SpreadsheetRealm createRealm() {
-//        synchronized(REALMS) {
-//            String id = UUID.randomUUID().toString();
-//            return createRealm(id);
-//        }
-//    }
-//    
-//    public static SpreadsheetRealm getOrCreateSCLRealm(String id) {
-//        synchronized(REALMS) {
-//             SpreadsheetRealm session = sclRealmById(id);
-//            if(session == null)
-//                return createRealm(id);
-//            else
-//                return session;
-//        }
-//    }
-//    
-//    private static SpreadsheetRealm createRealm(String id) {
-//        SpreadsheetBook book = new SpreadsheetBook();
-//        SpreadsheetRealm realm = new SpreadsheetRealm(book, id);
-//        REALMS.put(id, realm);
-//        return realm;
-//    }
-//    
-//    public static void removeRealm(String id) {
-//             REALMS.remove(id);
-//    }
-       
+
+       @Override
+       public void removeRealm(WriteGraph graph, String id) throws DatabaseException {
+        StandardRealm<SheetNode, SpreadsheetBook> realm = getOrCreateRealm(graph, id);
+        SpreadsheetEvaluationEnvironment.removeInstance(realm.getEngine());
+        super.removeRealm(graph, id);
+    }
+    
+    // Utility function for SCL, this should maybe be replaced with something better in the future
+    public static void removeSpreadsheetSession(WriteGraph graph, Variable runVariable) throws DatabaseException {
+        String uri = runVariable.getParent(graph).getURI(graph);
+        getInstance().removeRealm(graph, uri);
+    }
 }
+