Hi,

I am working to port Roller's backend code to use JPA/JDO (see trunk/sandbox/jdobackend). I ran across some code that is not portable across persistence strategies. Attached is a patch to fix that. The patch is from trunk dir based on revision 491960

Following is a summary of changes:
1. src/org/apache/roller/pojos/FolderData.java, src/org/apache/roller/pojos/WeblogCategoryData.java: JPA assumes that relationships are managed by user code and not persistence provider. If we have a one-to-many relationship, if the "many side" is set to point to an instance, the "one side" also needs to add it the collection. For example if we set a FolderData's "parent", the parent should add it to its "childFolders" collection. FolderData and WeblogCategoryData is modified to follow this convention.

2. tests/org/apache/roller/business/PingsTest.java
The test calls AutpoingManager#removeAutoPings(Collection) passing it a collection of unmanged instances. It is modified to remove manged version instead. I have verified that when AutpoingManager#removeAutoPings is called from roller code(PingSetupAction#disableSelected()), the instances are managed

I have successfully run all tests against hibernate-derby with these changes. Please review and check in.

Thanks,
Mitesh




Index: src/org/apache/roller/pojos/FolderData.java
===================================================================
--- src/org/apache/roller/pojos/FolderData.java (revision 491943)
+++ src/org/apache/roller/pojos/FolderData.java (working copy)
@@ -84,6 +84,15 @@
         } else {
             this.path = parent.getPath() + "/" + name;
         }
+
+        this.parentFolder = parent;
+        // Relationship needs to be maintained from both sides
+        if(parent != null) {
+            // Following triggers this.hascode(). Which is calculated based on 
this.path
+            // It needs to happen after this.path is initialized
+            parent.childFolders.add(this);
+        }
+
     }
     
     
Index: src/org/apache/roller/pojos/WeblogCategoryData.java
===================================================================
--- src/org/apache/roller/pojos/WeblogCategoryData.java (revision 491943)
+++ src/org/apache/roller/pojos/WeblogCategoryData.java (working copy)
@@ -71,8 +71,7 @@
         this.image = image;
         
         this.website = website;
-        this.parentCategory = parent;
-        
+
         // calculate path
         if(parent == null) {
             this.path = "/";
@@ -81,6 +80,15 @@
         } else {
             this.path = parent.getPath() + "/" + name;
         }
+
+        this.parentCategory = parent;
+        // Relationship needs to be maintained from both sides
+        if(parent != null) {
+            // Following triggers this.hascode(). Which is calculated based on 
this.path
+            // It needs to happen after this.path is initialized
+            parent.childCategories.add(this);
+        }
+
     }
     
     
Index: tests/org/apache/roller/business/PingsTest.java
===================================================================
--- tests/org/apache/roller/business/PingsTest.java     (revision 491943)
+++ tests/org/apache/roller/business/PingsTest.java     (working copy)
@@ -314,7 +314,9 @@
         
         // remove a collection
         List autoPings = new ArrayList();
+        autoPing2 = mgr.getAutoPing(autoPing2.getId()); //Get managed version 
of autoPing2
         autoPings.add(autoPing2);
+        autoPing3 = mgr.getAutoPing(autoPing3.getId()); //Get managed version 
of autoPing2
         autoPings.add(autoPing3);
         mgr.removeAutoPings(autoPings);
         TestUtils.endSession(true);

Reply via email to