roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From c..@apache.org
Subject svn commit: r494696 - in /incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller: business/datamapper/ pojos/
Date Wed, 10 Jan 2007 03:24:50 GMT
Author: clr
Date: Tue Jan  9 19:24:50 2007
New Revision: 494696

URL: http://svn.apache.org/viewvc?view=rev&rev=494696
Log:
Datamapper updates for managed relationships

Modified:
    incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/business/datamapper/DatamapperBookmarkManagerImpl.java
    incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/business/datamapper/DatamapperUserManagerImpl.java
    incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/business/datamapper/DatamapperWeblogManagerImpl.java
    incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/pojos/UserData.orm.xml
    incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/pojos/WebsiteData.orm.xml

Modified: incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/business/datamapper/DatamapperBookmarkManagerImpl.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/business/datamapper/DatamapperBookmarkManagerImpl.java?view=diff&rev=494696&r1=494695&r2=494696
==============================================================================
--- incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/business/datamapper/DatamapperBookmarkManagerImpl.java
(original)
+++ incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/business/datamapper/DatamapperBookmarkManagerImpl.java
Tue Jan  9 19:24:50 2007
@@ -65,8 +65,14 @@
     }
 
     public void saveBookmark(BookmarkData bookmark) throws RollerException {
+        if(!PersistentObjectHelper.isObjectPersistent(bookmark)) {
+            // This is a new object make sure that relationship is set on managed
+            // copy of other side
+            bookmark.getFolder().getBookmarks().add(bookmark);
+        }
+
         this.strategy.store(bookmark);
-        
+
         // update weblog last modified date (date is updated by saveWebsite())
         RollerFactory.getRoller().getUserManager().
             saveWebsite(bookmark.getWebsite());
@@ -92,6 +98,15 @@
             throw new RollerException("Duplicate folder name");
         }
 
+        if(!PersistentObjectHelper.isObjectPersistent(folder)) {
+            // Newly added object. If it has a parent,
+            // maintain relationship from both sides
+            FolderData parent = folder.getParent();
+            if(parent != null) {
+                parent.getFolders().add(folder);
+            }
+        }
+
         this.strategy.store(folder);
 
         // update weblog last modified date.  date updated by saveWebsite()
@@ -123,7 +138,14 @@
         log.debug("Moving folder " + srcFolder.getPath() + " under " +
             destFolder.getPath());
         
+        // Manage relationships
+        FolderData oldParent = srcFolder.getParent();
+        if(oldParent != null) {
+            oldParent.getFolders().add(srcFolder);
+        }
         srcFolder.setParent(destFolder);
+        destFolder.getFolders().add(srcFolder);
+        
         if("/".equals(destFolder.getPath())) {
             srcFolder.setPath("/"+srcFolder.getName());
         } else {

Modified: incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/business/datamapper/DatamapperUserManagerImpl.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/business/datamapper/DatamapperUserManagerImpl.java?view=diff&rev=494696&r1=494695&r2=494696
==============================================================================
--- incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/business/datamapper/DatamapperUserManagerImpl.java
(original)
+++ incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/business/datamapper/DatamapperUserManagerImpl.java
Tue Jan  9 19:24:50 2007
@@ -46,6 +46,7 @@
 import org.apache.roller.pojos.WeblogEntryTagData;
 import org.apache.roller.pojos.WeblogEntryTagAggregateData;
 import org.apache.roller.pojos.RoleData;
+import org.apache.roller.pojos.PersistentObject;
 
 import java.util.ArrayList;
 import java.util.Collections;
@@ -206,7 +207,21 @@
         WeblogCategoryData rootCat = wmgr.getRootWeblogCategory(website);
         if (null != rootCat) {
             this.strategy.remove(rootCat);
-    }
+        }
+
+        //remove permissions
+        //TODO: Datamapper: this is a workaround for toplink bug that requires
+        //to clean up from non owning side for removed objects.
+        for (Iterator iterator = website.getPermissions().iterator(); iterator.hasNext();)
{
+            PermissionsData perms = (PermissionsData) iterator.next();
+            //Remove it from database
+            this.strategy.remove(perms);
+            //Remove it from website
+            iterator.remove();
+            //Remove it from corresponding user
+            UserData user = (UserData) getManagedObject(perms.getUser());
+            user.getPermissions().remove(perms);
+        }
 
         // flush the changes before returning. This is required as there is a
         // circular dependency between WeblogCategoryData and WebsiteData
