You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by aa...@apache.org on 2007/09/17 14:09:18 UTC
svn commit: r576391 - in /cayenne/main/trunk:
docs/doc/src/main/resources/RELEASE-NOTES.txt
framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/DataRowUtils.java
Author: aadamchik
Date: Mon Sep 17 05:09:17 2007
New Revision: 576391
URL: http://svn.apache.org/viewvc?rev=576391&view=rev
Log:
CAY-863 Object property unexpectedly set to null through forceMergeWithSnapshot
Modified:
cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt
cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/DataRowUtils.java
Modified: cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt?rev=576391&r1=576390&r2=576391&view=diff
==============================================================================
--- cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt (original)
+++ cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt Mon Sep 17 05:09:17 2007
@@ -47,6 +47,7 @@
CAY-853 JPA EntityTransaction must allow multiple begin/commit cycles
CAY-854 the relationships to entities which are "not for client use" are being returned by ${objEntity.DeclaredRelationships} tag in superclass template
CAY-861 ObjRelationship 'addDbRelationship()' and 'removeDbRelationship' leave object in an inconsistent state
+CAY-863 Object property unexpectedly set to null through forceMergeWithSnapshot
----------------------------------
Release: 3.0M1
Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/DataRowUtils.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/DataRowUtils.java?rev=576391&r1=576390&r2=576391&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/DataRowUtils.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/DataRowUtils.java Mon Sep 17 05:09:17 2007
@@ -19,10 +19,14 @@
package org.apache.cayenne.access;
+import java.util.Iterator;
+import java.util.Map;
+
import org.apache.cayenne.DataRow;
import org.apache.cayenne.ObjectId;
import org.apache.cayenne.PersistenceState;
import org.apache.cayenne.Persistent;
+import org.apache.cayenne.map.DbJoin;
import org.apache.cayenne.map.DbRelationship;
import org.apache.cayenne.map.ObjAttribute;
import org.apache.cayenne.map.ObjEntity;
@@ -177,29 +181,35 @@
.getDbRelationships()
.get(0);
- ObjectId id = snapshot.createTargetObjectId(relationship
- .getTargetEntityName(), dbRelationship);
-
- if (diff == null
- || !diff.containsArcSnapshot(relationship.getName())
- || !Util.nullSafeEquals(id, diff
- .getArcSnapshotValue(relationship.getName()))) {
+ // must check before creating ObjectId because of partial
+ // snapshots
+ if (hasFK(dbRelationship, snapshot)) {
+ ObjectId id = snapshot.createTargetObjectId(relationship
+ .getTargetEntityName(), dbRelationship);
+
+ if (diff == null
+ || !diff.containsArcSnapshot(relationship.getName())
+ || !Util.nullSafeEquals(id, diff
+ .getArcSnapshotValue(relationship.getName()))) {
- if (id == null) {
- property.writeProperty(object, null, null);
- }
- else {
- // if inheritance is involved, we can't use 'localObject'
- // .. must turn to fault instead
- ObjEntity targetEntity = (ObjEntity) relationship
- .getTargetEntity();
- if (context.getEntityResolver().lookupInheritanceTree(
- targetEntity) != null) {
- property.invalidate(object);
+ if (id == null) {
+ property.writeProperty(object, null, null);
}
else {
- property.writeProperty(object, null, context
- .localObject(id, null));
+ // if inheritance is involved, we can't use
+ // 'localObject'
+ // .. must turn to fault instead
+ ObjEntity targetEntity = (ObjEntity) relationship
+ .getTargetEntity();
+ if (context
+ .getEntityResolver()
+ .lookupInheritanceTree(targetEntity) != null) {
+ property.invalidate(object);
+ }
+ else {
+ property.writeProperty(object, null, context
+ .localObject(id, null));
+ }
}
}
}
@@ -208,6 +218,18 @@
return true;
}
});
+ }
+
+ static boolean hasFK(DbRelationship relationship, Map snapshot) {
+ Iterator joins = relationship.getJoins().iterator();
+ while (joins.hasNext()) {
+ DbJoin join = (DbJoin) joins.next();
+ if (!snapshot.containsKey(join.getSourceName())) {
+ return false;
+ }
+ }
+
+ return true;
}
/**