}
Iterator relationships = entity.getRelationshipMap().entrySet().iterator();
while (relationships.hasNext()) {
Map.Entry entry = (Map.Entry) relationships.next();
ObjRelationship rel = (ObjRelationship) entry.getValue();
// if target doesn't propagates its key value, skip it
if (rel.isSourceIndependentFromTargetChange()) {
continue;
}
Object targetObject = object.readPropertyDirectly(rel.getName());
if (targetObject == null) {
continue;
}
// if target is Fault, get id attributes from stored snapshot
// to avoid unneeded fault triggering
if (targetObject instanceof Fault) {
DataRow storedSnapshot = getObjectStore().getSnapshot(
object.getObjectId());
if (storedSnapshot == null) {
throw new CayenneRuntimeException(
"No matching objects found for ObjectId "
+ object.getObjectId()
+ ". Object may have been deleted externally.");
}
DbRelationship dbRel = (DbRelationship) rel.getDbRelationships().get(0);
Iterator joins = dbRel.getJoins().iterator();
while (joins.hasNext()) {
DbJoin join = (DbJoin) joins.next();
String key = join.getSourceName();
snapshot.put(key, storedSnapshot.get(key));
}
continue;
}
// target is resolved and we have an FK->PK to it,
// so extract it from target...
DataObject target = (DataObject) targetObject;
Map idParts = target.getObjectId().getIdSnapshot();
// this may happen in uncommitted objects - see the warning in the JavaDoc of
// this method.
if (idParts.isEmpty()) {
continue;
}
DbRelationship dbRel = (DbRelationship) rel.getDbRelationships().get(0);
Map fk = dbRel.srcFkSnapshotWithTargetSnapshot(idParts);
snapshot.putAll(fk);
}
// process object id map