logo       

roller/src/org/roller/business BookmarkManagerImpl.java,1.3,1.4 package.htm: msg#00188

Subject: roller/src/org/roller/business BookmarkManagerImpl.java,1.3,1.4 package.html,1.1,1.2 UserManagerBase.java,1.13,1.14 RefererManagerBase.java,1.21,1.22 NewsfeedManagerBase.java,1.4,1.5 WeblogManagerBase.java,1.19,1.20 Queries.java,1.3,NONE
Update of /cvsroot/roller/roller/src/org/roller/business
In directory sc8-pr-cvs1:/tmp/cvs-serv7610/src/org/roller/business

Modified Files:
        BookmarkManagerImpl.java package.html UserManagerBase.java 
        RefererManagerBase.java NewsfeedManagerBase.java 
        WeblogManagerBase.java 
Removed Files:
        Queries.java 
Log Message:
Further refactoring of biz and persistence layers:
- moved all base managers over to Query API. 
- made begin, commit, and rollback behavior consistent.
- removed Hibernate and Castor specific methods.
- moved persistence package up to org.roller level.

Index: BookmarkManagerImpl.java
===================================================================
RCS file: 
/cvsroot/roller/roller/src/org/roller/business/BookmarkManagerImpl.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** BookmarkManagerImpl.java    27 Nov 2003 04:59:14 -0000      1.3
--- BookmarkManagerImpl.java    29 Nov 2003 19:11:18 -0000      1.4
***************
*** 7,14 ****
  import org.jdom.input.SAXBuilder;
  import org.roller.RollerException;
! import org.roller.business.persistence.Condition;
! import org.roller.business.persistence.PersistenceStrategy;
! import org.roller.business.persistence.Query;
! import org.roller.business.persistence.QueryFactory;
  import org.roller.model.BookmarkManager;
  import org.roller.model.UserManager;
--- 7,14 ----
  import org.jdom.input.SAXBuilder;
  import org.roller.RollerException;
! import org.roller.persistence.Condition;
! import org.roller.persistence.PersistenceStrategy;
! import org.roller.persistence.Query;
! import org.roller.persistence.QueryFactory;
  import org.roller.model.BookmarkManager;
  import org.roller.model.UserManager;
***************
*** 19,23 ****
  
  import java.io.StringReader;
- import java.util.ArrayList;
  import java.util.Iterator;
  import java.util.LinkedList;
--- 19,22 ----
***************
*** 45,51 ****
        //---------------------------------------------------------- Bookmark 
CRUD
  
!     public BookmarkData createBookmark() throws RollerException
      {
!        BookmarkData bd = new BookmarkData(this);
         return bd;
      }
--- 44,65 ----
        //---------------------------------------------------------- Bookmark 
CRUD
  
!     public BookmarkData createBookmark()
      {
!        BookmarkData bd = new BookmarkData();
!        return bd;
!     }
! 
!     public BookmarkData createBookmark(
!         FolderData parent, 
!         String name, 
!         String desc, 
!         String url, 
!         String feedUrl,
!         Integer weight, 
!         Integer priority, 
!         String image)
!     {
!        BookmarkData bd = new BookmarkData(
!            parent, name, desc, url, feedUrl, weight, priority, image);
         return bd;
      }
***************
*** 74,78 ****
       * @see org.roller.model.BookmarkManager#createFolder()
       */
