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.simulator.toolkit.StandardRealm;
+import org.simantics.simulator.toolkit.db.StandardSessionManager;
+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() {
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);
+ }
}
+