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