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%2FSerialisationSupportImpl.java;h=0eaf0ecf0ef7bff56f9851b0fbca774f24c9bcb4;hp=e0e871bb9ad154ae3a6ba93a274b3c86dd9e319b;hb=bfdceb3b5b0e4967358277cd506f237c9ee364c3;hpb=bc872011464c2c2f2b8c1dc045e71a1c748e827e diff --git a/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/SerialisationSupportImpl.java b/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/SerialisationSupportImpl.java index e0e871bb9..0eaf0ecf0 100644 --- a/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/SerialisationSupportImpl.java +++ b/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/SerialisationSupportImpl.java @@ -4,7 +4,9 @@ import org.simantics.db.Resource; import org.simantics.db.ResourceSerializer; import org.simantics.db.common.utils.Logger; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.InvalidResourceReferenceException; import org.simantics.db.impl.ClusterI; +import org.simantics.db.impl.ClusterI.PredicateProcedure; import org.simantics.db.impl.ResourceImpl; import org.simantics.db.procore.cluster.ClusterImpl; import org.simantics.db.procore.cluster.ClusterTraits; @@ -73,11 +75,32 @@ public class SerialisationSupportImpl implements SerialisationSupport { return cluster.clusterUID.toRID(ClusterTraits.getResourceIndexFromResourceKey(resourceKey)); } + static class ExistsPredicateProcedure implements PredicateProcedure { + + boolean exists = false; + + @Override + public boolean execute(Integer c, final int predicateKey, int objectIndex) { + exists = true; + return false; + } + + } + @Override public Resource getResource(ResourceUID uid) throws DatabaseException { ClusterI cluster = session.clusterTable.getClusterByClusterUIDOrMakeProxy(uid.asCID()); int key = ClusterTraits.createResourceKey(cluster.getClusterKey(), (int) uid.getIndex()); - return new ResourceImpl(session.resourceSupport, key); + if (cluster.hasResource(key, session.clusterTranslator)) { + ExistsPredicateProcedure pp = new ExistsPredicateProcedure(); + cluster.forPredicates(key, pp, 0, session.clusterTranslator); + if(pp.exists) { + return new ResourceImpl(session.resourceSupport, key); + } else if (cluster.hasValue(key, session.clusterTranslator)) { + return new ResourceImpl(session.resourceSupport, key); + } + } + throw new InvalidResourceReferenceException("Resource with uid = " + uid + " does not exist."); } }