@@ -221,6 +236,20 @@
     }
 
     public void removeUser(UserData user) throws RollerException {
+        //remove permissions
+        //TODO: Datamapper: this is a workaround for toplink bug that requires
+        //to clean up from non owning side for removed objects.
+        for (Iterator iterator = user.getPermissions().iterator(); iterator.hasNext();) {
+                PermissionsData perms = (PermissionsData) iterator.next();
+                //Remove it from database
+                this.strategy.remove(perms);
+                //Remove it from website
+                iterator.remove();
+                //Remove it from corresponding user
+                WebsiteData website = (WebsiteData) getManagedObject(perms.getWebsite());
+                website.getPermissions().remove(perms);
+        }
+
         this.strategy.remove(user);
 
         // remove entry from cache mapping
@@ -229,12 +258,28 @@
 
     public void savePermissions(PermissionsData perms) 
             throws RollerException {
+        if(!PersistentObjectHelper.isObjectPersistent(perms)) {
+            // This is a new object make sure that relationship is set on managed
+            // copy of other side
+            WebsiteData website = (WebsiteData) getManagedObject(perms.getWebsite());
+            website.getPermissions().add(perms);
+
+            UserData user = (UserData) getManagedObject(perms.getUser());
+            user.getPermissions().add(perms);
+        }
         this.strategy.store(perms);
     }
 
     public void removePermissions(PermissionsData perms) 
             throws RollerException {
         this.strategy.remove(perms);
+        // make sure that relationship is set on managed
+        // copy of other side
+        WebsiteData website = (WebsiteData) getManagedObject(perms.getWebsite());
+        website.getPermissions().remove(perms);
+
+        UserData user = (UserData) getManagedObject(perms.getUser());
+        user.getPermissions().remove(perms);
     }
 
     /**
@@ -293,7 +338,7 @@
         perms.setWebsite(newWeblog);
         perms.setPending(false);
         perms.setPermissionMask(PermissionsData.ADMIN);
-        this.strategy.store(perms);
+        savePermissions(perms);
 
         // add default category
         WeblogCategoryData rootCat = new WeblogCategoryData(
@@ -319,7 +364,7 @@
                 this.strategy.store(c);
             }
         }
-        
+
         // Use first category as default for Blogger API
         newWeblog.setBloggerCategory(firstCat);
 
@@ -387,7 +432,7 @@
         perms.setWebsite(website);
         perms.setUser(user);
         perms.setPermissionMask(mask);
-        this.strategy.store(perms);
+        savePermissions(perms);
 
         return perms;
     }
@@ -464,20 +509,9 @@
             }
         }
 
-        // cache failed, do lookup
-        DatamapperQuery query;
-        Object[] params;
-        if (enabled != null) {
-            query = strategy.newQuery(WebsiteData.class,
-                "WebsiteData.getByHandle&enabled");
-            params = new Object[] {handle, enabled};
-        } else {
-            query = strategy.newQuery(WebsiteData.class,
-                "WebsiteData.getByHandle");
-            params = new Object[] {handle};
-        }
+        DatamapperQuery query = strategy.newQuery(WebsiteData.class, "WebsiteData.getByHandle");
         query.setUnique();
-        WebsiteData website = (WebsiteData) query.execute(params);
+        WebsiteData website = (WebsiteData) query.execute(handle);
 
         // add mapping to cache
         if(website != null) {
@@ -485,7 +519,12 @@
             this.weblogHandleToIdMap.put(website.getHandle(), website.getId());
         }
 
-        return website;
+        if(website != null &&
+                (enabled == null || enabled.equals(website.getEnabled()))) {
+            return website;
+        } else {
+            return null;
+        }
     }
 
     /**
@@ -1101,6 +1140,21 @@
 
         return ret;
     }
-    
+
+    /**
+     * Returns a manged copy of given persistent object.
+     * @param obj Given persistent object
+     * @return Managed version of obj
+     * @throws RollerException
+     * The method is required to handle case when a newly created object is made
+     * to refer to a object stored in web session. The object stored in web session
+     * should be merged into current persistence context before it is being
+     * referred by any other object.
+     * It should be our goal to not require this method. All the caller of this
+     * method should be modfied to see make sure that the obj passed managed
+     */
+    private PersistentObject getManagedObject(PersistentObject obj) throws RollerException
{
+        return (PersistentObject) strategy.load(obj.getClass(), obj.getId());
+    }
     
 }

