X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.db.procore%2Fsrc%2Ffi%2Fvtt%2Fsimantics%2Fprocore%2Finternal%2FClusterSetsSupportImpl.java;fp=bundles%2Forg.simantics.db.procore%2Fsrc%2Ffi%2Fvtt%2Fsimantics%2Fprocore%2Finternal%2FClusterSetsSupportImpl.java;h=c2030409580b4a184419bfbce4e83d838539b53b;hp=0000000000000000000000000000000000000000;hb=969bd23cab98a79ca9101af33334000879fb60c5;hpb=866dba5cd5a3929bbeae85991796acb212338a08 diff --git a/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/ClusterSetsSupportImpl.java b/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/ClusterSetsSupportImpl.java new file mode 100644 index 000000000..c20304095 --- /dev/null +++ b/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/ClusterSetsSupportImpl.java @@ -0,0 +1,77 @@ +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 sClusterSets = new HashMap(); + 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 updateReadAndWriteDirectories(Path read, Path write) { + // Nothing to do here + } + +}