]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/ClusterSetsSupportImpl2.java
Fix for empty cancelled write transactions leaving scheduled updates
[simantics/platform.git] / bundles / org.simantics.db.procore / src / fi / vtt / simantics / procore / internal / ClusterSetsSupportImpl2.java
index 5da4e37615f8c4f2def8e31228b6b1985d7fbbe5..6e6140399f28a3b23a921e7e9ed7abb571ba2063 100644 (file)
@@ -1,86 +1,86 @@
-package fi.vtt.simantics.procore.internal;\r
-\r
-import java.io.IOException;\r
-import java.nio.file.Path;\r
-import java.util.HashMap;\r
-import java.util.Map;\r
-\r
-import org.simantics.db.Disposable;\r
-import org.simantics.db.service.ClusterSets;\r
-import org.simantics.db.service.ClusterSetsSupport;\r
-\r
-public class ClusterSetsSupportImpl2 implements ClusterSetsSupport, Disposable {\r
-\r
-    final private static boolean DEBUG = false;\r
-    final private static Map<String, ClusterSets> sClusterSets = new HashMap<String, ClusterSets>();\r
-    private Path readDirectory;\r
-    private Path writeDirectory;\r
-    private String databaseId; // Unique identifier for database of session. Initialized in connect. \r
-    private ClusterSets clusterSets; // Cluster sets for session. Initialized in connect.\r
-    public ClusterSetsSupportImpl2() {\r
-        this.databaseId = null;\r
-        this.clusterSets = null;\r
-    }\r
-\r
-    public synchronized void connect(String databaseId) {\r
-        assert(null == this.databaseId);\r
-        this.databaseId = databaseId;\r
-        clusterSets = sClusterSets.get(databaseId);\r
-        int count = 1;\r
-        if (null == clusterSets) {\r
-            clusterSets = new ClusterSets(readDirectory.toFile(), writeDirectory.toFile(), databaseId);\r
-            sClusterSets.put(databaseId, clusterSets);\r
-        } else {\r
-            count = clusterSets.inc();\r
-        }\r
-        if (DEBUG)\r
-            System.out.println("Starting session " + count + " for database=" + databaseId);\r
-        clusterSets.touch();\r
-    }\r
-    @Override\r
-    public synchronized void dispose() {\r
-        if (clusterSets == null)\r
-            return;\r
-        clusterSets.dispose();\r
-        if (0 >= clusterSets.dec()) {\r
-            sClusterSets.remove(databaseId);\r
-            if (DEBUG)\r
-                System.out.println("Stopping session for database=" + databaseId);\r
-        }            \r
-        clusterSets = null;\r
-    }\r
-    public synchronized boolean containsKey(long resourceId) {\r
-        return clusterSets.containsKey(resourceId);\r
-    }\r
-    public synchronized Long get(Long resourceId) {\r
-        return clusterSets.get(resourceId);\r
-    }\r
-    public synchronized void put(long resourceId, long clusterId) {\r
-        clusterSets.put(resourceId, clusterId);\r
-    }\r
-    public synchronized void save() throws IOException {\r
-        clusterSets.save();\r
-    }\r
-    \r
-    public synchronized Long getSet(long clusterId) {\r
-        return clusterSets.getClusterSet(clusterId);\r
-    }\r
-    @Override\r
-    public void clear() {\r
-       clusterSets.clear();\r
-    }\r
-    @Override\r
-    public void updateWriteDirectory(Path write) {\r
-        this.writeDirectory = write;\r
-        if(clusterSets != null) {\r
-            clusterSets.setWriteDirectory(writeDirectory.toFile());\r
-            clusterSets.touch();\r
-        }\r
-    }\r
-    \r
-    @Override\r
-    public void setReadDirectory(Path read) {\r
-        this.readDirectory = read;\r
-    }\r
-\r
-}\r
+package fi.vtt.simantics.procore.internal;
+
+import java.io.IOException;
+import java.nio.file.Path;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.simantics.db.Disposable;
+import org.simantics.db.service.ClusterSets;
+import org.simantics.db.service.ClusterSetsSupport;
+
+public class ClusterSetsSupportImpl2 implements ClusterSetsSupport, Disposable {
+
+    final private static boolean DEBUG = false;
+    final private static Map<String, ClusterSets> sClusterSets = new HashMap<String, ClusterSets>();
+    private Path readDirectory;
+    private Path writeDirectory;
+    private String databaseId; // Unique identifier for database of session. Initialized in connect. 
+    private ClusterSets clusterSets; // Cluster sets for session. Initialized in connect.
+    public ClusterSetsSupportImpl2() {
+        this.databaseId = null;
+        this.clusterSets = null;
+    }
+
+    public synchronized void connect(String databaseId) {
+        assert(null == this.databaseId);
+        this.databaseId = databaseId;
+        clusterSets = sClusterSets.get(databaseId);
+        int count = 1;
+        if (null == clusterSets) {
+            clusterSets = new ClusterSets(readDirectory.toFile(), writeDirectory.toFile(), databaseId);
+            sClusterSets.put(databaseId, clusterSets);
+        } else {
+            count = clusterSets.inc();
+        }
+        if (DEBUG)
+            System.out.println("Starting session " + count + " for database=" + databaseId);
+        clusterSets.touch();
+    }
+    @Override
+    public synchronized void dispose() {
+        if (clusterSets == null)
+            return;
+        clusterSets.dispose();
+        if (0 >= clusterSets.dec()) {
+            sClusterSets.remove(databaseId);
+            if (DEBUG)
+                System.out.println("Stopping session for database=" + databaseId);
+        }            
+        clusterSets = null;
+    }
+    public synchronized boolean containsKey(long resourceId) {
+        return clusterSets.containsKey(resourceId);
+    }
+    public synchronized Long get(Long resourceId) {
+        return clusterSets.get(resourceId);
+    }
+    public synchronized void put(long resourceId, long clusterId) {
+        clusterSets.put(resourceId, clusterId);
+    }
+    public synchronized void save() throws IOException {
+        clusterSets.save();
+    }
+    
+    public synchronized Long getSet(long clusterId) {
+        return clusterSets.getClusterSet(clusterId);
+    }
+    @Override
+    public void clear() {
+       clusterSets.clear();
+    }
+    @Override
+    public void updateWriteDirectory(Path write) {
+        this.writeDirectory = write;
+        if(clusterSets != null) {
+            clusterSets.setWriteDirectory(writeDirectory.toFile());
+            clusterSets.touch();
+        }
+    }
+    
+    @Override
+    public void setReadDirectory(Path read) {
+        this.readDirectory = read;
+    }
+
+}