X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.acorn%2Fsrc%2Forg%2Fsimantics%2Facorn%2Fcluster%2FClusterSmall.java;h=d20ddae6cf53d765314cad11250a0a460c7731c5;hp=726071dbecd3c5d5521ba457481dfffc83efaa43;hb=4aba159170fc72d39c2f930ea224aa71f4cdc2e7;hpb=873afce76b92cb7cf9094fe60e407278f220e5ed diff --git a/bundles/org.simantics.acorn/src/org/simantics/acorn/cluster/ClusterSmall.java b/bundles/org.simantics.acorn/src/org/simantics/acorn/cluster/ClusterSmall.java index 726071dbe..d20ddae6c 100644 --- a/bundles/org.simantics.acorn/src/org/simantics/acorn/cluster/ClusterSmall.java +++ b/bundles/org.simantics.acorn/src/org/simantics/acorn/cluster/ClusterSmall.java @@ -15,16 +15,18 @@ import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.util.Arrays; +import java.util.function.Consumer; +import org.simantics.acorn.exception.IllegalAcornStateException; import org.simantics.acorn.internal.ClusterChange; import org.simantics.acorn.internal.ClusterStream; import org.simantics.acorn.internal.ClusterSupport2; import org.simantics.acorn.internal.DebugPolicy; import org.simantics.db.Resource; +import org.simantics.db.common.utils.Logger; import org.simantics.db.exception.DatabaseException; import org.simantics.db.exception.ExternalValueException; import org.simantics.db.exception.ValidationException; -import org.simantics.db.impl.ClusterBase; import org.simantics.db.impl.ClusterI; import org.simantics.db.impl.ClusterSupport; import org.simantics.db.impl.ClusterTraitsBase; @@ -36,8 +38,8 @@ import org.simantics.db.impl.IClusterTable; 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.procore.cluster.ClusterMapSmall; import org.simantics.db.procore.cluster.ClusterTraits; import org.simantics.db.procore.cluster.ClusterTraitsSmall; @@ -51,8 +53,8 @@ import org.simantics.db.procore.cluster.ValueTableSmall; import org.simantics.db.service.Bytes; import org.simantics.db.service.ClusterUID; import org.simantics.db.service.ResourceUID; -import org.simantics.utils.datastructures.Callback; +import fi.vtt.simantics.procore.internal.SessionImplSocket; import gnu.trove.map.hash.TIntShortHashMap; import gnu.trove.procedure.TIntProcedure; import gnu.trove.set.hash.TIntHashSet; @@ -299,7 +301,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 (DEBUG) System.out.println("ClusterSmall.forObjects1: rk=" + resourceKey + " pk=" + predicateKey); @@ -313,7 +315,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); @@ -407,29 +409,28 @@ 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 { - throw new UnsupportedOperationException(); - -// SessionImplSocket session = (SessionImplSocket)graph.getSession(); -// ClusterSupport support = session.clusterTranslator; -// if (DEBUG) -// System.out.println("ClusterSmall.forObjects3: rk=" + resourceKey + " pk=" + predicateKey); -// final int resourceIndex = ClusterTraitsBase.getResourceIndexFromResourceKey(resourceKey); -// final int pRef = getInternalReferenceOrZero2(predicateKey, support); -// final int completeType = ClusterTraitsBase.getCompleteTypeIntFromResourceKey(predicateKey); -// final ClusterI.CompleteTypeEnum pCompleteType = CompleteTypeEnum.make(completeType); -// if (completeType > 0) { -// resourceTable.foreachObject(resourceIndex, graph, procedure, support, pRef, pCompleteType, completeTable, this); -// return; -// } -// final int predicateIndex = (int)resourceTable.table[(resourceIndex<<1) - 1 + resourceTable.offset] & 0xFFFFFF; -// if (0 == predicateIndex) { -// resourceTable.foreachObject(resourceIndex, graph, procedure, support, pRef, pCompleteType, completeTable, this); -// return; -// } -// int objectIndex = predicateTable.getObjectIndex(predicateIndex, pRef & 0xFFFF); -// forObjects(graph, resourceKey, predicateKey, objectIndex, procedure, support); + SessionImplSocket session = (SessionImplSocket)graph.getSession(); + ClusterSupport support = session.clusterTranslator; + if (DEBUG) + System.out.println("ClusterSmall.forObjects3: rk=" + resourceKey + " pk=" + predicateKey); + final int resourceIndex = ClusterTraitsBase.getResourceIndexFromResourceKey(resourceKey); + final int pRef = getInternalReferenceOrZero2(predicateKey, support); + final int completeType = ClusterTraitsBase.getCompleteTypeIntFromResourceKey(predicateKey); + final ClusterI.CompleteTypeEnum pCompleteType = CompleteTypeEnum.make(completeType); + if (completeType > 0) { + resourceTable.foreachObject(resourceIndex, graph, procedure, support, pRef, pCompleteType, completeTable, this); + return; + } + final int predicateIndex = (int)resourceTable.table[(resourceIndex<<1) - 1 + resourceTable.offset] & 0xFFFFFF; + if (0 == predicateIndex) { + resourceTable.foreachObject(resourceIndex, graph, procedure, support, pRef, pCompleteType, completeTable, this); + return; + } + int objectIndex = predicateTable.getObjectIndex(predicateIndex, pRef & 0xFFFF); + forObjects(graph, resourceKey, predicateKey, objectIndex, procedure, support); + } public void forObjects(ReadGraphImpl graph, int resourceKey, ForEachObjectProcedure procedure) throws DatabaseException { @@ -595,7 +596,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(); @@ -641,7 +642,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(); @@ -708,8 +709,7 @@ final public class ClusterSmall extends ClusterImpl { } } @Override - public byte[] getValue(int resourceKey, ClusterSupport support) - throws DatabaseException { + public byte[] getValue(int resourceKey, ClusterSupport support) throws DatabaseException { if (DEBUG) System.out.println("ClusterSmall.getValue " + resourceKey); int resourceIndex = ClusterTraitsBase.getResourceIndexFromResourceKeyNoThrow(resourceKey); @@ -838,12 +838,11 @@ final public class ClusterSmall extends ClusterImpl { return resourceTable.getUsedSize(); } - public int getNumberOfResources() { - - if(proxy) throw new IllegalStateException(); + public int getNumberOfResources() throws IllegalAcornStateException { + if(proxy) + throw new IllegalAcornStateException("proxy == true for " + clusterId); return resourceTable.getUsedSize(); - } @Override @@ -1019,7 +1018,7 @@ final public class ClusterSmall extends ClusterImpl { } @Override - public void load(Callback r) { + public void load(Consumer r) { throw new Error("Not supported."); } @@ -1134,7 +1133,13 @@ final public class ClusterSmall extends ClusterImpl { }); return "ClusterSmall[" + getClusterUID() + " - " + getClusterId() + " - " + getNumberOfResources() + " - " + foreignTable.getResourceHashMap().size() + " - " + set.size() + "]"; } catch (DatabaseException e) { - return "ClusterSmall[" + getNumberOfResources() + "]"; + try { + return "ClusterSmall[" + getNumberOfResources() + "]"; + } catch (IllegalAcornStateException e1) { + Logger.defaultLogError(e1); + e1.printStackTrace(); + return "An exception occured!!"; + } } } @@ -1270,7 +1275,7 @@ final public class ClusterSmall extends ClusterImpl { } @Override - public Table getForeignTable() { + public Table getForeignTable() { return foreignTable; }