&& object.getDataContext() != null) {
return getObjectStore().getSnapshot(object.getObjectId());
}
DataRow snapshot = new DataRow(10);
Iterator attributes = entity.getAttributeMap().entrySet().iterator();
while (attributes.hasNext()) {
Map.Entry entry = (Map.Entry) attributes.next();
String attrName = (String) entry.getKey();
ObjAttribute objAttr = (ObjAttribute) entry.getValue();
// processing compound attributes correctly
snapshot.put(objAttr.getDbAttributePath(), object
.readPropertyDirectly(attrName));
}
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;
}