cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r572251 - in /cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src: main/java/org/apache/cayenne/map/ObjRelationship.java test/java/org/apache/cayenne/map/ObjRelationshipTest.java
Date Mon, 03 Sep 2007 08:33:39 GMT
Author: aadamchik
Date: Mon Sep  3 01:33:37 2007
New Revision: 572251

URL: http://svn.apache.org/viewvc?rev=572251&view=rev
Log:
CAY-861 ObjRelationship 'addDbRelationship()' and 'removeDbRelationship' leave object in an
inconsistent state

Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/ObjRelationship.java
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/map/ObjRelationshipTest.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/ObjRelationship.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/ObjRelationship.java?rev=572251&r1=572250&r2=572251&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/ObjRelationship.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/ObjRelationship.java
Mon Sep  3 01:33:37 2007
@@ -234,10 +234,16 @@
         return Collections.unmodifiableList(dbRelationships);
     }
 
-    /** Appends a DbRelationship to the existing list of DbRelationships. */
+    /**
+     * Appends a DbRelationship to the existing list of DbRelationships.
+     */
     public void addDbRelationship(DbRelationship dbRel) {
         refreshFromPath(true);
 
+        if (dbRel.getName() == null) {
+            throw new IllegalArgumentException("DbRelationship has no name");
+        }
+
         // Adding a second is creating a flattened relationship.
         // Ensure that the new relationship properly continues
         // on the flattened path
@@ -265,6 +271,13 @@
 
         dbRelationships.add(dbRel);
 
+        if (dbRelationshipPath == null) {
+            dbRelationshipPath = dbRel.getName();
+        }
+        else {
+            dbRelationshipPath += '.' + dbRel.getName();
+        }
+
         this.calculateReadOnlyValue();
         this.calculateToManyValue();
     }
@@ -275,15 +288,36 @@
     public void removeDbRelationship(DbRelationship dbRel) {
         refreshFromPath(true);
 
-        dbRelationships.remove(dbRel);
-        // Do not listen any more
-        EventManager.getDefaultManager().removeListener(
-                this,
-                DbRelationship.PROPERTY_DID_CHANGE,
-                dbRel);
+        if (dbRelationships.remove(dbRel)) {
 
-        this.calculateReadOnlyValue();
-        this.calculateToManyValue();
+            if (dbRelationships.isEmpty()) {
+                dbRelationshipPath = null;
+            }
+            else {
+                StringBuffer path = new StringBuffer();
+
+                for (int i = 0; i < dbRelationships.size(); i++) {
+                    DbRelationship r = (DbRelationship) dbRelationships.get(i);
+                    if (i > 0) {
+                        path.append('.');
+                    }
+
+                    path.append(r.getName());
+                }
+
+                dbRelationshipPath = path.toString();
+            }
+
+            // Do not listen any more
+            EventManager.getDefaultManager().removeListener(
+                    this,
+                    DbRelationship.PROPERTY_DID_CHANGE,
+                    dbRel);
+
+            this.calculateReadOnlyValue();
+            this.calculateToManyValue();
+
+        }
     }
 
     public void clearDbRelationships() {

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/map/ObjRelationshipTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/map/ObjRelationshipTest.java?rev=572251&r1=572250&r2=572251&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/map/ObjRelationshipTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/map/ObjRelationshipTest.java
Mon Sep  3 01:33:37 2007
@@ -330,7 +330,7 @@
 
     public void testSingleDbRelationship() {
         ObjRelationship relationship = new ObjRelationship();
-        DbRelationship r1 = new DbRelationship();
+        DbRelationship r1 = new DbRelationship("X");
         relationship.addDbRelationship(r1);
         assertEquals(1, relationship.getDbRelationships().size());
         assertEquals(r1, relationship.getDbRelationships().get(0));
@@ -342,8 +342,8 @@
     }
 
     public void testFlattenedRelationship() {
-        DbRelationship r1 = new DbRelationship();
-        DbRelationship r2 = new DbRelationship();
+        DbRelationship r1 = new DbRelationship("X");
+        DbRelationship r2 = new DbRelationship("Y");
 
         r1.setSourceEntity(artistDBEntity);
         r1.setTargetEntity(artistExhibitDBEntity);
@@ -375,9 +375,9 @@
     public void testReadOnlyMoreThan3DbRelsRelationship() {
         // Readonly is a flattened relationship that isn't over a single many->many link
         // table
-        DbRelationship r1 = new DbRelationship();
-        DbRelationship r2 = new DbRelationship();
-        DbRelationship r3 = new DbRelationship();
+        DbRelationship r1 = new DbRelationship("X");
+        DbRelationship r2 = new DbRelationship("Y");
+        DbRelationship r3 = new DbRelationship("Z");
 
         r1.setSourceEntity(artistDBEntity);
         r1.setTargetEntity(artistExhibitDBEntity);
@@ -403,8 +403,8 @@
     // Test for a read-only flattened relationship that is readonly because it's dbrel
     // sequence is "incorrect" (or rather, unsupported)
     public void testIncorrectSequenceReadOnlyRelationship() {
-        DbRelationship r1 = new DbRelationship();
-        DbRelationship r2 = new DbRelationship();
+        DbRelationship r1 = new DbRelationship("X");
+        DbRelationship r2 = new DbRelationship("Y");
 
         r1.setSourceEntity(artistDBEntity);
         r1.setTargetEntity(paintingDbEntity);
@@ -459,7 +459,7 @@
 
     public void testWatchesDbRelChanges() {
         ObjRelationship relationship = new ObjRelationship();
-        DbRelationship r1 = new DbRelationship();
+        DbRelationship r1 = new DbRelationship("X");
         r1.setToMany(true);
         relationship.addDbRelationship(r1);
         assertTrue(relationship.isToMany());



Mime
View raw message