Modified: incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/business/datamapper/DatamapperWeblogManagerImpl.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/business/datamapper/DatamapperWeblogManagerImpl.java?view=diff&rev=494696&r1=494695&r2=494696
==============================================================================
--- incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/business/datamapper/DatamapperWeblogManagerImpl.java
(original)
+++ incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/business/datamapper/DatamapperWeblogManagerImpl.java
Tue Jan  9 19:24:50 2007
@@ -87,6 +87,15 @@
         if(cat.getId() == null && this.isDuplicateWeblogCategoryName(cat)) {
             throw new RollerException("Duplicate category name, cannot save category");
         }
+
+        if(!PersistentObjectHelper.isObjectPersistent(cat)) {
+            // Newly added object. If it has a parent,
+            // maintain relationship from both sides
+            WeblogCategoryData parent = cat.getParent();
+            if(parent != null) {
+                parent.getWeblogCategories().add(cat);
+            }
+        }
         
         // update weblog last modified date.  date updated by saveWebsite()
         RollerFactory.getRoller().getUserManager().saveWebsite(cat.getWebsite());
@@ -143,8 +152,15 @@
         
         log.debug("Moving category "+srcCat.getPath() +
             " under "+destCat.getPath());
-        
+
+
+        WeblogCategoryData oldParent = srcCat.getParent();
+        if(oldParent != null) {
+            oldParent.getWeblogCategories().remove(srcCat);
+        }
         srcCat.setParent(destCat);
+        destCat.getWeblogCategories().add(srcCat);
+
         if("/".equals(destCat.getPath())) {
             srcCat.setPath("/"+srcCat.getName());
         } else {
@@ -156,8 +172,8 @@
         // path attribute of the category and all descendent categories
         updatePathTree(srcCat);
     }
-    
-    
+
+
     // updates the paths of all descendents of the given category
     private void updatePathTree(WeblogCategoryData cat) 
             throws RollerException {

Modified: incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/pojos/UserData.orm.xml
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/pojos/UserData.orm.xml?view=diff&rev=494696&r1=494695&r2=494696
==============================================================================
--- incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/pojos/UserData.orm.xml
(original)
+++ incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/pojos/UserData.orm.xml
Tue Jan  9 19:24:50 2007
@@ -103,9 +103,6 @@
                 <column name="timeZone" insertable="true" updatable="true" unique="false"/>
             </basic>
             <one-to-many name="permissions" mapped-by="user" target-entity="org.apache.roller.pojos.PermissionsData"
fetch="LAZY">
-                <cascade>
-                    <cascade-remove/>
-                </cascade>
             </one-to-many>
             <one-to-many name="roles" mapped-by="user" target-entity="org.apache.roller.pojos.RoleData"
fetch="LAZY">
                 <cascade>

Modified: incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/pojos/WebsiteData.orm.xml
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/pojos/WebsiteData.orm.xml?view=diff&rev=494696&r1=494695&r2=494696
==============================================================================
--- incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/pojos/WebsiteData.orm.xml
(original)
+++ incubator/roller/trunk/sandbox/jdobackend/src/org/apache/roller/pojos/WebsiteData.orm.xml
Tue Jan  9 19:24:50 2007
@@ -11,9 +11,6 @@
 	<package>org.apache.roller.pojos</package>
 	<entity metadata-complete="true" name="WebsiteData" class="org.apache.roller.pojos.WebsiteData">
 		<table name="website"/>
-		<named-query name="WebsiteData.getByHandle&amp;enabled">
-			<query>SELECT w FROM WebsiteData w WHERE w.handle = ?1 AND w.enabled = ?2</query>
-		</named-query>
 		<named-query name="WebsiteData.getByHandle">
 			<query>SELECT w FROM WebsiteData w WHERE w.handle = ?1</query>
 		</named-query>
@@ -232,9 +229,6 @@
 				<join-column name="defaultcatid" insertable="true" updatable="true"/>
 			</many-to-one>
 			<one-to-many name="permissions" mapped-by="website" target-entity="org.apache.roller.pojos.PermissionsData"
fetch="LAZY">
-				<cascade>
-					<cascade-remove/>
-				</cascade>
 			</one-to-many>
 			<transient name="absoluteURL"/>
 			<transient name="adminUserCount"/>



Mime
View raw message