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;
return cluster.clusterUID.toRID(ClusterTraits.getResourceIndexFromResourceKey(resourceKey));
}
+ static class ExistsPredicateProcedure implements PredicateProcedure<Integer> {
+
+ 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.");
}
}