1 package fi.vtt.simantics.procore.internal;
4 import java.io.IOException;
5 import java.nio.file.Path;
6 import java.util.HashMap;
9 import org.simantics.db.Disposable;
10 import org.simantics.db.service.ClusterSets;
11 import org.simantics.db.service.ClusterSetsSupport;
13 public class ClusterSetsSupportImpl implements ClusterSetsSupport, Disposable {
15 final private static boolean DEBUG = false;
16 final private static Map<String, ClusterSets> sClusterSets = new HashMap<String, ClusterSets>();
17 final private File filePath;
18 private String databaseId; // Unique identifier for database of session. Initialized in connect.
19 private ClusterSets clusterSets; // Cluster sets for session. Initialized in connect.
20 ClusterSetsSupportImpl(File filePath) {
21 this.filePath = filePath;
22 this.databaseId = null;
23 this.clusterSets = null;
25 public synchronized void connect(String databaseId) {
26 assert(null == this.databaseId);
27 this.databaseId = databaseId;
28 clusterSets = sClusterSets.get(databaseId);
30 if (null == clusterSets) {
31 clusterSets = new ClusterSets(filePath, filePath, databaseId);
32 sClusterSets.put(databaseId, clusterSets);
34 count = clusterSets.inc();
37 System.out.println("Starting session " + count + " for database=" + databaseId);
40 public synchronized void dispose() {
41 if (clusterSets == null)
43 clusterSets.dispose();
44 if (0 >= clusterSets.dec()) {
45 sClusterSets.remove(databaseId);
47 System.out.println("Stopping session for database=" + databaseId);
51 public synchronized boolean containsKey(long resourceId) {
52 return clusterSets.containsKey(resourceId);
54 public synchronized Long get(Long resourceId) {
55 return clusterSets.get(resourceId);
57 public synchronized void put(long resourceId, long clusterId) {
58 clusterSets.put(resourceId, clusterId);
60 public synchronized void save()
65 public synchronized Long getSet(long clusterId) {
66 return clusterSets.getClusterSet(clusterId);
74 public void updateWriteDirectory(Path write) {
79 public void setReadDirectory(Path read) {