Anil Gangolli wrote:

Mitesh. Sorry I was not clear. I meant that we should be removing the queue entries. That function should ideally be performed by calling the PinqQueueManager and implementing the removal there in a new method to remove all queue entries by website. That method could be implemented with a bulk delete.

If that's too much of a detour, you could defer that and just fix it locally by adding the individual remove call in the code you showed.
I want the code in Datamapper*ManagerImpl to be as similar as possible to Hibernate*MangerImpl for the first pass. So, I will go with the current code pattern for now (deleting using individual remove call). I have a note in the code to start using bulk deletes from respective managers when this code stabilizes.

Thanks,
Mitesh

--a



----- Original Message ----- From: "Mitesh Meswani" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Thursday, October 05, 2006 9:32 AM
Subject: Re: Question about code in HibernateUserManagerImpl




Anil Gangolli wrote:
Inline.  Maybe Allen can comment too?

----- Original Message ----- From: "Mitesh Meswani" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Wednesday, October 04, 2006 2:48 PM
Subject: Question about code in HibernateUserManagerImpl


Hi,

I am working (along with Craig) on developing a persistence layer
abstraction for roller. While converting the code, I had following
questions about code in HibernateUserManagerImpl#removeWebsiteContents()

1. The list queueEntries is retrieved but not used.
   I think the intention would have been to remove the queueEntries
   from database is that correct?

Yes; it seems incomplete.

Removing the website's custom ping target will remove the associated queue entries, but you can have queue entries from common ping targets as well, so
this is probably good to do.
If it is ok to not delete queue entries here we should either the unnecessary database access to fetch queueEntries. I will remove the entries in DatamapperUserManagerImpl.

2. All the removals below (For example removing of auto ping
    configurations) can be replaced by bulk deletes.
That is deleting directly from database instead of getting them into
   memory and than deleting.I saw
           HibernateRefererManagerImpl#clearReferrers using the "bulk
   delete" pattern. Is there any reason
  (apart from historic code) why "bulk delete" is not used here ?


I think you just have to be careful that the object's manager doesn't itself
have some cascading delete logic that expects to be called whenever an
object it manages is removed.

It seems to me that the current pattern for handling cascading deletion in the managers seems to expect this; that is, the bulk deletion shortcut can only be used (safely) if it is in the manager that manages that object type directly.
Good point. I think than it makes sense to use current pattern.

Thanks,
Mitesh

--a.


Thanks,
Mitesh


<code_Of_the_method_for_quick_referece>

   private void removeWebsiteContents(WebsiteData website)
   throws HibernateException, RollerException {

       Session session = this.strategy.getSession();

       BookmarkManager bmgr =
RollerFactory.getRoller().getBookmarkManager();
WeblogManager wmgr = RollerFactory.getRoller().getWeblogManager();

       // Remove the website's ping queue entries
       Criteria criteria =
session.createCriteria(PingQueueEntryData.class);
       criteria.add(Expression.eq("website", website));
       List queueEntries = criteria.list();  *<--------1*

       // Remove the website's auto ping configurations   *<------ 2.*
       AutoPingManager autoPingMgr =
RollerFactory.getRoller().getAutopingManager();
       List autopings = autoPingMgr.getAutoPingsByWebsite(website);
       Iterator it = autopings.iterator();
       while(it.hasNext()) {
           this.strategy.remove((AutoPingData) it.next());
       }

       // Remove the website's custom ping targets
       PingTargetManager pingTargetMgr =
RollerFactory.getRoller().getPingTargetManager();
       List pingtargets = pingTargetMgr.getCustomPingTargets(website);
       it = pingtargets.iterator();
       while(it.hasNext()) {
           this.strategy.remove((PingTargetData) it.next());
       }

       // remove entries
       Criteria entryQuery =
session.createCriteria(WeblogEntryData.class);
       entryQuery.add(Expression.eq("website", website));
       List entries = entryQuery.list();
       for (Iterator iter = entries.iterator(); iter.hasNext();) {
           WeblogEntryData entry = (WeblogEntryData) iter.next();

           this.strategy.remove(entry);
       }

       // remove associated referers
Criteria refererQuery = session.createCriteria(RefererData.class);
       refererQuery.add(Expression.eq("website", website));
       List referers = refererQuery.list();
       for (Iterator iter = referers.iterator(); iter.hasNext();) {
           RefererData referer = (RefererData) iter.next();
           this.strategy.remove(referer);
       }


       // remove associated pages
Criteria pageQuery = session.createCriteria(WeblogTemplate.class);
       pageQuery.add(Expression.eq("website", website));
       List pages = pageQuery.list();
       for (Iterator iter = pages.iterator(); iter.hasNext();) {
           WeblogTemplate page = (WeblogTemplate) iter.next();
           this.strategy.remove(page);
       }

       // remove folders (including bookmarks)
       FolderData rootFolder = bmgr.getRootFolder(website);
       if (null != rootFolder) {
           this.strategy.remove(rootFolder);

           // Still cannot get all Bookmarks cleared!
Iterator allFolders = bmgr.getAllFolders(website).iterator();
           while (allFolders.hasNext()) {
               FolderData aFolder = (FolderData)allFolders.next();
               bmgr.removeFolderContents(aFolder);
               this.strategy.remove(aFolder);
           }
       }

       // remove categories
WeblogCategoryData rootCat = wmgr.getRootWeblogCategory(website);
       if (null != rootCat) {
           this.strategy.remove(rootCat);
       }

   }


</code_Of_the_method_for_quick_referece>




Reply via email to