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;h=48e358ba0534b6156700993a5b3d6792cca11408;hp=c4ed5739c873e809932cf2538c349c4f4f5bf685;hb=fe1a2f532761669e67da4db4ae15096ced8a04db;hpb=e67e00d01d30f362e7a4f599cbcf24770ce13e22 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 index c4ed5739c..48e358ba0 100644 --- 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 @@ -1,83 +1,83 @@ -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 updateWriteDirectory(Path write) { - // Nothing to do here - } - - @Override - public void setReadDirectory(Path read) { - - } - -} +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 updateWriteDirectory(Path write) { + // Nothing to do here + } + + @Override + public void setReadDirectory(Path read) { + + } + +}