-package fi.vtt.simantics.procore.internal;\r
-\r
-import java.io.File;\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 ClusterSetsSupportImpl implements ClusterSetsSupport, Disposable {\r
- \r
- final private static boolean DEBUG = false;\r
- final private static Map<String, ClusterSets> sClusterSets = new HashMap<String, ClusterSets>();\r
- final private File filePath;\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
- ClusterSetsSupportImpl(File filePath) {\r
- this.filePath = filePath;\r
- this.databaseId = null;\r
- this.clusterSets = null;\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(filePath, filePath, 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
- }\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()\r
- 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
- \r
- @Override\r
- public void setReadDirectory(Path read) {\r
- // TODO Auto-generated method stub\r
- \r
- }\r
- @Override\r
- public void updateWriteDirectory(Path write) {\r
- // Nothing to do here\r
- }\r
- \r
- @Override\r
- public void setReadDirectory(Path read) {\r
- \r
- }\r
- \r
-}\r
+package fi.vtt.simantics.procore.internal;
+
+import java.io.File;
+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 ClusterSetsSupportImpl implements ClusterSetsSupport, Disposable {
+
+ final private static boolean DEBUG = false;
+ final private static Map<String, ClusterSets> sClusterSets = new HashMap<String, ClusterSets>();
+ final private File filePath;
+ private String databaseId; // Unique identifier for database of session. Initialized in connect.
+ private ClusterSets clusterSets; // Cluster sets for session. Initialized in connect.
+ ClusterSetsSupportImpl(File filePath) {
+ this.filePath = filePath;
+ 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(filePath, filePath, databaseId);
+ sClusterSets.put(databaseId, clusterSets);
+ } else {
+ count = clusterSets.inc();
+ }
+ if (DEBUG)
+ System.out.println("Starting session " + count + " for database=" + databaseId);
+ }
+ @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) {
+ // Nothing to do here
+ }
+
+ @Override
+ public void setReadDirectory(Path read) {
+
+ }
+
+}