!     public FolderData createFolder() throws RollerException
      {
         FolderData fd = new FolderData();
--- 88,92 ----
       * @see org.roller.model.BookmarkManager#createFolder()
       */
!     public FolderData createFolder()
      {
         FolderData fd = new FolderData();
***************
*** 80,83 ****
--- 94,110 ----
      }
  
+     /** 
+      * @see org.roller.model.BookmarkManager#createFolder()
+      */
+     public FolderData createFolder(
+         FolderData parent,
+         String name, 
+         String desc, 
+         WebsiteData website)
+     {
+        FolderData fd = new FolderData(parent, name, desc, website);
+        return fd;
+     }
+ 
        /** 
       * Retrieve folder and lazy-load it's sub-folders and bookmarks. 
***************
*** 118,125 ****
              if (newFolder == null) 
              {
!                 newFolder = createFolder();
!                 newFolder.setName(folderName);
!                 newFolder.setDescription(folderName);
!                 newFolder.setWebsite(website);
                  storeFolder(newFolder);
              }
--- 145,149 ----
              if (newFolder == null) 
              {
!                 newFolder = createFolder(null, folderName, folderName, 
website);
                  storeFolder(newFolder);
              }
***************
*** 161,172 ****
          {
              // Store a bookmark
!             BookmarkData bd = createBookmark();
!             bd.setName(null!=title ? title : desc);
!             bd.setDescription(null!=desc ? desc : title);
!             bd.setUrl(null!=htmlUrl ? htmlUrl : url);
!             bd.setPriority(new Integer(0));
!             bd.setWeight(new Integer(100));
!             bd.setFolder(parent);
!             bd.setFeedUrl(null!=xmlUrl ? xmlUrl : url);
              
              parent.addBookmark(bd);
--- 185,197 ----
          {
              // Store a bookmark
!             BookmarkData bd = createBookmark(
!                 parent,
!                 null!=title ? title : desc,
!                 null!=desc ? desc : title,
!                 null!=htmlUrl ? htmlUrl : url,
!                 null!=xmlUrl ? xmlUrl : url,
!                 new Integer(0),
!                 new Integer(100),
!                 null);
              
              parent.addBookmark(bd);
***************
*** 175,183 ****
          {
              // Store a folder            
!             FolderData fd = createFolder();
!             fd.setName(title);
!             fd.setDescription(desc);
!             fd.setParent(parent);
!             fd.setWebsite(parent.getWebsite());
              parent.addFolder(fd);
              
--- 200,205 ----
          {
              // Store a folder            
!             FolderData fd = 
!                 createFolder(parent, title, desc, parent.getWebsite());
              parent.addFolder(fd);
              
***************
*** 203,207 ****
              deleteList.add(bd);
  
!             BookmarkData movedBd = createBookmark();
              movedBd.setData(bd);
              movedBd.setId(null);
--- 225,229 ----
              deleteList.add(bd);
  
!             BookmarkData movedBd = new BookmarkData();
              movedBd.setData(bd);
              movedBd.setId(null);

Index: package.html
===================================================================
RCS file: /cvsroot/roller/roller/src/org/roller/business/package.html,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** package.html        2 Mar 2003 06:02:45 -0000       1.1
--- package.html        29 Nov 2003 19:11:18 -0000      1.2
***************
*** 5,15 ****
  </head>
  <body>
! 
! Base and common classes that may be used in any implementation of the
! Roller Business Tier interfaces.
! 
! Currently, there is only one implementation of the Roller Business Tier
! interfaces and it uses the Castor Object-Relational mapping framework.
! 
  </body>
  </html>
--- 5,11 ----
  </head>
  <body>
! Base implementation of the Roller business layer interfaces using the Roller 
! Persistence and Query API. Hibernatre and Castor implementations use as-is or 
! extend as-needed the classes in this package.
  </body>
  </html>

Index: UserManagerBase.java
===================================================================
RCS file: /cvsroot/roller/roller/src/org/roller/business/UserManagerBase.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** UserManagerBase.java        18 Nov 2003 04:20:53 -0000      1.13
--- UserManagerBase.java        29 Nov 2003 19:11:18 -0000      1.14
***************
*** 4,14 ****
  package org.roller.business;
  
- import net.sf.hibernate.Hibernate;
- import net.sf.hibernate.type.Type;
- 
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.roller.RollerException;
! import org.roller.business.persistence.PersistenceStrategy;
  import org.roller.model.BookmarkManager;
  import org.roller.model.NewsfeedManager;
--- 4,14 ----
  package org.roller.business;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.roller.RollerException;
! import org.roller.persistence.Condition;
! import org.roller.persistence.PersistenceStrategy;
! import org.roller.persistence.Query;
! import org.roller.persistence.QueryFactory;
  import org.roller.model.BookmarkManager;
  import org.roller.model.NewsfeedManager;
***************
*** 28,41 ****
  import org.roller.util.Utilities;
  
- import java.sql.Timestamp;
  import java.util.Date;
  import java.util.HashMap;
  import java.util.Iterator;
  import java.util.List;
  
  /**
   * @author llavandowska
   */
! public abstract class UserManagerBase implements UserManager
  {
      private static Log mLogger =
--- 28,44 ----
  import org.roller.util.Utilities;
  
  import java.util.Date;
  import java.util.HashMap;
  import java.util.Iterator;
+ import java.util.LinkedList;
  import java.util.List;
+ import java.util.Map;
  
  /**
+  * Implementation of UserManager using PersistenceStrategy and Query API.
+  * @author Dave Johnson
   * @author llavandowska
   */
! public class UserManagerBase implements UserManager
  {
      private static Log mLogger =
***************
*** 45,50 ****
      protected Roller mRoller;
      
!     public UserManagerBase(Roller roller)
      {
          mRoller = roller;
      }
--- 48,54 ----
      protected Roller mRoller;
      
!     public UserManagerBase(PersistenceStrategy strategy, Roller roller)
      {
+         mStrategy = strategy;
          mRoller = roller;
      }
***************
*** 81,107 ****
  
      // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
!     public WebsiteData getWebsite(String userName, boolean enabledOnly) 
throws RollerException
      {
!         StringBuffer query = new StringBuffer( Queries.WEBSITE_BY_USER );
!         Object[] args = {userName};
!         Type[] types = { Hibernate.STRING };
          if (enabledOnly) 
          {
!             query.append( Queries.RELATIONSHIP_USER_ENABLED_RESTRICTION );
!             args = new Object[]{userName, Boolean.TRUE};
!             types = new Type[]{ Hibernate.STRING, Hibernate.BOOLEAN };
!         }
!         try
!         {
!             //if (getUser(userName, false) == null) return null;
!             
!             List list = mStrategy.query(query.toString(), args, types);
!             return list.size()>0 ? (WebsiteData)list.get(0) : null;
!         }
!         catch (Exception e)
!         {
!             mLogger.error("Error fetching Website for " + userName);
!             throw new RollerException(e);
          }
      }
  
--- 85,110 ----
  
      // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
!     public WebsiteData getWebsite(String userName, boolean enabledOnly) 
!         throws RollerException
      {
!         if (userName==null )
!             throw new RollerException("userName is null");
! 
!         QueryFactory factory = mStrategy.getQueryFactory();
!         Query query = factory.createQuery(WebsiteData.class.getName());       
 
!         
!         List conditions = new LinkedList();        
!         conditions.add(factory.createCondition(
!             "user.userName", Query.EQ, userName));       
          if (enabledOnly) 
          {
!             conditions.add(factory.createCondition(
!                 "user.userEnabled", Query.EQ, new Boolean(true)));
          }
+         
+         query.setWhere(factory.createCondition(Query.AND, conditions));
+         
+         List list = query.execute();
+         return list.size()>0 ? (WebsiteData)list.get(0) : null;
      }
  
***************
*** 133,150 ****
      public UserData getUser(String userName, boolean enabledOnly) throws 
RollerException
      {
!         if (userName == null)
!             return null;
  
!         Object[] args = { userName };
!         Type[] types = { Hibernate.STRING };
!         StringBuffer query = new StringBuffer( Queries.USER_BY_NAME );
!         if (enabledOnly)
          {
!             query.append(Queries.USER_ENABLED_RESTRICTION2);
!             args = new Object[]{userName, Boolean.TRUE};
!             types = new Type[]{ Hibernate.STRING, Hibernate.BOOLEAN };
!         } 
! 
!         List list = mStrategy.query(query.toString(), args, types);
          return list.size()>0 ? (UserData)list.get(0) : null;
      }
--- 136,156 ----
      public UserData getUser(String userName, boolean enabledOnly) throws 
RollerException
      {
!         if (userName==null )
!             throw new RollerException("userName is null");
  
!         QueryFactory factory = mStrategy.getQueryFactory();
!         Query query = factory.createQuery(UserData.class.getName());        
!         
!         List conditions = new LinkedList();        
!         conditions.add(factory.createCondition("userName", Query.EQ, 
userName));        
!         if (enabledOnly) 
          {
!             conditions.add(factory.createCondition(
!                 "userEnabled", Query.EQ, new Boolean(true)));
!         }
!         
!         query.setWhere(factory.createCondition(Query.AND, conditions));
!         
!         List list = query.execute();
          return list.size()>0 ? (UserData)list.get(0) : null;
      }
***************
*** 157,181 ****
  
      // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  
   
!     public UserData getUserById(String userId, boolean enabledOnly) throws 
RollerException
      {
  
!         Object[] args = { userId };
!         Type[] types = { Hibernate.STRING };
!         StringBuffer query = new StringBuffer(Queries.USER_BY_ID);
!         if (enabledOnly)
          {
!             query.append(Queries.USER_ENABLED_RESTRICTION2);
!             args = new Object[]{userId, Boolean.TRUE};
!             types = new Type[]{ Hibernate.STRING, Hibernate.BOOLEAN };
!         } 
          
!         List list = mStrategy.query(query.toString(), args, types);
!             
!         return list.size()!=0 ? (UserData)list.get(0) : null;
      }
  
      //-----------------------------------------------------------------------
  
!     public UserData[] getUsers() throws RollerException
      {
          return getUsers(true);
--- 163,192 ----
  
      // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  
   
!     public UserData getUserById(String userId, boolean enabledOnly) 
!         throws RollerException
      {
+         if (userId==null )
+             throw new RollerException("UserId is null");
  
!         QueryFactory factory = mStrategy.getQueryFactory();
!         Query query = factory.createQuery(UserData.class.getName());        
!         
!         List conditions = new LinkedList();        
!         conditions.add(factory.createCondition("id", Query.EQ, userId));      
  
!         if (enabledOnly) 
          {
!             conditions.add(factory.createCondition(
!                 "userEnabled", Query.EQ, new Boolean(true)));
!         }
          
!         query.setWhere(factory.createCondition(Query.AND, conditions));
!         
!         List list = query.execute();
!         return list.size()>0 ? (UserData)list.get(0) : null;
      }
  
      //-----------------------------------------------------------------------
  
!     public List getUsers() throws RollerException
      {
          return getUsers(true);
***************
*** 183,200 ****
  
      // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  
   
!     public UserData[] getUsers(boolean enabledOnly) throws RollerException
      {
!         Object[] args = {};
!         Type[] types = {};
!         StringBuffer query = new StringBuffer( Queries.SELECT_USER );
!         if (enabledOnly) 
          {
!             query.append(Queries.USER_ENABLED_RESTRICTION1);
!             args = new Object[]{Boolean.TRUE};
!             types = new Type[]{Hibernate.BOOLEAN};
!         }
  
!         List v = mStrategy.query(query.toString(), args, types);
!         return (UserData[]) v.toArray(new UserData[v.size()]);
      }
  
--- 194,229 ----
  
      // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  
   
!     public List getUsers(boolean enabledOnly) throws RollerException
      {
!         QueryFactory factory = mStrategy.getQueryFactory();
!         Query query = factory.createQuery(UserData.class.getName()); 
!         
!         if (enabledOnly)
          {
!             query.setWhere(factory.createCondition(
!                 "userEnabled", Query.EQ, new Boolean(true)));
!         } 
!                                
!         return query.execute();
!     }
  
!     
//------------------------------------------------------------------------    
!     /** 
!      * @see org.roller.model.UserManager#exportUser(java.lang.String)
!      */
!     public String exportUser(String userName) throws RollerException
!     {
!         // TODO Hibernate impl for exportUser
!         return null;
!     }
! 
!     
//------------------------------------------------------------------------    
!     /** 
!      * @see org.roller.model.UserManager#retrievePage(java.lang.String)
!      */
!     public PageData retrievePageReadOnly(String id) throws RollerException
!     {
!         // Hibernate has a read-only flag: LockMode.READ
!         return 
(PageData)mStrategy.retrievePersistentObject(id,PageData.class);
      }
  
***************
*** 220,230 ****
       * @see 
org.roller.business.UserManagerBase#getRoles(org.roller.pojos.UserData)
       */
!     protected RoleData[] getRoles(UserData user) throws RollerException
      {
!         Object[] args = { user.getId() };
!         Type[] types = { Hibernate.STRING };
!         List roles = mStrategy.query(Queries.ROLES_BY_USER, args, types);
! 
!         return (RoleData[]) roles.toArray(new RoleData[roles.size()]);
      }
  
--- 249,259 ----
       * @see 
org.roller.business.UserManagerBase#getRoles(org.roller.pojos.UserData)
       */
!     protected List getRoles(UserData user) throws RollerException
      {
!         QueryFactory factory = mStrategy.getQueryFactory();
!         Query query = factory.createQuery(RoleData.class.getName());         
!         query.setWhere(factory.createCondition(
!             "userId", Query.EQ, user.getId()));                               
!         return query.execute();
      }
  
***************
*** 252,272 ****
       * @see org.roller.model.UserManager#getPageByName(java.lang.String, 
java.lang.String)
       */
!     public PageData getPageByName(String u, String p) throws RollerException
      {
!         if ( u==null )
!             throw new RollerException("Username is null");
                                     
!         if ( p==null )
              throw new RollerException("Page name is null");
                                     
!         Object[] args = { u,p, Boolean.TRUE };
!         Type[] types = { Hibernate.STRING,Hibernate.STRING,Hibernate.BOOLEAN 
};
          
!         List list = mStrategy.query(
!             Queries.PAGES_BY_USER + 
!             Queries.NAME_RESTRICTION + 
!             Queries.WEBSITE_USER_ENABLED_RESTRICTION3,
!             args,types);
              
          return list.size()!=0 ? (PageData)list.get(0) : null;
      }
--- 281,313 ----
       * @see org.roller.model.UserManager#getPageByName(java.lang.String, 
java.lang.String)
       */
!     public PageData getPageByName(WebsiteData website, String pagename) 
!         throws RollerException
      {
!         if (website == null)
!             throw new RollerException("website is null");
                                     
!         if (pagename == null)
              throw new RollerException("Page name is null");
                                     
!         QueryFactory factory = mStrategy.getQueryFactory();
!         Query query = factory.createQuery(PageData.class.getName());
          
!         Condition specifiedUser = factory.createCondition(
!             "website", Query.EQ, website);
!         
!         Condition userEnabled = factory.createCondition(
!             "website.user.userEnabled", Query.EQ, new Boolean(true));
!         
!         Condition specifiedPage = factory.createCondition(
!             "name", Query.EQ, pagename);
!             
!         List conditions = new LinkedList();
!         conditions.add(specifiedUser);
!         conditions.add(userEnabled);
!         conditions.add(specifiedPage);
!         
!         query.setWhere(factory.createCondition(Query.AND, conditions));
              
+         List list = query.execute();                               
          return list.size()!=0 ? (PageData)list.get(0) : null;
      }
***************
*** 276,296 ****
       * @see org.roller.model.UserManager#getPageByLink(java.lang.String, 
java.lang.String)
       */
!     public PageData getPageByLink(String user, String pageLink) throws 
RollerException
      {        
!         if ( user==null )
!             throw new RollerException("Username is null");
                                     
!         if ( pageLink==null )
              throw new RollerException("Pagelink is null");
!                                    
!         Object[] args = { user, pageLink, Boolean.TRUE};
!         Type[] types = { Hibernate.STRING,Hibernate.STRING,Hibernate.BOOLEAN 
};
          
!         List list = mStrategy.query(
!             Queries.PAGES_BY_USER + 
!             Queries.LINK_RESTRICTION +
!             Queries.WEBSITE_USER_ENABLED_RESTRICTION3,
!             args,types);
              
          return list.size()!=0 ? (PageData)list.get(0) : null;
      }    
--- 317,348 ----
       * @see org.roller.model.UserManager#getPageByLink(java.lang.String, 
java.lang.String)
       */
!     public PageData getPageByLink(WebsiteData website, String pagelink) 
throws RollerException
      {        
!         if (website == null)
!             throw new RollerException("userName is null");
                                     
!         if (pagelink == null)
              throw new RollerException("Pagelink is null");
!                                                                       
!         QueryFactory factory = mStrategy.getQueryFactory();
!         Query query = factory.createQuery(PageData.class.getName());
          
!         Condition specifiedUser = factory.createCondition(
!             "website", Query.EQ, website);
!         
!         Condition userEnabled = factory.createCondition(
!             "website.user.userEnabled", Query.EQ, new Boolean(true));
!         
!         Condition specifiedLink = factory.createCondition(
!             "link", Query.EQ, pagelink);
!             
!         List conditions = new LinkedList();
!         conditions.add(specifiedUser);
!         conditions.add(userEnabled);
!         conditions.add(specifiedLink);
!         
!         query.setWhere(factory.createCondition(Query.AND, conditions));
              
+         List list = query.execute();                               
          return list.size()!=0 ? (PageData)list.get(0) : null;
      }    
***************
*** 300,316 ****
       * @see org.roller.model.UserManager#getPages(java.lang.String)
       */
!     public PageData[] getPages(String userName) throws RollerException
      {
!         if ( userName == null )
!             throw new RollerException("Username is null");
!                                            
!         Object[] args = {userName, Boolean.TRUE};
!         Type[] types = {Hibernate.STRING,Hibernate.BOOLEAN};       
!         List list = mStrategy.query(
!             Queries.PAGES_BY_USER + 
!             Queries.WEBSITE_USER_ENABLED_RESTRICTION2 +
!             Queries.ORDER_BY_NAME,args,types);
!                         
!         return (PageData[]) list.toArray(new PageData[list.size()]);
      }
  
--- 352,378 ----
       * @see org.roller.model.UserManager#getPages(java.lang.String)
       */
!     public List getPages(WebsiteData website) throws RollerException
      {
!         if (website == null)
!             throw new RollerException("userName is null");
!                                                                       
!         QueryFactory factory = mStrategy.getQueryFactory();
!         Query query = factory.createQuery(PageData.class.getName());
!         
!         Condition specifiedUser = factory.createCondition(
!             "website", Query.EQ, website);
!         
!         Condition userEnabled = factory.createCondition(
!             "website.user.userEnabled", Query.EQ, new Boolean(true));
!             
!         List conditions = new LinkedList();
!         conditions.add(specifiedUser);
!         conditions.add(userEnabled);
!         
!         query.setWhere(factory.createCondition(Query.AND, conditions));
!         
!         query.setOrderBy(Query.ASC, "name");
!             
!         return query.execute();                               
      }
  
***************
*** 336,340 ****
       * @param themeDir Directory containing the theme for this user
       */
!     public void addUser(UserData ud, String theme, HashMap pages)
          throws RollerException
      {
--- 398,402 ----
       * @param themeDir Directory containing the theme for this user
       */
!     public void addUser(UserData ud, String theme, Map pages)
          throws RollerException
      {
***************
*** 409,454 ****
              Integer zero = new Integer(0);
              
!             
!             /* TODO Create bookmarks for new account 
!             
!             FolderData topFolder = new FolderData(
!                 null, "top", "top", website, null);
!             mStrategy.storePersistentObject(topFolder);
!             
!             FolderData blogroll = new FolderData(
!                 null, "Blogroll", "Blogroll", website, topFolder);
              mStrategy.storePersistentObject(blogroll);
  
!             BookmarkData b1 = new BookmarkData(null,
!                 "Dave Johnson","","http://rollerweblogger.org/page/roller";,
!                 zero,zero,blogroll,"",null);
              mStrategy.storePersistentObject(b1);
  
!             BookmarkData b2 = new BookmarkData(null,
!                 "Matt Raible","","http://raibledesigns.com";,
!                 zero,zero,blogroll,"",null);
              mStrategy.storePersistentObject(b2);
  
!             BookmarkData b3 = new BookmarkData(null,
!                 "Lance Lavandowska","",
                  "http://brainopolis.dnsalias.com/roller/page/lance/";,
!                 zero,zero,blogroll,"",null);
              mStrategy.storePersistentObject(b3);
              
              
!             FolderData news = new FolderData(
!                 null, "News", "News", website, topFolder);
              mStrategy.storePersistentObject(news);
  
!             BookmarkData b5 = new BookmarkData(null,
!                 "CNN","","http://www.cnn.com";,
!                 zero,zero,news,"",null);
              mStrategy.storePersistentObject(b5);
  
!             BookmarkData b6 = new BookmarkData(null,
!                 "NY Times","","http://nytimes.com";,
!                 zero,zero,news,"",null);
              mStrategy.storePersistentObject(b6);
!             */
  
              //
--- 471,520 ----
              Integer zero = new Integer(0);
              
!             BookmarkManager bmgr = mRoller.getBookmarkManager();
!                         
!             FolderData blogroll = bmgr.createFolder(
!                 null, "Blogroll", "Blogroll", website);
              mStrategy.storePersistentObject(blogroll);
  
!             BookmarkData b1 = bmgr.createBookmark(
!                 blogroll, "Dave Johnson", "",
!                 "http://rollerweblogger.org/page/roller";,
!                 "http://rollerweblogger.org/rss/roller";,
!                 zero, zero, null);
              mStrategy.storePersistentObject(b1);
  
!             BookmarkData b2 = bmgr.createBookmark(
!                 blogroll, "Matt Raible", "",
!                 "http://raibledesigns.com";,
!                 "http://raibledesigns.com/rss";,
!                 zero, zero, null);
              mStrategy.storePersistentObject(b2);
  
!             BookmarkData b3 = bmgr.createBookmark(
!                 blogroll, "Lance Lavandowska", "",
                  "http://brainopolis.dnsalias.com/roller/page/lance/";,
!                 "http://brainopolis.dnsalias.com/roller/rss/lance/";,
!                 zero, zero, null);
              mStrategy.storePersistentObject(b3);
              
              
!             FolderData news = bmgr.createFolder(
!                 null, "News", "News", website);
              mStrategy.storePersistentObject(news);
  
!             BookmarkData b5 = bmgr.createBookmark(
!                 news, "CNN", "",
!                 "http://www.cnn.com";,
!                 "",
!                 zero, zero, null);
              mStrategy.storePersistentObject(b5);
  
!             BookmarkData b6 = bmgr.createBookmark(
!                 news, "NY Times", "", 
!                "http://nytimes.com";,
!                "",
!                 zero, zero, null);
              mStrategy.storePersistentObject(b6);
! 
  
              //
***************
*** 534,602 ****
  
          WebsiteData website = getWebsite(userName, false);
!         if (website == null)
!         {
!             throw new RollerException("Unable to locate Website for " + 
userName);
!         }
! 
!         int i = 0;
! 
!         // remove folders (takes bookmarks with it)
!         Iterator folders = bMgr.getTopLevelFolders(website).iterator();
!         while (folders.hasNext())
!         {
!             FolderData folder = (FolderData) folders.next();
!             folder.remove();           
!         }
! 
!         // remove newsfeeds
!         NewsfeedData[] newsfeeds = nMgr.getNewsfeeds(userName);
!         for (i = 0; i < newsfeeds.length; i++)
!         {
!             mStrategy.removePersistentObject(
!                 
!                 newsfeeds[i].getId(),
!                 NewsfeedData.class);
!         }
! 
!         // remove entries
!         List entries =
!             wMgr.getWeblogEntries(
!                 userName,
!                 null,
!                 null, 
!                 null, 
!                 false);
!         for (Iterator wbItr = entries.iterator(); wbItr.hasNext();) {
!             WeblogEntryData entry = (WeblogEntryData) wbItr.next();
!             List comments = entry.getComments();
!             for (int x=0; x<comments.size(); x++)
              {
-                 CommentData comment = (CommentData)comments.get(x);
                  mStrategy.removePersistentObject(
!                     comment.getId(), CommentData.class );
              }
!             mStrategy.removePersistentObject(
!                 entry.getId(),
!                 WeblogEntryData.class);
!         }
! 
!         // remove categories
!         List cats = wMgr.getWeblogCategories(website);
!         for (Iterator wbcItr = cats.iterator(); wbcItr.hasNext();) {
!             WeblogCategoryData category = (WeblogCategoryData) wbcItr.next();
!             mStrategy.removePersistentObject(
!                 category.getId(),
!                 WeblogCategoryData.class);
!         }
!         
! 
!         // remove roles
!         RoleData[] roles = getRoles(user);
!         for (i = 0; i < roles.length; i++)
!         {
!             mStrategy.removePersistentObject( roles[i].getId(), 
RoleData.class);
          }
- 
-         mStrategy.removePersistentObject( website.getId(), WebsiteData.class);
  
          mStrategy.removePersistentObject( user.getId(), UserData.class);
--- 600,668 ----
  
          WebsiteData website = getWebsite(userName, false);
!         if (null != website)
!         {   
!             int i = 0;
!     
!             // remove folders (takes bookmarks with it)
!             Iterator folders = bMgr.getTopLevelFolders(website).iterator();
!             while (folders.hasNext())
!             {
!                 FolderData folder = (FolderData) folders.next();
!                 folder.remove();           
!             }
!     
!             // remove newsfeeds
!             NewsfeedData[] newsfeeds = nMgr.getNewsfeeds(userName);
!             for (i = 0; i < newsfeeds.length; i++)
              {
                  mStrategy.removePersistentObject(
!                     
!                     newsfeeds[i].getId(),
!                     NewsfeedData.class);
              }
!     
!             // remove entries
!             List entries =
!                 wMgr.getWeblogEntries(
!                     userName,
!                     null,
!                     null, 
!                     null, 
!                     false);
!             for (Iterator wbItr = entries.iterator(); wbItr.hasNext();) {
!                 WeblogEntryData entry = (WeblogEntryData) wbItr.next();
!                 List comments = entry.getComments();
!                 for (int x=0; x<comments.size(); x++)
!                 {
!                     CommentData comment = (CommentData)comments.get(x);
!                     mStrategy.removePersistentObject(
!                         comment.getId(), CommentData.class );
!                 }
!                 mStrategy.removePersistentObject(
!                     entry.getId(),
!                     WeblogEntryData.class);
!             }
!     
!             // remove categories
!             List cats = wMgr.getWeblogCategories(website);
!             for (Iterator wbcItr = cats.iterator(); wbcItr.hasNext();) {
!                 WeblogCategoryData category = (WeblogCategoryData) 
wbcItr.next();
!                 mStrategy.removePersistentObject(
!                     category.getId(),
!                     WeblogCategoryData.class);
!             }
!             
!     
!             // remove roles
!             List roles = getRoles(user);
!             Iterator roleIter = roles.iterator();
!             while (roleIter.hasNext())
!             {
!                 RoleData role = (RoleData) roleIter.next();
!                 mStrategy.removePersistentObject( role.getId(), 
RoleData.class);            
!             }
!     
!             mStrategy.removePersistentObject( website.getId(), 
WebsiteData.class);
          }
  
          mStrategy.removePersistentObject( user.getId(), UserData.class);

Index: RefererManagerBase.java
===================================================================
RCS file: 
/cvsroot/roller/roller/src/org/roller/business/RefererManagerBase.java,v
retrieving revision 1.21
retrieving revision 1.22
diff -C2 -d -r1.21 -r1.22
*** RefererManagerBase.java     18 Nov 2003 04:20:53 -0000      1.21
--- RefererManagerBase.java     29 Nov 2003 19:11:18 -0000      1.22
***************
*** 8,12 ****
  import org.roller.RollerException;
  import org.roller.ThreadManager;
! import org.roller.business.persistence.PersistenceStrategy;
  import org.roller.model.ParsedRequest;
  import org.roller.model.RefererManager;
--- 8,15 ----
  import org.roller.RollerException;
  import org.roller.ThreadManager;
! import org.roller.persistence.Condition;
! import org.roller.persistence.PersistenceStrategy;
! import org.roller.persistence.Query;
! import org.roller.persistence.QueryFactory;
  import org.roller.model.ParsedRequest;
  import org.roller.model.RefererManager;
***************
*** 17,22 ****
--- 20,28 ----
  import org.roller.util.Utilities;
  
+ import java.text.SimpleDateFormat;
  import java.util.ArrayList;
+ import java.util.Date;
  import java.util.Iterator;
+ import java.util.LinkedList;
  import java.util.List;
  
***************
*** 31,50 ****
      static Log mLogger =
          LogFactory.getFactory().getInstance(RefererManagerBase.class);
!     
      private ThreadManager mThreadManager;
!     
!     public RefererManagerBase() {
      }
      
!     protected PersistenceStrategy mSupport;
! 
!     //------------------------------------------------------------------------
      
!     // Abstract methods used by the methods in this class.
!          
!     public abstract void checkForTurnover(boolean forceTurnover, String 
websiteId) 
          throws RollerException;
!     
!     protected abstract int getHits(String username, String type) throws 
RollerException;
  
      //------------------------------------------------------------------------
--- 37,121 ----
      static Log mLogger =
          LogFactory.getFactory().getInstance(RefererManagerBase.class);
!     protected PersistenceStrategy mStrategy;
      private ThreadManager mThreadManager;
!     private Date mRefDate = new Date();
!     private SimpleDateFormat mDateFormat = new SimpleDateFormat("yyyyMMdd");
! 
!     //----------------------------------------------------------------------- 
   
! 
!     public RefererManagerBase() 
!     {
      }
      
!     //----------------------------------------------------------------------- 
 
      
!     protected abstract int getHits(WebsiteData website, String type)
          throws RollerException;
!       
!     //----------------------------------------------------------------------- 
   
! 
!     /** 
!      * Purge referers at midnight. Zero out all dayhits and remove all 
!      * referers that do not have excerpts.
!      */
!     public void checkForTurnover( boolean forceTurnover, String websiteId ) 
!         throws RollerException
!     {
!         // Note, this method doesn't need to be synchronized anymore since 
!         // it's called from the timer task now, and will never be executed 
!         // by two threads simultaneously.
!         if (mLogger.isDebugEnabled()) 
!         {
!             mLogger.debug("checkForTurnover");
!         }
!         
!         Date now = new Date();
! 
!         if (forceTurnover || 
!                 !mDateFormat.format(now).equals(mDateFormat.format(mRefDate)))
!         {
!             try
!             {
!                 if (websiteId == null) mRefDate = now;
!                 
!                 QueryFactory factory = mStrategy.getQueryFactory();
!                 Query query = 
factory.createQuery(RefererData.class.getName());        
!         
!                 List conditions = new LinkedList();
!                 conditions.add(factory.createCondition(
!                     "dayHits", Query.GT, new Integer(0)));             
! 
!                 if (websiteId != null)
!                 {
!                     conditions.add(factory.createCondition(
!                         "website.id", Query.EQ, websiteId));             
!                 }
!                 query.setWhere(factory.createCondition(Query.AND, 
conditions));
!                 List refs = query.execute();
!                 
!                 Integer zero = new Integer(0);
!                 for (Iterator rdItr = refs.iterator(); rdItr.hasNext();) {
!                     RefererData referer = (RefererData) rdItr.next();
!                     
!                     if ((referer.getExcerpt() != null) && 
!                             (referer.getExcerpt().trim().length() > 0))
!                     {
!                         // Zero out dayhits of referers with excerpts
!                         referer.setDayHits(zero);
!                         storeReferer(referer);
!                     }
!                     else
!                     {
!                         // Throw away referers without excerpts
!                         removeReferer(referer.getId());
!                     }
!                 }
!             }
!             catch (RollerException e)
!             {
!                 mLogger.error("EXCEPTION resetting referers",e);
!             }         
!         }
!     }
  
      //------------------------------------------------------------------------
***************
*** 63,76 ****
      //--------------------------------------------------------- Get hit counts
  
!     public int getDayHits(String username) throws RollerException
      {
!         return getHits(username, "dayhits");
      }
  
      //----------------------------------------------------------------------- 
   
  
!     public int getTotalHits(String username) throws RollerException
      {
!         return getHits(username, "totalhits");
      }
  
--- 134,147 ----
      //--------------------------------------------------------- Get hit counts
  
!     public int getDayHits(WebsiteData website) throws RollerException
      {
!         return getHits(website, "dayhits");
      }
  
      //----------------------------------------------------------------------- 
   
  
!     public int getTotalHits(WebsiteData website) throws RollerException
      {
!         return getHits(website, "totalhits");
      }
  
***************
*** 83,87 ****
      public void removeReferer(String id) throws RollerException
      {
!         mSupport.removePersistentObject(id, RefererData.class);
      }
  
--- 154,158 ----
      public void removeReferer(String id) throws RollerException
      {
!         mStrategy.removePersistentObject(id, RefererData.class);
      }
  
***************
*** 93,97 ****
      public RefererData retrieveReferer(String id) throws RollerException
      {
!         return 
(RefererData)mSupport.retrievePersistentObject(id,RefererData.class);
      }
  
--- 164,168 ----
      public RefererData retrieveReferer(String id) throws RollerException
      {
!         return 
(RefererData)mStrategy.retrievePersistentObject(id,RefererData.class);
      }
  
***************
*** 104,114 ****
      public void storeReferer(RefererData data) throws RollerException
      {
!         mSupport.storePersistentObject(data);
      }
      
      //-----------------------------------------------------------------------
!     public List getEntryReferers(String entryId, boolean authorized) throws 
RollerException
      {       
!         //TODO: Redesign this so this is performed using the DB query, and 
not in java code for perf/memory reasons
          List authorizedvisible = new ArrayList();
          List referers = getReferersToEntry(entryId);
--- 175,187 ----
      public void storeReferer(RefererData data) throws RollerException
      {
!         mStrategy.storePersistentObject(data);
      }
      
      //-----------------------------------------------------------------------
!     public List getEntryReferers(String entryId, boolean authorized) 
!         throws RollerException
      {       
!         //TODO: Redesign this so this is performed using the DB query, and 
!         // not in java code for perf/memory reasons
          List authorizedvisible = new ArrayList();
          List referers = getReferersToEntry(entryId);
***************
*** 130,140 ****
       * @see org.roller.pojos.RefererManager#getReferers(java.lang.String)
       */
!     public List getReferers(String username) throws RollerException
      {
!         String query =
!             Queries.REFERERS_BY_USER + 
Queries.WEBSITE_USER_ENABLED_RESTRICTION2 + Queries.ORDER_BY_TOTAL_HITS;
!         Object[] args = { username, Boolean.TRUE };
!         Type[] types = { Hibernate.STRING, Hibernate.BOOLEAN };
!         return getReferers(query, args, types);
      }
  
--- 203,226 ----
       * @see org.roller.pojos.RefererManager#getReferers(java.lang.String)
       */
!     public List getReferers(WebsiteData website) throws RollerException
      {
!         if (website==null )
!             throw new RollerException("website is null");
! 
!         QueryFactory factory = mStrategy.getQueryFactory();
!         Query query = factory.createQuery(RefererData.class.getName());       
 
!         
!         Condition specifiedUser = factory.createCondition(
!             "website", Query.EQ, website);
!         
!         Condition userEnabled = factory.createCondition(
!             "website.user.userEnabled", Query.EQ, new Boolean(true));
!         
!         query.setWhere(factory.createCondition(
!             specifiedUser, Query.AND, userEnabled));
!             
!         query.setOrderBy(Query.DESC, "totalHits");
!         
!         return query.execute();
      }
  
***************
*** 144,158 ****
       * @see org.roller.pojos.RefererManager#getTodaysReferers(String)
       */
!     public List getTodaysReferers(String username)
          throws RollerException
      {
!         Object[] args = { username, Boolean.TRUE }; 
!         Type[] types = { Hibernate.STRING, Hibernate.BOOLEAN };
!         String query =
!             Queries.REFERERS_WITH_DAYHITS + 
!             Queries.WEBSITE_USER_RESTRICTION +
!             Queries.WEBSITE_USER_ENABLED_RESTRICTION2 +
!             Queries.ORDER_BY_DAY_HITS;
!         return getReferers(query, args, types);
      }
  
--- 230,261 ----
       * @see org.roller.pojos.RefererManager#getTodaysReferers(String)
       */
!     public List getTodaysReferers(WebsiteData website)
          throws RollerException
      {
!         if (website==null )
!             throw new RollerException("website is null");
! 
!         QueryFactory factory = mStrategy.getQueryFactory();
!         Query query = factory.createQuery(RefererData.class.getName()); 
!                
!         Condition specifiedUser = factory.createCondition(
!             "website", Query.EQ, website);
!             
!         Condition hasDayHits = factory.createCondition(
!             "dayhits", Query.GT, new Integer(0));
!             
!         Condition userEnabled = factory.createCondition(
!             "website.user.userEnabled", Query.EQ, new Boolean(true));
!             
!         List conditions = new LinkedList();
!         conditions.add(specifiedUser);
!         conditions.add(hasDayHits);
!         conditions.add(userEnabled);
!                 
!         query.setWhere(factory.createCondition(Query.AND, conditions));
!             
!         query.setOrderBy(Query.DESC, "dayhits");
!         
!         return query.execute();
      }
  
***************
*** 165,181 ****
       * java.lang.String, java.lang.String)
       */
!     public List getReferersToDate(String username, String date)
          throws RollerException
      {
!     //    WebsiteData website = mUserMgr.getWebsite(username);
!     //    if (website == null) return Collections.EMPTY_LIST;
          
!         Object[] args = { username, date, Boolean.FALSE };
!         Type[] types = {Hibernate.STRING,Hibernate.STRING,Hibernate.BOOLEAN};
!         String query =
!             Queries.REFERERS_BY_USER +
!             "AND p.dateString=$2 AND p.duplicate=$3 " + 
!             Queries.ORDER_BY_TOTAL_HITS;
!         return getReferers(query, args, types);
      }
  
--- 268,302 ----
       * java.lang.String, java.lang.String)
       */
!     public List getReferersToDate(WebsiteData website, String date)
          throws RollerException
      {
!         if (website==null )
!             throw new RollerException("website is null");
! 
!         if (date==null )
!             throw new RollerException("Date is null");
! 
!         QueryFactory factory = mStrategy.getQueryFactory();
!         Query query = factory.createQuery(RefererData.class.getName()); 
          
!         Condition specifiedUser = factory.createCondition(
!             "website", Query.EQ, website);
!             
!         Condition specifiedDate = factory.createCondition(
!             "dateString", Query.EQ, date);
!             
!         Condition notDuplicate = factory.createCondition(
!             "duplicate", Query.EQ, new Boolean(false));
!             
!         List conditions = new LinkedList();
!         conditions.add(specifiedUser);
!         conditions.add(specifiedDate);
!         conditions.add(notDuplicate);
! 
!         query.setWhere(factory.createCondition(Query.AND, conditions));
!             
!         query.setOrderBy(Query.DESC, "totalhits");
!         
!         return query.execute();
      }
  
***************
*** 188,197 ****
          throws RollerException
      {
!         Type[] types = { Hibernate.STRING, Hibernate.STRING, Hibernate.STRING 
};
!         String query =
!             Queries.REFERERS_BY_WEBSITE + 
!             Queries.REQUEST_URL_RESTRICTION + 
!             " AND p.refererUrl=$3 ";               
!         return getReferers(query,args,types);
      }
      
--- 309,332 ----
          throws RollerException
      {
!         QueryFactory factory = mStrategy.getQueryFactory();
!         Query query = factory.createQuery(RefererData.class.getName()); 
!         
!         Condition specifiedWebsite = factory.createCondition(
!             "website.user.userName", Query.EQ, args[0] );
!         
!         Condition specifiedUrl = factory.createCondition(
!             "requestUrl", Query.EQ, args[1] );
!         
!         Condition specifiedReferer = factory.createCondition(
!             "refererUrl", Query.EQ, args[2] );
! 
!         List conditions = new LinkedList();
!         conditions.add(specifiedWebsite);
!         conditions.add(specifiedUrl);
!         conditions.add(specifiedReferer);
! 
!         query.setWhere(factory.createCondition(Query.AND, conditions));
!         
!         return query.execute();
      }
      
***************
*** 204,213 ****
          throws RollerException
      {
!         Type[] types = { Hibernate.STRING, Hibernate.STRING, Hibernate.STRING 
};
!         String query =
!             Queries.REFERERS_BY_WEBSITE + 
!             " AND p.dateString=$2 " +
!             " AND p.refererPermalink=$3 ";               
!         return getReferers(query,args,types);
      }
      
--- 339,362 ----
          throws RollerException
      {
!         QueryFactory factory = mStrategy.getQueryFactory();
!         Query query = factory.createQuery(RefererData.class.getName()); 
!         
!         Condition specifiedWebsite = factory.createCondition(
!             "website.user.userName", Query.EQ, args[0] );
!         
!         Condition specifiedDate = factory.createCondition(
!             "dateString", Query.EQ, args[1] );
!         
!         Condition specifiedReferer = factory.createCondition(
!             "refererPermalink", Query.EQ, args[2] );
! 
!         List conditions = new LinkedList();
!         conditions.add(specifiedWebsite);
!         conditions.add(specifiedDate);
!         conditions.add(specifiedReferer);
! 
!         query.setWhere(factory.createCondition(Query.AND, conditions));
!         
!         return query.execute();
      }
      
***************
*** 216,219 ****
--- 365,399 ----
  
      /**
+      * @see org.roller.pojos.RefererManager#getReferersToEntry(
+      * java.lang.String, java.lang.String)
+      */
+     public List getReferersToEntry(String entryid) throws RollerException
+     {
+         if (null == entryid)
+             throw new RollerException("entryid is null");
+         
+         QueryFactory factory = mStrategy.getQueryFactory();
+         Query query = factory.createQuery(RefererData.class.getName());
+         List conditions = new LinkedList();
+         
+         conditions.add(factory.createCondition(
+             "weblogEntry.id", Query.EQ, entryid));
+         
+         conditions.add(factory.createCondition(
+             "title", Query.NOT_NULL));
+         
+         conditions.add(factory.createCondition(
+             "excerpt", Query.NOT_NULL));
+             
+         query.setWhere(factory.createCondition(Query.AND, conditions));
+         query.setOrderBy(Query.DESC, "totalHits");
+         
+         return query.execute();
+     }
+ 
+ 
+     //----------------------------------------------------------------------- 
   
+ 
+     /**
       * Query for collection of referers.
       */
***************
*** 221,228 ****
          throws RollerException
      {
!         Type[] types = { Hibernate.STRING, Hibernate.STRING };
!         String query =
!             Queries.REFERERS_BY_WEBSITE + " AND p.refererUrl=$2 ";
!         return getReferers(query,args,types);
      }
      
--- 401,420 ----
          throws RollerException
      {
!         QueryFactory factory = mStrategy.getQueryFactory();
!         Query query = factory.createQuery(RefererData.class.getName()); 
!         
!         Condition specifiedWebsite = factory.createCondition(
!             "website.user.userName", Query.EQ, args[0] );
!         
!         Condition specifiedReferer = factory.createCondition(
!             "refererUrl", Query.EQ, args[1] );
! 
!         List conditions = new LinkedList();
!         conditions.add(specifiedWebsite);
!         conditions.add(specifiedReferer);
! 
!         query.setWhere(factory.createCondition(Query.AND, conditions));
!         
!         return query.execute();
      }
      
***************
*** 235,245 ****
          throws RollerException
      {
!         Type[] types = { Hibernate.STRING, Hibernate.STRING, 
!                          Hibernate.STRING, Hibernate.STRING };
!         String query = 
!             Queries.REFERERS_BY_WEBSITE + 
!             Queries.REQUEST_URL_RESTRICTION +
!             "AND ( p.title=$3 OR p.excerpt=$4 )";
!         return getReferers(query,args,types);
      }
      
--- 427,456 ----
          throws RollerException
      {
!         QueryFactory factory = mStrategy.getQueryFactory();
!         Query query = factory.createQuery(RefererData.class.getName()); 
!         
!         Condition specifiedWebsite = factory.createCondition(
!             "website.user.userName", Query.EQ, args[0] );
!         
!         Condition specifiedUrl = factory.createCondition(
!             "requestUrl", Query.EQ, args[1] );
! 
!         Condition specifiedTitle = factory.createCondition(
!             "title", Query.EQ, args[2] );
! 
!         Condition specifiedExcerpt = factory.createCondition(
!             "excerpt", Query.EQ, args[3] );
! 
!         Condition titleOrExcerpt = factory.createCondition(
!             specifiedTitle, Query.OR, specifiedExcerpt );
! 
!         List conditions = new LinkedList();
!         conditions.add(specifiedWebsite);
!         conditions.add(specifiedUrl);
!         conditions.add(titleOrExcerpt);
!         
!         query.setWhere(factory.createCondition(Query.AND, conditions));
!         
!         return query.execute();
      }
      
***************
*** 252,256 ****
          throws RollerException
      {
!         return mSupport.query(query, args, types);
      }
  
--- 463,467 ----
          throws RollerException
      {
!         return mStrategy.query(query, args, types);
      }
  
***************
*** 597,601 ****
              {
                  try {
!                     mSupport.release();
                  }
                  catch (RollerException e) {
--- 808,812 ----
              {
                  try {
!                     mStrategy.release();
                  }
                  catch (RollerException e) {

Index: NewsfeedManagerBase.java
===================================================================
RCS file: 
/cvsroot/roller/roller/src/org/roller/business/NewsfeedManagerBase.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** NewsfeedManagerBase.java    19 Oct 2003 21:48:38 -0000      1.4
--- NewsfeedManagerBase.java    29 Nov 2003 19:11:18 -0000      1.5
***************
*** 4,16 ****
  package org.roller.business;
  
- import net.sf.hibernate.Hibernate;
- import net.sf.hibernate.type.Type;
- 
  import org.roller.RollerException;
! import org.roller.business.persistence.Condition;
! import org.roller.business.persistence.FieldCondition;
! import org.roller.business.persistence.PersistenceStrategy;
! import org.roller.business.persistence.Query;
! import org.roller.business.persistence.QueryFactory;
  import org.roller.model.NewsfeedManager;
  import org.roller.pojos.NewsfeedData;
--- 4,12 ----
  package org.roller.business;
  
  import org.roller.RollerException;
! import org.roller.persistence.Condition;
! import org.roller.persistence.PersistenceStrategy;
! import org.roller.persistence.Query;
! import org.roller.persistence.QueryFactory;
  import org.roller.model.NewsfeedManager;
  import org.roller.pojos.NewsfeedData;
***************
*** 19,27 ****
  
  /**
   * @author llavandowska
   */
! public abstract class NewsfeedManagerBase implements NewsfeedManager
  {    
!       protected PersistenceStrategy mSupport;
  
        /** 
--- 15,30 ----
  
  /**
+  * Implementation of NewsfeedManager using PersistenceStrategy and Query API.
+  * @author Dave Johnson
   * @author llavandowska
   */
! public class NewsfeedManagerBase implements NewsfeedManager
  {    
!       protected PersistenceStrategy mStrategy;
!     
!     public NewsfeedManagerBase(PersistenceStrategy strategy) 
!     {
!         mStrategy = strategy;
!     }
  
        /** 
***************
*** 39,43 ****
        public NewsfeedData retrieveNewsfeed(String id) throws RollerException
        {
!               return 
(NewsfeedData)mSupport.retrievePersistentObject(id,NewsfeedData.class);
        }
  
--- 42,46 ----
        public NewsfeedData retrieveNewsfeed(String id) throws RollerException
        {
!               return 
(NewsfeedData)mStrategy.retrievePersistentObject(id,NewsfeedData.class);
        }
  
***************
*** 47,51 ****
        public void storeNewsfeed(NewsfeedData data) throws RollerException
        {
!               mSupport.storePersistentObject(data);
        }
  
--- 50,54 ----
        public void storeNewsfeed(NewsfeedData data) throws RollerException
        {
!               mStrategy.storePersistentObject(data);
        }
  
***************
*** 55,59 ****
        public void removeNewsfeed(String id) throws RollerException
        {
!               mSupport.removePersistentObject(id,NewsfeedData.class);
        }
  
--- 58,62 ----
        public void removeNewsfeed(String id) throws RollerException
        {
!               mStrategy.removePersistentObject(id,NewsfeedData.class);
        }
  
***************
*** 66,70 ****
              throw new RollerException("Username is null");
          
!         QueryFactory factory = mSupport.getQueryFactory();
          Query query = factory.createQuery(NewsfeedData.class.getName());      
  
          Condition c = 
--- 69,73 ----
              throw new RollerException("Username is null");
          
!         QueryFactory factory = mStrategy.getQueryFactory();
          Query query = factory.createQuery(NewsfeedData.class.getName());      
  
          Condition c = 
***************
*** 72,79 ****
          query.setWhere(c);
          List list = query.execute();
-             
- //        Object[] args = { userName };
- //        Type[] types = {Hibernate.STRING};        
- //        List list = mSupport.query(Queries.NEWSFEEDS_BY_USER, args, types );
          
          return (NewsfeedData[])list.toArray(new NewsfeedData[list.size()]);
--- 75,78 ----
***************
*** 90,94 ****
              throw new RollerException("Newsfeed name is null");
                         
!         QueryFactory factory = mSupport.getQueryFactory();
          Query query = factory.createQuery(NewsfeedData.class.getName());      
  
          Condition c1 = 
--- 89,93 ----
              throw new RollerException("Newsfeed name is null");
                         
!         QueryFactory factory = mStrategy.getQueryFactory();
          Query query = factory.createQuery(NewsfeedData.class.getName());      
  
          Condition c1 = 
***************
*** 97,105 ****
          query.setWhere(factory.createCondition(c1, Query.AND, c2));
          List list = query.execute();
- 
- //        Object[] args = { userName, name };
- //        Type[] types = {Hibernate.STRING,Hibernate.STRING};        
- //        List list = mSupport.query(
- //            Queries.NEWSFEEDS_BY_USER + Queries.NAME_RESTRICTION, args, 
types );
              
          return list.size()!=0 ? (NewsfeedData)list.get(0) : null;
--- 96,99 ----

Index: WeblogManagerBase.java
===================================================================
RCS file: 
/cvsroot/roller/roller/src/org/roller/business/WeblogManagerBase.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -C2 -d -r1.19 -r1.20
*** WeblogManagerBase.java      27 Oct 2003 20:49:14 -0000      1.19
--- WeblogManagerBase.java      29 Nov 2003 19:11:18 -0000      1.20
***************
*** 4,12 ****
  package org.roller.business;
  
! import net.sf.hibernate.Hibernate;
! import net.sf.hibernate.type.Type;
! 
  import org.roller.RollerException;
! import org.roller.business.persistence.PersistenceStrategy;
  import org.roller.model.WeblogManager;
  import org.roller.pojos.CommentData;
--- 4,14 ----
  package org.roller.business;
  
! import org.apache.commons.logging.Log;
! import org.apache.commons.logging.LogFactory;
  import org.roller.RollerException;
! import org.roller.persistence.Condition;
! import org.roller.persistence.PersistenceStrategy;
! import org.roller.persistence.Query;
! import org.roller.persistence.QueryFactory;
  import org.roller.model.WeblogManager;
  import org.roller.pojos.CommentData;
***************
*** 22,29 ****
  import java.util.ArrayList;
  import java.util.Calendar;
- import java.util.Collections;
  import java.util.Comparator;
  import java.util.Date;
  import java.util.Iterator;
  import java.util.List;
  import java.util.Map;
--- 24,31 ----
  import java.util.ArrayList;
  import java.util.Calendar;
  import java.util.Comparator;
  import java.util.Date;
  import java.util.Iterator;
+ import java.util.LinkedList;
  import java.util.List;
  import java.util.Map;
***************
*** 32,44 ****
  
  /**
!  * Provides methods that can be used by persistence framework specific 
!  * implementations.
!  * @author dmj
   */
! public abstract class WeblogManagerBase implements WeblogManager
  {
!     protected PersistenceStrategy mSupport;
      private Comparator reverseComparator = new ReverseComparator();
      private SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
  
      class ReverseComparator implements Comparator
--- 34,53 ----
  
  /**
!  * Implementation of WeblogManager using PersistenceStrategory and Query API.
!  * @author Dave Johnson
   */
! public class WeblogManagerBase implements WeblogManager
  {
!     private static Log mLogger =
!         LogFactory.getFactory().getInstance(WeblogManagerBase.class);
!     protected PersistenceStrategy mStrategy;
      private Comparator reverseComparator = new ReverseComparator();
      private SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
+     
+     
+     public WeblogManagerBase(PersistenceStrategy strategy)
+     {
+         mStrategy = strategy;
+     }
  
      class ReverseComparator implements Comparator
***************
*** 61,69 ****
  
      //------------------------------------------------------------------------
  
      public WeblogEntryData retrieveWeblogEntry(String id)
          throws RollerException
      {
!         return (WeblogEntryData) mSupport.retrievePersistentObject(
              id,
              WeblogEntryData.class);
--- 70,91 ----
  
      //------------------------------------------------------------------------
+     
+     public void storeWeblogEntry(WeblogEntryData data) throws RollerException
+     {
+         // If no anchor then create one
+         if (data.getAnchor()==null || data.getAnchor().trim().equals(""))
+         {
+             data.setAnchor(createAnchor(data));
+         }
+ 
+         mStrategy.storePersistentObject(data);          
+     }
+     
+     //------------------------------------------------------------------------
  
      public WeblogEntryData retrieveWeblogEntry(String id)
          throws RollerException
      {
!         return (WeblogEntryData) mStrategy.retrievePersistentObject(
              id,
              WeblogEntryData.class);
***************
*** 74,78 ****
      public void removeWeblogEntry(String id) throws RollerException
      {
!         mSupport.removePersistentObject(id, WeblogEntryData.class);
      }
  
--- 96,100 ----
      public void removeWeblogEntry(String id) throws RollerException
      {
!         mStrategy.removePersistentObject(id, WeblogEntryData.class);
      }
  
***************
*** 82,86 ****
          throws RollerException
      {
!         return (WeblogCategoryData) mSupport.retrievePersistentObject(
              id,
              WeblogCategoryData.class);
--- 104,108 ----
          throws RollerException
      {
!         return (WeblogCategoryData) mStrategy.retrievePersistentObject(
              id,
              WeblogCategoryData.class);
***************
*** 92,96 ****
          throws RollerException
      {
!         mSupport.storePersistentObject(data);
      }
  
--- 114,118 ----
          throws RollerException
      {
!         mStrategy.storePersistentObject(data);
      }
  
***************
*** 99,103 ****
      public void removeWeblogCategory(String id) throws RollerException
      {
!         mSupport.removePersistentObject(id, WeblogCategoryData.class);
      }
  
--- 121,125 ----
      public void removeWeblogCategory(String id) throws RollerException
      {
!         mStrategy.removePersistentObject(id, WeblogCategoryData.class);
      }
  
***************
*** 106,115 ****
      public void storeComment(CommentData data) throws RollerException
      {
!         mSupport.storePersistentObject(data);
      }
  
      public void removeComment(String id) throws RollerException
      {
!         mSupport.removePersistentObject(id, CommentData.class);
      }
  
--- 128,137 ----
      public void storeComment(CommentData data) throws RollerException
      {
!         mStrategy.storePersistentObject(data);
      }
  
      public void removeComment(String id) throws RollerException
      {
!         mStrategy.removePersistentObject(id, CommentData.class);
      }
  
***************
*** 146,154 ****
          int count = 0;
  
-         String query =
-             Queries.ENTRIES_BY_WEBSITEID + Queries.ANCHOR_RESTRICTION
-         /* + Queries.ORDER_BY_PUBTIME */;
-         String[] args = { entry.getWebsite().getId(), name };
-         Type[] types = { Hibernate.STRING, Hibernate.STRING };
          while (true)
          {
--- 168,171 ----
***************
*** 156,163 ****
              {
                  name = base + count;
-                 args[1] = name;
              }
  
!             List results = mSupport.query(query, args, types);
              if (results.size() < 1)
              {
--- 173,192 ----
              {
                  name = base + count;
              }
  
!             QueryFactory factory = mStrategy.getQueryFactory();
!             Query query = 
factory.createQuery(WeblogEntryData.class.getName());
!             
!             Condition specifiedWebsite = factory.createCondition(
!                 "website", Query.EQ, entry.getWebsite());
!             
!             Condition candidateAnchor = factory.createCondition(
!                 "anchor", Query.EQ, name);
!             
!             query.setWhere(factory.createCondition(
!                 specifiedWebsite, Query.AND, candidateAnchor));
!             
!             List results = query.execute();
!             
              if (results.size() < 1)
              {
***************
*** 306,317 ****
      }
  
-     public abstract List getRecentWeblogEntriesArray(
-         String userName,
-         Date day,
-         String catName,
-         int count,
-         boolean publishedOnly)
-         throws RollerException;
- 
      // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  
--- 335,338 ----
***************
*** 359,382 ****
  
      public WeblogEntryData getWeblogEntryByAnchor(
!         String userName,
!         String anchor)
!         throws RollerException
      {
!         // query for website's weblogentries
!         String query =
!             Queries.ENTRIES_BY_WEBSITE
!                 + Queries.ANCHOR_RESTRICTION
!                 + Queries.WEBSITE_USER_ENABLED_RESTRICTION3
!                 + Queries.ORDER_BY_PUBTIME;
!         Object[] args = { userName, anchor, Boolean.TRUE };
!         Type[] types =
!             { Hibernate.STRING, Hibernate.STRING, Hibernate.BOOLEAN };
!         List results = mSupport.query(query, args, types);
!         if (results.size() > 0)
!         {
!             return (WeblogEntryData) results.get(0);
!         }
  
!         return null;
      }
  
--- 380,414 ----
  
      public WeblogEntryData getWeblogEntryByAnchor(
!         String userName,String anchor) throws RollerException
      {
!         if (userName == null)
!             throw new RollerException("Username is null");
!                                                                       
!         if (anchor == null)
!             throw new RollerException("Anchor is null");
!                                                                       
!         QueryFactory factory = mStrategy.getQueryFactory();
!         Query query = factory.createQuery(WeblogEntryData.class.getName());
!         
!         Condition specifiedUser = factory.createCondition(
!             "website.user.userName", Query.EQ, userName);
!         
!         Condition userEnabled = factory.createCondition(
!             "website.user.userEnabled", Query.EQ, new Boolean(true));
!             
!         Condition specifiedAnchor = factory.createCondition(
!             "anchor", Query.EQ, anchor);
!             
!         List conditions = new LinkedList();
!         conditions.add(specifiedUser);
!         conditions.add(userEnabled);
!         conditions.add(specifiedAnchor);
!         
!         query.setWhere(factory.createCondition(Query.AND, conditions));
!         
!         query.setOrderBy(Query.DESC, "pubTime");
  
!         List list = query.execute();                               
!         return list.size()!=0 ? (WeblogEntryData)list.get(0) : null;
      }
  
***************
*** 451,518 ****
          }
  
-         //        /**
-         //         * I think this could be rewritten using the new DateUtil 
methods
-         //         * getEndOfDay() and getStartOfDay(), but I'm not 100% sure 
of the
-         //         * logic, so I don't want to attempt it. -Lance
-         //         */
-         //
-         //        // Get earliest time of startDate
-         //        Calendar scal = Calendar.getInstance();
-         //        scal.setTime(start);
-         //        scal.set(Calendar.HOUR_OF_DAY,      
scal.getMinimum(Calendar.HOUR_OF_DAY));
-         //        scal.set(Calendar.MINUTE,           
scal.getMinimum(Calendar.MINUTE));
-         //        scal.set(Calendar.SECOND,           
scal.getMinimum(Calendar.SECOND));
-         //        scal.set(Calendar.MILLISECOND,      
scal.getMinimum(Calendar.MILLISECOND));
-         //
-         //        // Get latest time of endDate
-         //        Calendar ecal = Calendar.getInstance();
-         //        ecal.setTime(end);
-         //        ecal.set(Calendar.HOUR_OF_DAY,      
ecal.getMaximum(Calendar.HOUR_OF_DAY));
-         //        ecal.set(Calendar.MINUTE,           
ecal.getMaximum(Calendar.MINUTE));
-         //        ecal.set(Calendar.SECOND,           
ecal.getMaximum(Calendar.SECOND));
-         //        ecal.set(Calendar.MILLISECOND,      
ecal.getMaximum(Calendar.MILLISECOND));
-         //
-         //        // Loop from endDate to startDate
-         //        Calendar cal = Calendar.getInstance();
-         //        cal.setTime(ecal.getTime());
-         //        Date dayEnd = null;
-         //        Calendar tcal = null;
-         //        Date dayStart = null;
-         //        while (cal.after(scal))
-         //        {
-         //            dayEnd = cal.getTime();
-         //
-         //            tcal = Calendar.getInstance();
-         //            tcal.setTime(dayEnd);
-         //            tcal.set(
-         //                Calendar.HOUR_OF_DAY,
-         //                tcal.getMinimum(Calendar.HOUR_OF_DAY));
-         //            tcal.set(Calendar.MINUTE, 
tcal.getMinimum(Calendar.MINUTE));
-         //            tcal.set(Calendar.SECOND, 
tcal.getMinimum(Calendar.SECOND));
-         //            tcal.set(
-         //                Calendar.MILLISECOND,
-         //                tcal.getMinimum(Calendar.MILLISECOND));
-         //            dayStart = tcal.getTime();
-         //
-         //            List entries =
-         //                getWeblogEntries(
-         //                    userName,
-         //                    catName,
-         //                    dayStart,
-         //                    dayEnd,
-         //                    publishedOnly);
-         //            int size = entries.size();
-         //            if (size > 0 && daysOnly)
-         //            {
-         //                SimpleDateFormat formatter = new 
SimpleDateFormat("yyyyMMdd");
-         //                map.put(dayStart, formatter.format(dayStart));
-         //            }
-         //            else if (size > 0)
-         //            {
-         //                map.put(dayStart, entries);
-         //            }
-         //            cal.add(Calendar.DATE, -1);
-         //        }
- 
          return map;
      }
--- 483,486 ----
***************
*** 604,642 ****
          throws RollerException
      {
!         Object[] args = null;
!         Type[] types = null;
!         // query for website's weblogentries
!         String query =
!             Queries.RECENT_PUBLISHED_ENTRIES
!             + Queries.WEBSITE_USER_ENABLED_RESTRICTION3;
              
!         if (catName == null)
          {
!             args = new Object[]{ endDate, Boolean.TRUE, Boolean.TRUE, new 
Integer(max)};
!             types = new Type[]{
!                 Hibernate.TIMESTAMP,
!                 Hibernate.BOOLEAN,
!                 Hibernate.BOOLEAN,
!                 Hibernate.INTEGER };
!                 
!             query += Queries.ORDER_BY_PUBTIME;
!             if (max > 0) query += " LIMIT $4";
          }
!         else
          {
!             args = new Object[]{ endDate, Boolean.TRUE, Boolean.TRUE, 
catName, new Integer(max)};
!             types = new Type[]{
!                 Hibernate.TIMESTAMP,
!                 Hibernate.BOOLEAN,
!                 Hibernate.BOOLEAN,
!                 Hibernate.STRING,
!                 Hibernate.INTEGER };
  
!             query += " AND p.category.name = $4 ";
!             query += Queries.ORDER_BY_PUBTIME;
!             if (max > 0) query += " LIMIT $5";
          }
  
!         return mSupport.query(query, args, types);
      }
  
--- 572,774 ----
          throws RollerException
      {
!         if (endDate == null)
!             throw new RollerException("endDate is null");
!                                                                       
!         QueryFactory factory = mStrategy.getQueryFactory();
!         Query query = factory.createQuery(WeblogEntryData.class.getName());
!         
!         Condition specifiedEndDate = factory.createCondition(
!             "pubTime", Query.LT, endDate);
!         
!         Condition userEnabled = factory.createCondition(
!             "website.user.userEnabled", Query.EQ, new Boolean(true));
              
!         List conditions = new LinkedList();
!         conditions.add(specifiedEndDate);
!         conditions.add(userEnabled);
!         
!         if (null != catName)
          {
!             Condition specifiedCategory = factory.createCondition(
!                 "category.name", Query.EQ, catName);
!             conditions.add(specifiedCategory);
          }
!         
!         query.setWhere(factory.createCondition(Query.AND, conditions));
!         
!         query.setLimit(max);
!         query.setOrderBy(Query.DESC, "pubTime");
! 
!         return query.execute();
!     }
! 
!     //------------------------------------------------------------------------
! 
!     public List getWeblogEntries(
!         String userName,
!         String catName,
!         Date startDate,
!         Date endDate,
!         boolean publishedOnly)
!         throws RollerException
!     {
!         QueryFactory factory = mStrategy.getQueryFactory();
!         Query query = factory.createQuery(WeblogEntryData.class.getName());
!             
!         Condition userEnabled = factory.createCondition(
!             "website.user.userEnabled", Query.EQ, new Boolean(true));
!             
!         List conditions = new LinkedList();
!         conditions.add(userEnabled);
! 
!         if ( startDate != null ) 
          {
!             conditions.add(factory.createCondition(
!                 "pubTime", Query.GT, startDate));
!         }
!         
!         if ( endDate != null) 
!         {
!             conditions.add(factory.createCondition(
!                 "pubTime", Query.LT, endDate));
!         }
!         
!         if ( userName != null ) 
!         {
!             conditions.add(factory.createCondition(
!                 "website.user.userName", Query.EQ, userName));
!         }
!         
!         if ( catName != null ) 
!         {
!             conditions.add(factory.createCondition(
!                 "category.name", Query.EQ, catName));
!         }
!         
!         if ( publishedOnly )
!         {
!             conditions.add(factory.createCondition(
!                 "publishEntry", Query.EQ, new Boolean(true)));
!         }
!         
!         query.setWhere(factory.createCondition(Query.AND, conditions));
!         query.setOrderBy(Query.DESC, "pubTime");
!         
!         if (mLogger.isDebugEnabled()) 
!         {
!             mLogger.debug("userName="+userName);
!             if (startDate!=null)
!                 mLogger.debug("startDate="+startDate.toString());
!             if (endDate!=null)
!                 mLogger.debug("endDate="+endDate.toString());
!             mLogger.debug("catName="+catName);
!             mLogger.debug("query="+query);
!         }
  
!         return query.execute();
!     }
! 
!     //------------------------------------------------------------------------
! 
!     /**
!      * Gets the Date of the latest Entry publish time.
!      * 
!      * @param userName User name of weblog or null for all users
!      * @param catName Category name of posts or null for all categories
!      * @return Date Of last publish time
!      * @throws RollerException
!      */
!     public Date getWeblogLastPublishTime( String userName, String catName ) 
!         throws RollerException
!     {               
!         Date ret = new Date();
! 
!         QueryFactory factory = mStrategy.getQueryFactory();
!         Query query = factory.createQuery(WeblogEntryData.class.getName());   
         
!         List conditions = new LinkedList();
!         
!         conditions.add(factory.createCondition(
!             "website.user.userEnabled", Query.EQ, Boolean.TRUE));
! 
!         conditions.add(factory.createCondition(
!             "publishEntry", Query.EQ, Boolean.TRUE));
!         
!         if ( userName != null ) 
!         {
!             conditions.add(factory.createCondition(
!                 "website.user.userName", Query.EQ, userName));
          }
  
!         if ( catName != null ) 
!         {
!             conditions.add(factory.createCondition(
!                 "category.name", Query.EQ, catName));
!         }
! 
!         query.setWhere(factory.createCondition(Query.AND, conditions));
!         query.setOrderBy(Query.DESC, "pubTime");
!         query.setLimit(1);
!                            
!         if (mLogger.isDebugEnabled()) 
!         { 
!             mLogger.debug("userName="+userName);
!             mLogger.debug("catName="+catName);
!             mLogger.debug("query="+query);
!         }
!         
!         List results = query.execute();
!         Iterator iter = results.iterator();
!         if (iter.hasNext())
!         {
!             WeblogEntryData pubTime= (WeblogEntryData)iter.next();
!             ret = pubTime.getPubTime();
!         }
! 
!         return ret;
!     }
!     
!     //------------------------------------------------------------------------
! 
!     public List getRecentWeblogEntriesArray(
!         String userName,
!         Date day,
!         String catName,
!         int count,
!         boolean publishedOnly)
!         throws RollerException
!     {
!         QueryFactory factory = mStrategy.getQueryFactory();
!         Query query = factory.createQuery(WeblogEntryData.class.getName());   
         
!         List conditions = new LinkedList();
!         
!         conditions.add(factory.createCondition(
!             "website.user.userEnabled", Query.EQ, Boolean.TRUE));
!          
!         conditions.add(factory.createCondition(
!             "pubTime", Query.LE, DateUtil.getEndOfDay(day)));
!         
!         if ( publishedOnly ) 
!         {
!             conditions.add(factory.createCondition(
!                 "publishEntry", Query.EQ, Boolean.TRUE));
!         }
!         
!         if ( userName != null ) 
!         {
!             conditions.add(factory.createCondition(
!                 "website.user.userName", Query.EQ, userName));
!         }
! 
!         if ( catName != null ) 
!         {
!             conditions.add(factory.createCondition(
!                 "category.name", Query.EQ, catName));
!         }
! 
!         query.setWhere(factory.createCondition(Query.AND, conditions));
!         query.setOrderBy(Query.DESC, "pubTime");
!         query.setLimit(count);
!                             
!         return query.execute();
      }
  
***************
*** 645,662 ****
      public boolean isWeblogCategoryInUse(String catId) throws RollerException
      {
!         boolean ret = false;
!         Object[] args = { catId, new Integer(1)};
!         Type[] types = { Hibernate.STRING, Hibernate.INTEGER };
!         List results =
!             mSupport.query(
!                 Queries.ENTRIES_BY_CATEGORY + "order by p.id limit $2",
!                 args,
!                 types);
!         if (results.size() > 0)
!         {
!             // there is an entry in the category, so yes it is IN USE
!             ret = true;
!         }
!         return ret;
      }
  
--- 777,795 ----
      public boolean isWeblogCategoryInUse(String catId) throws RollerException
      {
!         if (catId == null)
!             throw new RollerException("catId is null");
!         
!         QueryFactory factory = mStrategy.getQueryFactory();
!         Query query = factory.createQuery(WeblogEntryData.class.getName());
!         
!         Condition specifiedCategory = factory.createCondition(
!             "category.id", Query.EQ, catId);
!         
!         query.setWhere(specifiedCategory);
!         query.setOrderBy(Query.ASC, "id");
!         query.setLimit(1);        
!         List results = query.execute();
!         
!         return results.size() > 0;
      }
  
***************
*** 666,679 ****
      {
          if (website == null)
!             return Collections.EMPTY_LIST;
! 
!         String query =
!             Queries.CATEGORIES_BY_WEBSITE
!                 + Queries.WEBSITE_USER_ENABLED_RESTRICTION2;
!         Object[] args = { website.getId(), Boolean.TRUE };
!         Type[] types = { Hibernate.STRING, Hibernate.BOOLEAN };
! 
!         return mSupport.query(query, args, types);
  
      }
  
--- 799,819 ----
      {
          if (website == null)
!             throw new RollerException("website is null");
!         
!         QueryFactory factory = mStrategy.getQueryFactory();
!         Query query = factory.createQuery(WeblogCategoryData.class.getName());
!         
!         Condition specifiedWebsite = factory.createCondition(
!             "website", Query.EQ, website);
!         
!         Condition userEnabled = factory.createCondition(
!             "website.user.userEnabled", Query.EQ, new Boolean(true));
!             
!         List conditions = new LinkedList();
!         conditions.add(specifiedWebsite);
!         conditions.add(userEnabled);
  
+         query.setWhere(factory.createCondition(Query.AND, conditions));
+         return query.execute();
      }
  
***************
*** 682,692 ****
      public List getWeblogCategories(String userName) throws RollerException
      {
!         String query =
!             Queries.CATEGORIES_BY_USERNAME
!                 + Queries.WEBSITE_USER_ENABLED_RESTRICTION2;
!         Object[] args = { userName, Boolean.TRUE };
!         Type[] types = { Hibernate.STRING, Hibernate.BOOLEAN };
  
!         return mSupport.query(query, args, types);
      }
  
--- 822,843 ----
      public List getWeblogCategories(String userName) throws RollerException
      {
!         if (userName == null)
!             throw new RollerException("userName is null");
!         
!         QueryFactory factory = mStrategy.getQueryFactory();
!         Query query = factory.createQuery(WeblogCategoryData.class.getName());
!         
!         Condition specifiedWebsite = factory.createCondition(
!             "website.user.userName", Query.EQ, userName);
!         
!         Condition userEnabled = factory.createCondition(
!             "website.user.userEnabled", Query.EQ, new Boolean(true));
!             
!         List conditions = new LinkedList();
!         conditions.add(specifiedWebsite);
!         conditions.add(userEnabled);
  
!         query.setWhere(factory.createCondition(Query.AND, conditions));
!         return query.execute();
      }
  
***************
*** 694,719 ****
  
      public WeblogCategoryData getWeblogCategory(
!         String catName,
!         String userName)
!         throws RollerException
      {
!         WeblogCategoryData cat = null;
  
!         if (catName != null)
!         {
!             String query =
!                 Queries.CATEGORIES_BY_USERNAME
!                     + Queries.NAME_RESTRICTION
!                     + Queries.WEBSITE_USER_ENABLED_RESTRICTION3;
!             Object[] args = { userName, catName, Boolean.TRUE };
!             Type[] types =
!                 { Hibernate.STRING, Hibernate.STRING, Hibernate.BOOLEAN };
!             List results = mSupport.query(query, args, types);
!             if (results.size() > 0)
!             {
!                 cat = (WeblogCategoryData) results.get(0);
!             }
!         }
!         return cat;
      }
  
--- 845,874 ----
  
      public WeblogCategoryData getWeblogCategory(
!         String catName, String userName) throws RollerException
      {
!         if (userName == null)
!             throw new RollerException("userName is null");
!         
!         QueryFactory factory = mStrategy.getQueryFactory();
!         Query query = factory.createQuery(WeblogCategoryData.class.getName());
!         
!         Condition specifiedCategory = factory.createCondition(
!             "name", Query.EQ, catName);
!         
!         Condition specifiedWebsite = factory.createCondition(
!             "website.user.name", Query.EQ, userName);
!         
!         Condition userEnabled = factory.createCondition(
!             "website.user.userEnabled", Query.EQ, new Boolean(true));
!             
!         List conditions = new LinkedList();
!         conditions.add(specifiedCategory);
!         conditions.add(specifiedWebsite);
!         conditions.add(userEnabled);
  
!         query.setWhere(factory.createCondition(Query.AND, conditions));
!         
!         List list = query.execute();                               
!         return list.size()!=0 ? (WeblogCategoryData)list.get(0) : null;
      }
  
***************
*** 724,737 ****
      {
          WeblogCategoryData destCd =
!             (WeblogCategoryData) mSupport.retrievePersistentObject(
!                 destId,
!                 WeblogCategoryData.class);
! 
          WebsiteData website = destCd.getWebsite();
  
          // Loop through entries in src cat, assign them to dest cat
-         Object[] args = { srcId };
-         Type[] types = { Hibernate.STRING };
-         List results = mSupport.query(Queries.ENTRIES_BY_CATEGORY, args, 
types);
          Iterator iter = results.iterator();
          while (iter.hasNext())
--- 879,895 ----
      {
          WeblogCategoryData destCd =
!             (WeblogCategoryData) mStrategy.retrievePersistentObject(
!                 destId, WeblogCategoryData.class);
          WebsiteData website = destCd.getWebsite();
  
+         // Get entries in src category
+         QueryFactory factory = mStrategy.getQueryFactory();
+         Query query = factory.createQuery(WeblogEntryData.class.getName());   
     
+         Condition specifiedCategory = factory.createCondition(
+             "category.id", Query.EQ, srcId);
+         query.setWhere(specifiedCategory);
+         List results = query.execute();
+         
          // Loop through entries in src cat, assign them to dest cat
          Iterator iter = results.iterator();
          while (iter.hasNext())
***************
*** 748,759 ****
      public List getComments(String entryId) throws RollerException
      {
!         if (entryId == null || entryId.equals(""))
!             return Collections.EMPTY_LIST;
! 
!         // Loop through entries in src cat, assign them to dest cat
!         Object[] args = { entryId };
!         Type[] types = { Hibernate.STRING };
! 
!         return mSupport.query(Queries.COMMENTS_BY_ENTRY, args, types);
      }
  
--- 906,919 ----
      public List getComments(String entryId) throws RollerException
      {
!         if (entryId == null)
!             throw new RollerException("entryId is null");
!  
!         QueryFactory factory = mStrategy.getQueryFactory();
!         Query query = factory.createQuery(CommentData.class.getName());       
 
!         Condition specifiedEntry = factory.createCondition(
!             "entry.id", Query.EQ, entryId);
!         query.setWhere(specifiedEntry);
!         query.setOrderBy(Query.ASC, "postTime");
!         return query.execute();
      }
  

--- Queries.java DELETED ---




-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
Does SourceForge.net help you be more productive?  Does it
help you create better code?  SHARE THE LOVE, and help us help
YOU!  Click Here: http://sourceforge.net/donate/


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
web.pylons.gene...    hurd.l4/2002-10...    kernel.commits....    user-groups.lin...    yellowdog.gener...    java.drools.use...    security.openva...    package-managem...    linux.debian.us...    qnx.openqnx.dev...    genealogy.gramp...    file-systems.if...    voip.wengophone...    tex.context/200...    ietf.smime/2003...    audio.csound.de...    culture.region....    xfree86.devel/2...    mobile.kannel.u...    distributed.con...    education.engli...    org.user-groups...    bug-tracking.gn...    recreation.bicy...   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe