]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/ClusteringSupportImpl.java
Ignore NoSingleResultException in DependenciesRelation
[simantics/platform.git] / bundles / org.simantics.db.procore / src / fi / vtt / simantics / procore / internal / ClusteringSupportImpl.java
index 463e8c6f88c410b8ad0eec876fdb6bcff5878e8d..44af02533763205530910b83d5ddbf47752beeb5 100644 (file)
@@ -1,90 +1,90 @@
-package fi.vtt.simantics.procore.internal;\r
-\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.exception.ResourceNotFoundException;\r
-import org.simantics.db.exception.RuntimeDatabaseException;\r
-import org.simantics.db.impl.ClusterI;\r
-import org.simantics.db.impl.ResourceImpl;\r
-import org.simantics.db.impl.TransientGraph;\r
-import org.simantics.db.procore.cluster.ClusterImpl;\r
-import org.simantics.db.service.ClusteringSupport;\r
-\r
-public class ClusteringSupportImpl implements ClusteringSupport {\r
-\r
-    final private SessionImplSocket session;\r
-\r
-    ClusteringSupportImpl(SessionImplSocket session) {\r
-        this.session = session;\r
-    }\r
-\r
-    @Override\r
-    public long createCluster() {\r
-        long id;\r
-        try {\r
-            id = session.graphSession.newClusterId();\r
-        } catch (DatabaseException e) {\r
-            throw new RuntimeDatabaseException("Failed to get new cluster id.", e);\r
-        }\r
-        session.clusterTable.makeCluster(id, session.writeOnly);\r
-        return id;\r
-    }\r
-\r
-    @Override\r
-    public long getCluster(Resource r) {\r
-        int id = session.querySupport.getId(r);\r
-        if(id < 0) // Virtual resource\r
-            return TransientGraph.getVirtualClusterKey(id);\r
-        return session.clusterTable.getClusterIdByResourceKeyNoThrow(id);\r
-    }\r
-\r
-    @Override\r
-    public int getNumberOfResources(long clusterId) throws DatabaseException {\r
-        return session.clusterTable.getClusterByClusterId(clusterId).getNumberOfResources(session.clusterTranslator);\r
-    }\r
-\r
-    @Override\r
-    public Resource getResourceByKey(int resourceKey)\r
-            throws ResourceNotFoundException {\r
-        return session.getResourceByKey(resourceKey);\r
-    }\r
-\r
-    @Override\r
-    public Resource getResourceByIndexAndCluster(int resourceIndex, long clusterId)\r
-            throws DatabaseException, ResourceNotFoundException {\r
-        if (resourceIndex < 1)\r
-            throw new ResourceNotFoundException("Illegal resource index=" + resourceIndex + " cluster=" + clusterId);\r
-        ClusterI cluster = session.getClusterTable().getLoadOrThrow(clusterId);\r
-        int n = cluster.getNumberOfResources(null);\r
-        if (resourceIndex > n)\r
-            throw new ResourceNotFoundException("Illegal resource index=" + resourceIndex + " cluster=" + clusterId\r
-                    + " max index=" + n);\r
-        return session.getResource(resourceIndex, clusterId);\r
-    }\r
-//    @Override\r
-//    public Id getModifiedId(long clusterId) throws DatabaseException {\r
-//        return session.clusterTable.getClusterByClusterId(clusterId).getModifiedId();\r
-//    }\r
-\r
-    @Override\r
-    public Resource getClusterSetOfCluster(Resource r) throws DatabaseException {\r
-        if(!r.isPersistent()) return null;\r
-        ClusterImpl cluster = session.clusterTable.getClusterByResourceKey(((ResourceImpl)r).id);\r
-        Long rid = session.clusterSetsSupport.getSet(cluster.getClusterId());\r
-        if(rid == null || rid == 0) return null;\r
-        return session.resourceSerializer.getResource(rid);\r
-    }\r
-\r
-    @Override\r
-    public Resource getClusterSetOfCluster(long cluster) throws DatabaseException {\r
-        Long rid = session.clusterSetsSupport.getSet(cluster);\r
-        if(rid == null || rid == 0) return null;\r
-        return session.resourceSerializer.getResource(rid);\r
-    }\r
-\r
-    @Override\r
-    public boolean isClusterSet(Resource r) throws DatabaseException {\r
-        return session.containsClusterSet(r);\r
-    }\r
-\r
-}\r
+package fi.vtt.simantics.procore.internal;
+
+import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.exception.ResourceNotFoundException;
+import org.simantics.db.exception.RuntimeDatabaseException;
+import org.simantics.db.impl.ClusterI;
+import org.simantics.db.impl.ResourceImpl;
+import org.simantics.db.impl.TransientGraph;
+import org.simantics.db.procore.cluster.ClusterImpl;
+import org.simantics.db.service.ClusteringSupport;
+
+public class ClusteringSupportImpl implements ClusteringSupport {
+
+    final private SessionImplSocket session;
+
+    ClusteringSupportImpl(SessionImplSocket session) {
+        this.session = session;
+    }
+
+    @Override
+    public long createCluster() {
+        long id;
+        try {
+            id = session.graphSession.newClusterId();
+        } catch (DatabaseException e) {
+            throw new RuntimeDatabaseException("Failed to get new cluster id.", e);
+        }
+        session.clusterTable.makeCluster(id, session.writeOnly);
+        return id;
+    }
+
+    @Override
+    public long getCluster(Resource r) {
+        int id = session.querySupport.getId(r);
+        if(id < 0) // Virtual resource
+            return TransientGraph.getVirtualClusterKey(id);
+        return session.clusterTable.getClusterIdByResourceKeyNoThrow(id);
+    }
+
+    @Override
+    public int getNumberOfResources(long clusterId) throws DatabaseException {
+        return session.clusterTable.getClusterByClusterId(clusterId).getNumberOfResources(session.clusterTranslator);
+    }
+
+    @Override
+    public Resource getResourceByKey(int resourceKey)
+            throws ResourceNotFoundException {
+        return session.getResourceByKey(resourceKey);
+    }
+
+    @Override
+    public Resource getResourceByIndexAndCluster(int resourceIndex, long clusterId)
+            throws DatabaseException, ResourceNotFoundException {
+        if (resourceIndex < 1)
+            throw new ResourceNotFoundException("Illegal resource index=" + resourceIndex + " cluster=" + clusterId);
+        ClusterI cluster = session.getClusterTable().getLoadOrThrow(clusterId);
+        int n = cluster.getNumberOfResources(null);
+        if (resourceIndex > n)
+            throw new ResourceNotFoundException("Illegal resource index=" + resourceIndex + " cluster=" + clusterId
+                    + " max index=" + n);
+        return session.getResource(resourceIndex, clusterId);
+    }
+//    @Override
+//    public Id getModifiedId(long clusterId) throws DatabaseException {
+//        return session.clusterTable.getClusterByClusterId(clusterId).getModifiedId();
+//    }
+
+    @Override
+    public Resource getClusterSetOfCluster(Resource r) throws DatabaseException {
+        if(!r.isPersistent()) return null;
+        ClusterImpl cluster = session.clusterTable.getClusterByResourceKey(((ResourceImpl)r).id);
+        Long rid = session.clusterSetsSupport.getSet(cluster.getClusterId());
+        if(rid == null || rid == 0) return null;
+        return session.resourceSerializer.getResource(rid);
+    }
+
+    @Override
+    public Resource getClusterSetOfCluster(long cluster) throws DatabaseException {
+        Long rid = session.clusterSetsSupport.getSet(cluster);
+        if(rid == null || rid == 0) return null;
+        return session.resourceSerializer.getResource(rid);
+    }
+
+    @Override
+    public boolean isClusterSet(Resource r) throws DatabaseException {
+        return session.containsClusterSet(r);
+    }
+
+}