]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ClusterSmall.java
Utilities for listing of statements in DB
[simantics/platform.git] / bundles / org.simantics.db.procore / src / org / simantics / db / procore / cluster / ClusterSmall.java
index ead0099847e70aacf5914535b74600c4d84dbb06..c8309c6bf5303a2909564de1a2f29637a8a34534 100644 (file)
@@ -33,6 +33,8 @@ import org.simantics.db.procedure.AsyncContextMultiProcedure;
 import org.simantics.db.procedure.AsyncMultiProcedure;
 import org.simantics.db.service.ClusterUID;
 import org.simantics.db.service.ResourceUID;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import fi.vtt.simantics.procore.DebugPolicy;
 import fi.vtt.simantics.procore.internal.ClusterChange;
@@ -43,6 +45,8 @@ import gnu.trove.map.hash.TIntShortHashMap;
 import gnu.trove.set.hash.TIntHashSet;
 
 final public class ClusterSmall extends ClusterImpl {
+       
+       private static final Logger LOGGER = LoggerFactory.getLogger(ClusterSmall.class);
     
     private static final int TABLE_HEADER_SIZE = TableHeader.HEADER_SIZE + TableHeader.EXTRA_SIZE;
     private static final int RESOURCE_TABLE_OFFSET = 0;
@@ -522,6 +526,11 @@ final public class ClusterSmall extends ClusterImpl {
         if (DEBUG)
             System.out.println("ClusterSmall.forPredicates: rk=" + resourceKey );
         if (deleted) return false;
+        if(proxy) {
+            ClusterImpl cluster = clusterTable.load2(clusterId, clusterKey);
+            return cluster.forPredicates(resourceKey, procedure, context, support);
+        }
+
         final int resourceIndex = getLocalReference(resourceKey);
         final int predicateIndex = resourceTable.getPredicateIndex(resourceIndex);
         if (0 == predicateIndex)
@@ -652,6 +661,10 @@ final public class ClusterSmall extends ClusterImpl {
     public boolean hasValue(int resourceKey, ClusterSupport support)
     throws DatabaseException {
         if (deleted) return false;
+        if(proxy) {
+            ClusterImpl cluster = clusterTable.load2(clusterId, clusterKey);
+            return cluster.hasValue(resourceKey, support);
+        }
         int resourceIndex = getLocalReference(resourceKey);
         return resourceTable.hasValue(resourceIndex);
     }
@@ -739,6 +752,15 @@ final public class ClusterSmall extends ClusterImpl {
     }
     @Override
     public boolean hasResource(int resourceKey, ClusterSupport support) {
+        if(proxy) {
+                       try {
+                               ClusterImpl cluster = clusterTable.load2(clusterId, clusterKey);
+                   return cluster.hasResource(resourceKey, support);
+                       } catch (DatabaseException e) {
+                               LOGGER.error("Failed to load cluster with clusterId " + clusterId);
+                               return false;
+                       }
+        }
         if (deleted) return false;
         int clusterKey = ClusterTraitsBase.getClusterKeyFromResourceKeyNoThrow(resourceKey);
         if (this.clusterKey != clusterKey) // foreign resource
@@ -935,13 +957,21 @@ final public class ClusterSmall extends ClusterImpl {
     @Override
     public void load() {
         if (deleted) return;
-        throw new Error("Not supported.");
+        try {
+               clusterTable.load2(clusterId, clusterKey);
+        } catch (DatabaseException e) {
+               LOGGER.error("Failed to load cluster with clusterId " + clusterId, e);
+        }
     }
 
     @Override
     public void load(Consumer<DatabaseException> r) {
         if (deleted) return;
-        throw new Error("Not supported.");
+        try {
+               clusterTable.load2(clusterId, clusterKey);
+        } catch (DatabaseException e) {
+               r.accept(e);
+        }
     }
 
     public boolean contains(int resourceKey) {
@@ -955,7 +985,7 @@ final public class ClusterSmall extends ClusterImpl {
             clusterTable.load2(clusterId, clusterKey);
             callback.run();
         } catch (DatabaseException e) {
-            e.printStackTrace();
+               LOGGER.error("Failed to load cluster with clusterId " + clusterId, e);
         }
 
     }