[jboss-svn-commits] JBL Code SVN: r7582 - in labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums: . impl ui/view

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon Nov 13 19:29:16 EST 2006


Author: unibrew
Date: 2006-11-13 19:29:13 -0500 (Mon, 13 Nov 2006)
New Revision: 7582

Modified:
   labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ForumsModule.java
   labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/impl/ForumsModuleImpl.java
   labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/view/ViewTopic.java
Log:
[JBFORUMS-135] Improving efficiency of TopicView.

Modified: labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ForumsModule.java
===================================================================
--- labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ForumsModule.java	2006-11-14 00:20:15 UTC (rev 7581)
+++ labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ForumsModule.java	2006-11-14 00:29:13 UTC (rev 7582)
@@ -436,6 +436,34 @@
    List findPostsByTopicId(Integer topicID)
       throws ModuleException;
 
+    /**
+     * DOCUMENT_ME
+     *
+     * @param topicID DOCUMENT_ME
+     * @param start   DOCUMENT_ME
+     * @param limit   DOCUMENT_ME
+     * @return DOCUMENT_ME
+     * @throws ModuleException DOCUMENT_ME
+     */
+    List findPostsByTopicIdAscFetchAttachmentsAndPosters(Integer topicID,
+                               int start,
+                               int limit)
+       throws ModuleException;
+
+    /**
+     * DOCUMENT_ME
+     *
+     * @param topicID DOCUMENT_ME
+     * @param start   DOCUMENT_ME
+     * @param limit   DOCUMENT_ME
+     * @return DOCUMENT_ME
+     * @throws ModuleException DOCUMENT_ME
+     */
+    List findPostsByTopicIdDescFetchAttachmentsAndPosters(Integer topicID,
+                                int start,
+                                int limit)
+       throws ModuleException;
+
    /**
     * DOCUMENT_ME
     *

Modified: labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/impl/ForumsModuleImpl.java
===================================================================
--- labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/impl/ForumsModuleImpl.java	2006-11-14 00:20:15 UTC (rev 7581)
+++ labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/impl/ForumsModuleImpl.java	2006-11-14 00:29:13 UTC (rev 7582)
@@ -1101,6 +1101,61 @@
       }
    }
 
+    private List findPostsByTopicIdFetchAttachmentsAndPosters(Integer topicId,
+                                    int start,
+                                    int limit,
+                                    String order)
+       throws ModuleException
+    {
+       try
+       {
+          Session session = getSession();
+          Query query =
+             session.createQuery(" from PostImpl as p " +
+                                 " join fetch p.poster " +
+                                 " left outer join fetch p.attachments " +
+                                 " where p.topic=:topicId " +
+                                 " order by p.createDate " + order);
+          query.setString("topicId",topicId.toString());
+          query.setFirstResult(start);
+          if (limit != 0)
+          {
+             query.setMaxResults(limit);
+          }
+          Iterator it = query.list().iterator();
+          List list = new LinkedList();
+          while (it.hasNext()) {
+              Post post = (Post)it.next();
+              if (!list.contains(post)) {
+                list.add(post);
+              }
+          }
+          return list;
+       }
+       catch (HibernateException e)
+       {
+          String message = "Cannot find posts";
+          log.error(message, e);
+          throw new ModuleException(message, e);
+       }
+    }
+    
+    public List findPostsByTopicIdAscFetchAttachmentsAndPosters(Integer topicId,
+                                      int start,
+                                      int limit)
+       throws ModuleException
+    {
+       return findPostsByTopicIdFetchAttachmentsAndPosters(topicId, start, limit, "asc");
+    }
+
+    public List findPostsByTopicIdDescFetchAttachmentsAndPosters(Integer topicId,
+                                       int start,
+                                       int limit)
+       throws ModuleException
+    {
+       return findPostsByTopicIdFetchAttachmentsAndPosters(topicId, start, limit, "desc");
+    }
+
    public List findPostsByTopicId(Integer topicId)
       throws ModuleException
    {

Modified: labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/view/ViewTopic.java
===================================================================
--- labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/view/ViewTopic.java	2006-11-14 00:20:15 UTC (rev 7581)
+++ labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/view/ViewTopic.java	2006-11-14 00:29:13 UTC (rev 7582)
@@ -197,11 +197,11 @@
             this.topic =
                     BaseController.getForumsModule().findTopicById(new Integer(topicId));
             topic.setViewCount(topic.getViewCount()+1);
-            Collection posts = this.topic.getPosts();
+            Collection posts = null;
             if (this.userPreferences.getPreference(Constants.POST_ORDER_KEY).compareToIgnoreCase("ascending")==0) {
-                posts = this.getForumsModule().findPostsByTopicIdAsc(topic.getId(),0,Integer.MAX_VALUE);
+                posts = this.getForumsModule().findPostsByTopicIdAscFetchAttachmentsAndPosters(topic.getId(),0,Integer.MAX_VALUE);
             } else {
-                posts = this.getForumsModule().findPostsByTopicIdDesc(topic.getId(),0,Integer.MAX_VALUE);
+                posts = this.getForumsModule().findPostsByTopicIdDescFetchAttachmentsAndPosters(topic.getId(),0,Integer.MAX_VALUE);
             }
             if (posts != null && posts.size() > 0) {
                 int currentPage = 0;




More information about the jboss-svn-commits mailing list