X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.db.procore%2Fsrc%2Forg%2Fsimantics%2Fdb%2Fprocore%2Fcluster%2FClusterSmall.java;h=b24862a67ba190fbda07166346724a934c2e8d64;hp=ead0099847e70aacf5914535b74600c4d84dbb06;hb=4aba159170fc72d39c2f930ea224aa71f4cdc2e7;hpb=b29a69792f689d2ac7beffb725c814aa65fca301 diff --git a/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ClusterSmall.java b/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ClusterSmall.java index ead009984..b24862a67 100644 --- a/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ClusterSmall.java +++ b/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ClusterSmall.java @@ -29,10 +29,12 @@ import org.simantics.db.impl.ForPossibleRelatedValueProcedure; import org.simantics.db.impl.Table; import org.simantics.db.impl.TableHeader; import org.simantics.db.impl.graph.ReadGraphImpl; -import org.simantics.db.procedure.AsyncContextMultiProcedure; -import org.simantics.db.procedure.AsyncMultiProcedure; +import org.simantics.db.procedure.SyncContextMultiProcedure; +import org.simantics.db.procedure.SyncMultiProcedure; 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; @@ -268,7 +272,7 @@ final public class ClusterSmall extends ClusterImpl { return objectTable.getSingleObject(objectIndex, support, this); } - public void forObjects(ReadGraphImpl graph, int resourceKey, int predicateKey, int objectIndex, AsyncMultiProcedure procedure, + public void forObjects(ReadGraphImpl graph, int resourceKey, int predicateKey, int objectIndex, SyncMultiProcedure procedure, ClusterSupport support) throws DatabaseException { if (deleted) return; if (DEBUG) @@ -283,7 +287,7 @@ final public class ClusterSmall extends ClusterImpl { objectTable.foreachObject(graph, objectIndex, procedure, this); } - public void forObjects(ReadGraphImpl graph, int resourceKey, int predicateKey, int objectIndex, C context, AsyncContextMultiProcedure procedure, + public void forObjects(ReadGraphImpl graph, int resourceKey, int predicateKey, int objectIndex, C context, SyncContextMultiProcedure procedure, ClusterSupport support) throws DatabaseException { if (DEBUG) System.out.println("ClusterSmall.forObjects1: rk=" + resourceKey + " pk=" + predicateKey); @@ -382,7 +386,7 @@ final public class ClusterSmall extends ClusterImpl { @Override public void forObjects(ReadGraphImpl graph, int resourceKey, - int predicateKey, AsyncMultiProcedure procedure) throws DatabaseException { + int predicateKey, SyncMultiProcedure procedure) throws DatabaseException { if (deleted) return; SessionImplSocket session = (SessionImplSocket)graph.getSession(); ClusterSupport support = session.clusterTranslator; @@ -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) @@ -567,7 +576,7 @@ final public class ClusterSmall extends ClusterImpl { support.setStreamOff(false); ClusterI cluster2 = cluster.addRelation(sResourceKey, pResourceKey, oResourceKey, support); if (cluster != cluster2) - throw new DatabaseException("Internal error. Contact application support."); + throw new DatabaseException("Internal error, cluster mismatch."); return cluster; } // check(); @@ -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 @@ -886,8 +908,11 @@ final public class ClusterSmall extends ClusterImpl { if (ClusterTraitsSmall.resourceRefIsLocal(resourceRef)) { key = clusterBits | resourceRef; } else { - foreignTable.fillResourceUID(ClusterTraitsSmall.resourceRefGetForeignIndex((short)resourceRef), this); - key = ClusterTraitsBase.createResourceKey(clusterSupport.getClusterKeyByClusterUIDOrMake(clusterUID1, clusterUID2), executeIndex); + // TODO: not so nice + synchronized(this) { + foreignTable.fillResourceUID(ClusterTraitsSmall.resourceRefGetForeignIndex((short)resourceRef), this); + key = ClusterTraitsBase.createResourceKey(clusterSupport.getClusterKeyByClusterUIDOrMake(clusterUID1, clusterUID2), executeIndex); + } } if (DEBUG) System.out.println("ClusterSmall.execute key=" + key); @@ -935,13 +960,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 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 +988,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); } }