X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.spreadsheet.graph%2Fsrc%2Forg%2Fsimantics%2Fspreadsheet%2Fgraph%2FSpreadsheetSessionManager.java;h=d90fe3106613fbad5907920a5711f00492c4bc51;hp=659eddf7458bbf9648ec2d8321cbd453104c4003;hb=82ed7c74dbd83a2a557e781b8674b3262b52da54;hpb=27d76db8786149c91b2e5a97d79c774e8c163eb0 diff --git a/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/SpreadsheetSessionManager.java b/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/SpreadsheetSessionManager.java index 659eddf74..d90fe3106 100644 --- a/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/SpreadsheetSessionManager.java +++ b/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/SpreadsheetSessionManager.java @@ -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 { + 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 createRealm(SpreadsheetBook engine, String id) { return new SpreadsheetRealm(engine, id); } - -// static ConcurrentHashMap REALMS = -// new ConcurrentHashMap(); -// -// static ConcurrentHashMap> SUPPORTS = -// new ConcurrentHashMap>(); -// -// public static SpreadsheetRealm sclRealmById(String id) { -// // CONNECTIONS is ConcurrentHashMap so no synchronization is needed here -// return REALMS.get(id); -// } -// -// public static NodeSupport getOrCreateNodeSupport(String id) { -// synchronized(SUPPORTS) { -// NodeSupport result = SUPPORTS.get(id); -// if(result == null) { -// SpreadsheetRealm realm = getOrCreateSCLRealm(id); -// result = new NodeSupport(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 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); + } } +