[jboss-svn-commits] JBL Code SVN: r7603 - in labs/jbossforums/branches/forums22/forums/src: main/org/jboss/portlet/forums main/org/jboss/portlet/forums/impl main/org/jboss/portlet/forums/ui/action main/org/jboss/portlet/forums/ui/view resources/portal-forums-sar/conf/hibernate resources/portal-forums-war/WEB-INF
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Tue Nov 14 21:58:40 EST 2006
Author: unibrew
Date: 2006-11-14 21:58:31 -0500 (Tue, 14 Nov 2006)
New Revision: 7603
Modified:
labs/jbossforums/branches/forums22/forums/src/main/org/jboss/portlet/forums/ForumsModule.java
labs/jbossforums/branches/forums22/forums/src/main/org/jboss/portlet/forums/impl/ForumsModuleImpl.java
labs/jbossforums/branches/forums22/forums/src/main/org/jboss/portlet/forums/ui/action/ModeratorAction.java
labs/jbossforums/branches/forums22/forums/src/main/org/jboss/portlet/forums/ui/view/PageNavigator.java
labs/jbossforums/branches/forums22/forums/src/main/org/jboss/portlet/forums/ui/view/ViewForum.java
labs/jbossforums/branches/forums22/forums/src/main/org/jboss/portlet/forums/ui/view/ViewTopic.java
labs/jbossforums/branches/forums22/forums/src/resources/portal-forums-sar/conf/hibernate/hibernate.cfg.xml
labs/jbossforums/branches/forums22/forums/src/resources/portal-forums-war/WEB-INF/forums-config.xml
Log:
[JBFORUMS-141] I redesigned pagination to work more efficiently.
Modified: labs/jbossforums/branches/forums22/forums/src/main/org/jboss/portlet/forums/ForumsModule.java
===================================================================
--- labs/jbossforums/branches/forums22/forums/src/main/org/jboss/portlet/forums/ForumsModule.java 2006-11-15 02:52:06 UTC (rev 7602)
+++ labs/jbossforums/branches/forums22/forums/src/main/org/jboss/portlet/forums/ForumsModule.java 2006-11-15 02:58:31 UTC (rev 7603)
@@ -445,7 +445,31 @@
* @return DOCUMENT_ME
* @throws ModuleException DOCUMENT_ME
*/
- List findPostsByTopicIdAscFetchAttachmentsAndPosters(Integer topicID,
+ List findPostsByIdsAscFetchAttachmentsAndPosters( Collection postIds )
+ throws ModuleException;
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param topicID DOCUMENT_ME
+ * @param start DOCUMENT_ME
+ * @param limit DOCUMENT_ME
+ * @return DOCUMENT_ME
+ * @throws ModuleException DOCUMENT_ME
+ */
+ List findPostsByIdsDescFetchAttachmentsAndPosters( Collection postIds )
+ throws ModuleException;
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param topicID DOCUMENT_ME
+ * @param start DOCUMENT_ME
+ * @param limit DOCUMENT_ME
+ * @return DOCUMENT_ME
+ * @throws ModuleException DOCUMENT_ME
+ */
+ List findPostIdsAsc(Integer topicID,
int start,
int limit)
throws ModuleException;
@@ -459,10 +483,11 @@
* @return DOCUMENT_ME
* @throws ModuleException DOCUMENT_ME
*/
- List findPostsByTopicIdDescFetchAttachmentsAndPosters(Integer topicID,
+ List findPostIdsDesc(Integer topicID,
int start,
int limit)
- throws ModuleException;
+ throws ModuleException;
+
/**
* DOCUMENT_ME
Modified: labs/jbossforums/branches/forums22/forums/src/main/org/jboss/portlet/forums/impl/ForumsModuleImpl.java
===================================================================
--- labs/jbossforums/branches/forums22/forums/src/main/org/jboss/portlet/forums/impl/ForumsModuleImpl.java 2006-11-15 02:52:06 UTC (rev 7602)
+++ labs/jbossforums/branches/forums22/forums/src/main/org/jboss/portlet/forums/impl/ForumsModuleImpl.java 2006-11-15 02:58:31 UTC (rev 7603)
@@ -51,7 +51,9 @@
import java.util.LinkedList;
import java.util.Map;
+import org.jboss.portlet.forums.ui.JSFUtil;
+
/**
* @author <a href="mailto:theute at jboss.org">Thomas Heute </a>
* @author <a href="mailto:boleslaw.dawidowicz at jboss.com">Boleslaw Dawidowicz</a>
@@ -421,33 +423,52 @@
}
- private List findTopics(Forum forum,
- int type,
- int start,
- int perPage,
- String order)
- throws ModuleException
- {
- try
- {
- Session session = getSession();
- Query query =
- session.createQuery("from TopicImpl as t where t.forum = :forumid and t.type <> :type order by t.lastPostDate " + order);
- query.setFirstResult(start);
- query.setMaxResults(perPage);
- query.setString("forumid", "" + forum.getId());
- query.setString("type", "" + type);
- return query.list();
- }
- catch (HibernateException e)
- {
- String message = "Cannot find topics";
- log.error(message, e);
- throw new ModuleException(message, e);
- }
- }
+ /**
+ *
+ * @param forum
+ * @param type
+ * @param start
+ * @param perPage
+ * @param order
+ * @return
+ * @throws ModuleException
+ */
+ private List findTopics(Forum forum,
+ int type,
+ int start,
+ int perPage,
+ String order)
+ throws ModuleException
+ {
+ try
+ {
+ Session session = getSession();
+ Query query =
+ session.createQuery("from TopicImpl as t " +
+ "join fetch t.poster " +
+ "where t.forum = :forumid " +
+ "and t.type = :type " +
+ "order by t.lastPostDate " + order);
+ query.setFirstResult(start);
+ query.setMaxResults(perPage);
+ query.setString("forumid", "" + forum.getId());
+ query.setString("type", "" + type);
+ List list = query.list();
+ return list;
+ }
+ catch (HibernateException e)
+ {
+ String message = "Cannot find topics";
+ throw new ModuleException(message, e);
+ } catch (Exception e) {
+ JSFUtil.handleException(e);
+ String message = "Error while using ForumsModule.";
+ throw new ModuleException(message, e);
+ }
+ }
+
public List findTopicsAsc(Forum forum,
int type,
int start,
@@ -1102,9 +1123,7 @@
}
}
- private List findPostsByTopicIdFetchAttachmentsAndPosters(Integer topicId,
- int start,
- int limit,
+ private List findPostsByIdsFetchAttachmentsAndPosters(Collection postIds ,
String order)
throws ModuleException
{
@@ -1115,14 +1134,9 @@
session.createQuery(" from PostImpl as p " +
" join fetch p.poster " +
" left outer join fetch p.attachments " +
- " where p.topic=:topicId " +
+ " where p.id IN ( :postIds ) " +
" order by p.createDate " + order);
- query.setString("topicId",topicId.toString());
- query.setFirstResult(start);
- if (limit != 0)
- {
- query.setMaxResults(limit);
- }
+ query.setParameterList("postIds",postIds);
Iterator it = query.list().iterator();
List list = new LinkedList();
while (it.hasNext()) {
@@ -1141,20 +1155,62 @@
}
}
- public List findPostsByTopicIdAscFetchAttachmentsAndPosters(Integer topicId,
+ public List findPostsByIdsAscFetchAttachmentsAndPosters(Collection postIds)
+ throws ModuleException
+ {
+ return findPostsByIdsFetchAttachmentsAndPosters( postIds , "asc");
+ }
+
+ public List findPostsByIdsDescFetchAttachmentsAndPosters(Collection postIds)
+ throws ModuleException
+ {
+ return findPostsByIdsFetchAttachmentsAndPosters( postIds , "desc");
+ }
+
+ private List findPostIds(Integer topicId,
+ int start,
+ int limit,
+ String order)
+ throws ModuleException
+ {
+ try
+ {
+ Session session = getSession();
+ Query query =
+ session.createQuery("select p.id " +
+ "from PostImpl as p " +
+ "where p.topic=:topicId " +
+ "order by p.createDate " + order);
+ query.setString("topicId", topicId.toString());
+ query.setFirstResult(start);
+ if (limit != 0)
+ {
+ query.setMaxResults(limit);
+ }
+ return query.list();
+ }
+ catch (HibernateException e)
+ {
+ String message = "Cannot find post ids";
+ log.error(message, e);
+ throw new ModuleException(message, e);
+ }
+ }
+
+ public List findPostIdsAsc(Integer topicId,
int start,
int limit)
throws ModuleException
{
- return findPostsByTopicIdFetchAttachmentsAndPosters(topicId, start, limit, "asc");
+ return findPostIds(topicId, start, limit, "asc");
}
- public List findPostsByTopicIdDescFetchAttachmentsAndPosters(Integer topicId,
+ public List findPostIdsDesc(Integer topicId,
int start,
int limit)
throws ModuleException
{
- return findPostsByTopicIdFetchAttachmentsAndPosters(topicId, start, limit, "desc");
+ return findPostIds(topicId, start, limit, "desc");
}
public List findPostsByTopicId(Integer topicId)
Modified: labs/jbossforums/branches/forums22/forums/src/main/org/jboss/portlet/forums/ui/action/ModeratorAction.java
===================================================================
--- labs/jbossforums/branches/forums22/forums/src/main/org/jboss/portlet/forums/ui/action/ModeratorAction.java 2006-11-15 02:52:06 UTC (rev 7602)
+++ labs/jbossforums/branches/forums22/forums/src/main/org/jboss/portlet/forums/ui/action/ModeratorAction.java 2006-11-15 02:58:31 UTC (rev 7603)
@@ -37,6 +37,7 @@
import org.hibernate.Session;
+import org.jboss.portal.core.modules.ModuleException;
import org.jboss.portlet.forums.ForumsModule;
import org.jboss.portlet.forums.impl.ForumsModuleImpl;
import org.jboss.portlet.forums.model.Forum;
@@ -420,36 +421,67 @@
checkboxes=new HashMap();
+ // ForumsModule is stored as a final variable so that anonymous class could use it.
+ final ForumsModule fm = BaseController.getForumsModule();
+
//grab the data to be displayed for this page
if(forumId!=-1)
{
+
//setup the business objects like the forum, topics etc that will be displayed
- this.forum = BaseController.getForumsModule().findForumById(new Integer(forumId));
- Object[] topicObjects = this.forum.getTopics().toArray();
- //setup the pageNavigator for this forum
- this.pageNavigator = new PageNavigator(
- topicObjects, //total number of entries to be split up into pages
- Integer.parseInt(this.userPreferences.getPreference(Constants.TOPICS_FORUM_KEY)),
- currentPage //currently selected page being displayed, first page by default
- );
- this.page = this.pageNavigator.getPage();
+ this.forum = fm.findForumById(new Integer(forumId));
+
} else {
+
// trying to get forumId from topicId read from request
- int topicId;
String t = ForumUtil.getParameter(Constants.p_topicId);
+
if (t!=null && t.trim().length()>0) {
- Topic topic = this.getForumsModule().findTopicById(new Integer(t));
+
+ Topic topic = fm.findTopicById(new Integer(t));
this.forum = topic.getForum();
- Object[] topicObjects = this.forum.getTopics().toArray();
- //setup the pageNavigator for this forum
- this.pageNavigator = new PageNavigator(
- topicObjects, //total number of entries to be split up into pages
- Integer.parseInt(this.userPreferences.getPreference(Constants.TOPICS_FORUM_KEY)),
- currentPage //currently selected page being displayed, first page by default
- );
- this.page = this.pageNavigator.getPage();
+
}
}
+
+ int topicCount = this.forum.getTopicCount();
+
+ //setup the pageNavigator for this forum
+ this.pageNavigator = new PageNavigator(
+ topicCount, //total number of entries to be split up into pages
+ Integer.parseInt(this.userPreferences.getPreference(Constants.TOPICS_FORUM_KEY)),
+ currentPage //currently selected page being displayed, first page by default
+ ) {
+
+ protected Collection initializePage() {
+
+ int beginIndex = this.getBeginIndex();
+ int endIndex = this.getEndIndex();
+ int totalEntries = this.getNumberOfEntries();
+
+ //reset the page navigation if the start cursor is outside the range (both forward and backward)
+ if(beginIndex >= totalEntries || beginIndex < 0)
+ {
+ this.setCurrentPage(0); //go to the first page
+ beginIndex = this.getBeginIndex();
+ endIndex = this.getEndIndex();
+ }
+
+ try {
+ return fm.findTopicsDesc(forum,
+ Constants.POST_NORMAL,
+ beginIndex,
+ endIndex);
+ } catch (ModuleException e) {
+ JSFUtil.handleException(e);
+ }
+ return new ArrayList();
+
+ }
+
+ };
+
+ this.page = this.pageNavigator.getPage();
}
private void setWarnBundleMessage(String bundleKey) {
Modified: labs/jbossforums/branches/forums22/forums/src/main/org/jboss/portlet/forums/ui/view/PageNavigator.java
===================================================================
--- labs/jbossforums/branches/forums22/forums/src/main/org/jboss/portlet/forums/ui/view/PageNavigator.java 2006-11-15 02:52:06 UTC (rev 7602)
+++ labs/jbossforums/branches/forums22/forums/src/main/org/jboss/portlet/forums/ui/view/PageNavigator.java 2006-11-15 02:58:31 UTC (rev 7603)
@@ -29,8 +29,9 @@
* Created on May 11, 2006
*
* @author <a href="mailto:sohil.shah at jboss.com">Sohil Shah</a>
+ * @author <a href="mailto:ryszard.kozmik at jboss.com">Ryszard Kozmik</a>
*/
-public class PageNavigator implements Serializable
+public abstract class PageNavigator implements Serializable
{
/**
*
@@ -38,38 +39,48 @@
private int totalPages = 0;
private int pageSize = 0;
private int currentPage = 0;
- private Object[] entries = null;
+ private int numberOfEntries=0;
+ private Collection page = null;
/**
*
*
*/
- public PageNavigator(Object[] entries,int pageSize,int currentPage)
+ public PageNavigator(int numberOfEntries,int pageSize,int currentPage)
{
- if(entries==null)
+ if(numberOfEntries<0)
{
- throw new IllegalStateException("PageNavigator cannot be initialized with a null set of entries");
+ throw new IllegalStateException("PageNavigator cannot be initialized for negative number of entries");
}
this.pageSize = pageSize;
this.currentPage = currentPage;
- int totalEntries = 0;
- if(entries!=null)
- {
- this.entries = entries;
- totalEntries = this.entries.length;
- }
+ this.numberOfEntries = numberOfEntries;
-
//calculate the totalNumberofPages that will be made
- double totalDbl = totalEntries;
double pageSizeDbl = this.pageSize;
- double pageCountDbl = totalDbl/pageSizeDbl;
- this.totalPages = (int)Math.ceil(pageCountDbl);
+ double pageCountDbl = numberOfEntries/pageSizeDbl;
+ this.totalPages = (int)Math.ceil(pageCountDbl);
+
+ this.page = initializePage();
}
/**
+ * Every non-abstract class extending this class will have to implement this method
+ * and initialize page with objects.
+ */
+ protected abstract Collection initializePage();
+
+ /**
+ *
*
+ */
+ public int getNumberOfEntries() {
+ return this.numberOfEntries;
+ }
+
+ /**
+ *
*
*/
public int getTotalPages()
@@ -109,15 +120,10 @@
int endIndex = 0;
endIndex = this.getBeginIndex() + this.pageSize;
- int totalEntries = 0;
- if(this.entries!=null)
+ if(endIndex >= this.numberOfEntries)
{
- totalEntries = this.entries.length;
+ endIndex = this.numberOfEntries;
}
- if(endIndex >= totalEntries)
- {
- endIndex = totalEntries;
- }
return endIndex;
}
@@ -128,31 +134,10 @@
*/
public Collection getPage()
{
- Collection page = new ArrayList();
-
- int beginIndex = this.getBeginIndex();
- int endIndex = this.getEndIndex();
- int totalEntries = 0;
- if(this.entries!=null)
- {
- totalEntries = this.entries.length;
+ if (this.page==null) {
+ return new ArrayList();
}
-
- //reset the page navigation if the start cursor is outside the range (both forward and backward)
- if(beginIndex >= totalEntries || beginIndex < 0)
- {
- this.setCurrentPage(0); //go to the first page
- beginIndex = this.getBeginIndex();
- endIndex = this.getEndIndex();
- }
-
- //get the entries for this page
- for(int i=beginIndex;i<endIndex;i++)
- {
- page.add(this.entries[i]);
- }
-
- return page;
+ return this.page;
}
@@ -187,7 +172,7 @@
{
int pageAfterAdd = 0;
- double totalDbl = this.entries.length+1;
+ double totalDbl = this.numberOfEntries+1;
double pageSizeDbl = this.pageSize;
double pageCountDbl = totalDbl/pageSizeDbl;
pageAfterAdd = ((int)Math.ceil(pageCountDbl))-1;
Modified: labs/jbossforums/branches/forums22/forums/src/main/org/jboss/portlet/forums/ui/view/ViewForum.java
===================================================================
--- labs/jbossforums/branches/forums22/forums/src/main/org/jboss/portlet/forums/ui/view/ViewForum.java 2006-11-15 02:52:06 UTC (rev 7602)
+++ labs/jbossforums/branches/forums22/forums/src/main/org/jboss/portlet/forums/ui/view/ViewForum.java 2006-11-15 02:58:31 UTC (rev 7603)
@@ -160,11 +160,11 @@
stickyThreads = new ArrayList();
try {
//ForumsModule fm = this.getForumsModule();
- stickyThreads = findTopics(forum,
+ stickyThreads = BaseController.getForumsModule().findTopicsDesc(forum,
Constants.POST_STICKY,
-1,
Integer.parseInt(this.userPreferences.getPreference(
- Constants.TOPICS_FORUM_KEY)),"desc");
+ Constants.TOPICS_FORUM_KEY)));
} catch (Exception e) {
JSFUtil.handleException(e);
}
@@ -189,11 +189,11 @@
}
boolean present = false;
try {
- stickyThreads = findTopics(forum,
+ stickyThreads = BaseController.getForumsModule().findTopicsDesc(forum,
Constants.POST_STICKY,
-1,
Integer.parseInt(this.userPreferences.getPreference(
- Constants.TOPICS_FORUM_KEY)),"desc");
+ Constants.TOPICS_FORUM_KEY)));
if (stickyThreads!=null && stickyThreads.size()>0) {
present = true;
}
@@ -246,58 +246,9 @@
{
this.userPreferences = userPreferences;
}
- //-------------------------------------------------------------------------------------------------------------------------------------
+ //-------------------------------------------------------------------------------------------------------------------------------------
/**
- *
- * TODO: THIS METHOD IS IMPORTED FROM FORUMSMODULE AND MUST BE MOVED THERE BACK
- * SINCE IT CONTAINS SERIOUS MISTAKE IN FORUMSMODULE, IT IS HERE FOR A MOMENT
- * AND WILL BE MOVED AFTER 1.0 RELEASE
- *
- * @param forum
- * @param type
- * @param start
- * @param perPage
- * @param order
- * @return
- * @throws ModuleException
- */
- private List findTopics(Forum forum,
- int type,
- int start,
- int perPage,
- String order)
- throws ModuleException
- {
- try
- {
- Session session = this.getForumsModule().getHibernate().getSessionFactory().getCurrentSession();
- Query query =
- session.createQuery("from TopicImpl as t " +
- "join fetch t.poster " +
- "where t.forum = :forumid " +
- "and t.type = :type " +
- "order by t.lastPostDate " + order);
- query.setFirstResult(start);
- query.setMaxResults(perPage);
- query.setString("forumid", "" + forum.getId());
- query.setString("type", "" + type);
- List list = query.list();
- return list;
- }
- catch (HibernateException e)
- {
- String message = "Cannot find topics";
- throw new ModuleException(message, e);
- } catch (Exception e) {
- JSFUtil.handleException(e);
- String message = "Error while using ForumsModule.";
- throw new ModuleException(message, e);
- }
- }
-
-
- /**
*
* @author sshah
*/
@@ -329,71 +280,106 @@
*
*
*/
- private void execute() throws Exception
- {
- //parse the input parameters
- String page = ForumUtil.getParameter(Constants.p_page);
- int forumId = -1;
- String f = ForumUtil.getParameter(Constants.p_forumId);
- if(f!=null && f.trim().length()>0)
- {
- forumId = Integer.parseInt(f);
- }
-
- //grab the data to be displayed for this page
- if(forumId!=-1)
- {
- //setup the business objects like the forum, topics etc that will be displayed
- this.forum = BaseController.getForumsModule().findForumById(new Integer(forumId));
-
- Object[] topicObjects = findTopics(forum,
- Constants.POST_NORMAL,
- -1,
- Integer.MAX_VALUE,"desc").toArray();
-
- //setup the pageNavigator for this forum
- this.pageNavigator = new PageNavigator(
- topicObjects, //total number of entries to be split up into pages
- Integer.parseInt(this.userPreferences.getPreference(Constants.TOPICS_FORUM_KEY)),
- 0 //currently selected page being displayed, first page by default
- );
-
- if(page!=null && page.trim().length()>0)
- {
- //setup the page data
- this.pageNavigator.setCurrentPage(Integer.parseInt(page));
- }
- this.page = this.pageNavigator.getPage();
-
+ private void execute() throws Exception
+ {
+ //parse the input parameters
+ String page = ForumUtil.getParameter(Constants.p_page);
+ int forumId = -1;
+ String f = ForumUtil.getParameter(Constants.p_forumId);
+ if(f!=null && f.trim().length()>0)
+ {
+ forumId = Integer.parseInt(f);
+ }
+
+ // ForumsModule is stored as a final variable so that anonymous class could use it.
+ final ForumsModule fm = BaseController.getForumsModule();
+
+ //grab the data to be displayed for this page
+ if(forumId!=-1)
+ {
+ //setup the business objects like the forum, topics etc that will be displayed
+ this.forum = fm.findForumById(new Integer(forumId));
+
+ int pageNumber = 0;
+
+ if(page!=null && page.trim().length()>0)
+ {
+ //setup the page data
+ pageNumber = Integer.parseInt(page);
+ }
+
+ //setup the pageNavigator for this forum
+ this.pageNavigator = new PageNavigator(
+ forum.getTopicCount(), //total number of entries to be split up into pages
+ Integer.parseInt(this.userPreferences.getPreference(Constants.TOPICS_FORUM_KEY)),
+ pageNumber //currently selected page being displayed, first page by default
+ ) {
+
+ protected Collection initializePage() {
+
+ int beginIndex = this.getBeginIndex();
+ int endIndex = this.getEndIndex();
+ int totalEntries = this.getNumberOfEntries();
+
+ //reset the page navigation if the start cursor is outside the range (both forward and backward)
+ if(beginIndex >= totalEntries || beginIndex < 0)
+ {
+ this.setCurrentPage(0); //go to the first page
+ beginIndex = this.getBeginIndex();
+ endIndex = this.getEndIndex();
+ }
+
+ try {
+ return fm.findTopicsDesc(forum,
+ Constants.POST_NORMAL,
+ beginIndex,
+ endIndex);
+ } catch (ModuleException e) {
+ JSFUtil.handleException(e);
+ }
+ return new ArrayList();
+
+ }
+
+ };
+
+ this.page = this.pageNavigator.getPage();
+
+ // Getting sticky topics for this page
+ Collection stickies = getStickyThreads();
+
+ // Getting announcements
+ Collection announcements = getAnnouncements();
+
+ Collection listOfTopics = new LinkedList();
+
+ listOfTopics.addAll(stickies);
+ listOfTopics.addAll(announcements);
+ listOfTopics.addAll(this.page);
+
// Getting sticky topics for this page
- Collection stickies = getStickyThreads();
-
- // Getting announcements
- Collection announcements = getAnnouncements();
-
- Collection listOfTopics = new LinkedList();
-
- listOfTopics.addAll(stickies);
- listOfTopics.addAll(announcements);
- listOfTopics.addAll(this.page);
-
- // Getting lastPosts for all topics
- this.topicLastPosts = BaseController.getForumsModule().findLastPostsOfTopics(listOfTopics);
-
- // setup dummy pageNavigators for all topics being displayed for topic minipaging
- for(Iterator itr=listOfTopics.iterator();itr.hasNext();)
- {
- Topic cour = (Topic)itr.next();
- if(cour.getReplies()>0)
- {
- PageNavigator topicNav = new PageNavigator(new Object[cour.getReplies()+1],
- Integer.parseInt(this.userPreferences.getPreference(Constants.POSTS_TOPIC_KEY)), //this is user's posts per page preference
- 0 //current page of the navigator
- );
- this.topicNavigator.put(cour.getId(),topicNav);
- }
- }
- }
- }
+ this.topicLastPosts = fm.findLastPostsOfTopics(listOfTopics);
+
+ // setup dummy pageNavigators for all topics being displayed for topic minipaging
+ for(Iterator itr=listOfTopics.iterator();itr.hasNext();)
+ {
+ Topic cour = (Topic)itr.next();
+ if(cour.getReplies()>0)
+ {
+ PageNavigator topicNav = new PageNavigator(cour.getReplies()+1,
+ Integer.parseInt(this.userPreferences.getPreference(Constants.POSTS_TOPIC_KEY)), //this is user's posts per page preference
+ 0 //current page of the navigator
+ ) {
+
+ protected Collection initializePage() {
+ return null;
+ }
+
+ };
+ this.topicNavigator.put(cour.getId(),topicNav);
+ }
+ }
+ }
+ }
//-------------------------------------------------------------------------------------------------------------------------------------
}
Modified: labs/jbossforums/branches/forums22/forums/src/main/org/jboss/portlet/forums/ui/view/ViewTopic.java
===================================================================
--- labs/jbossforums/branches/forums22/forums/src/main/org/jboss/portlet/forums/ui/view/ViewTopic.java 2006-11-15 02:52:06 UTC (rev 7602)
+++ labs/jbossforums/branches/forums22/forums/src/main/org/jboss/portlet/forums/ui/view/ViewTopic.java 2006-11-15 02:58:31 UTC (rev 7603)
@@ -26,6 +26,8 @@
import java.util.Collection;
import java.util.Iterator;
+import org.jboss.portal.core.modules.ModuleException;
+import org.jboss.portlet.forums.ForumsModule;
import org.jboss.portlet.forums.model.Category;
import org.jboss.portlet.forums.model.Topic;
import org.jboss.portlet.forums.ui.BaseController;
@@ -192,18 +194,17 @@
topicId = Integer.parseInt(t);
}
+ // ForumsModule is stored as a final variable so that anonymous class could use it.
+ final ForumsModule fm = BaseController.getForumsModule();
+
//process the topic information
if (topicId != -1) {
- this.topic =
- BaseController.getForumsModule().findTopicById(new Integer(topicId));
+ this.topic = fm.findTopicById(new Integer(topicId));
topic.setViewCount(topic.getViewCount()+1);
- Collection posts = null;
- if (this.userPreferences.getPreference(Constants.POST_ORDER_KEY).compareToIgnoreCase("ascending")==0) {
- posts = this.getForumsModule().findPostsByTopicIdAscFetchAttachmentsAndPosters(topic.getId(),0,Integer.MAX_VALUE);
- } else {
- posts = this.getForumsModule().findPostsByTopicIdDescFetchAttachmentsAndPosters(topic.getId(),0,Integer.MAX_VALUE);
- }
- if (posts != null && posts.size() > 0) {
+ String postOrder = this.userPreferences.getPreference(Constants.POST_ORDER_KEY);
+ int postCount = topic.getReplies()+1;
+
+ if (postCount > 0) {
int currentPage = 0;
if (page != null && page.trim().length() > 0) {
//setup the page data
@@ -212,13 +213,77 @@
//setup the pageNavigator
//total number of entries to be split up into pages
- //currently selected page being displayed, first page by default
+ //currently selected page being displayed, first page by default
+ if (postOrder.compareToIgnoreCase("ascending")==0) {
this.pageNavigator =
- new PageNavigator(posts.toArray(), Integer.parseInt(this.userPreferences.getPreference(Constants.POSTS_TOPIC_KEY)),
- currentPage);
+ new PageNavigator(postCount,
+ Integer.parseInt(this.userPreferences.getPreference(Constants.POSTS_TOPIC_KEY)),
+ currentPage) {
+ protected Collection initializePage() {
+
+ int beginIndex = this.getBeginIndex();
+ int endIndex = this.getEndIndex();
+ int totalEntries = this.getNumberOfEntries();
+
+ //reset the page navigation if the start cursor is outside the range (both forward and backward)
+ if(beginIndex >= totalEntries || beginIndex < 0)
+ {
+ this.setCurrentPage(0); //go to the first page
+ beginIndex = this.getBeginIndex();
+ endIndex = this.getEndIndex();
+ }
+
+ try {
+ return fm.findPostIdsAsc(topic.getId(),
+ beginIndex,
+ endIndex);
+ } catch (ModuleException e) {
+ JSFUtil.handleException(e);
+ }
+ return new ArrayList();
+ }
+ };
+
+ Collection pagePostIds = this.pageNavigator.getPage();
+ this.page = fm.findPostsByIdsAscFetchAttachmentsAndPosters(pagePostIds);
+
+ } else {
+
+ this.pageNavigator =
+ new PageNavigator(postCount,
+ Integer.parseInt(this.userPreferences.getPreference(Constants.POSTS_TOPIC_KEY)),
+ currentPage) {
- this.page = this.pageNavigator.getPage();
+ protected Collection initializePage() {
+
+ int beginIndex = this.getBeginIndex();
+ int endIndex = this.getEndIndex();
+ int totalEntries = this.getNumberOfEntries();
+
+ //reset the page navigation if the start cursor is outside the range (both forward and backward)
+ if(beginIndex >= totalEntries || beginIndex < 0)
+ {
+ this.setCurrentPage(0); //go to the first page
+ beginIndex = this.getBeginIndex();
+ endIndex = this.getEndIndex();
+ }
+
+ try {
+ return fm.findPostIdsDesc(topic.getId(),
+ beginIndex,
+ endIndex);
+ } catch (ModuleException e) {
+ JSFUtil.handleException(e);
+ }
+ return new ArrayList();
+ }
+ };
+
+ Collection pagePostIds = this.pageNavigator.getPage();
+ this.page = fm.findPostsByIdsDescFetchAttachmentsAndPosters(pagePostIds);
+
+ }
}
}
}
Modified: labs/jbossforums/branches/forums22/forums/src/resources/portal-forums-sar/conf/hibernate/hibernate.cfg.xml
===================================================================
--- labs/jbossforums/branches/forums22/forums/src/resources/portal-forums-sar/conf/hibernate/hibernate.cfg.xml 2006-11-15 02:52:06 UTC (rev 7602)
+++ labs/jbossforums/branches/forums22/forums/src/resources/portal-forums-sar/conf/hibernate/hibernate.cfg.xml 2006-11-15 02:58:31 UTC (rev 7603)
@@ -6,7 +6,7 @@
<session-factory>
<property name="connection.datasource">java:@portal.datasource.name@</property>
<property name="hibernate.cache.use_query_cache">true</property>
- <property name="show_sql">false</property>
+ <property name="show_sql">true</property>
<!-- Force the dialect instead of using autodetection -->
<!--
Modified: labs/jbossforums/branches/forums22/forums/src/resources/portal-forums-war/WEB-INF/forums-config.xml
===================================================================
--- labs/jbossforums/branches/forums22/forums/src/resources/portal-forums-war/WEB-INF/forums-config.xml 2006-11-15 02:52:06 UTC (rev 7602)
+++ labs/jbossforums/branches/forums22/forums/src/resources/portal-forums-war/WEB-INF/forums-config.xml 2006-11-15 02:58:31 UTC (rev 7603)
@@ -8,11 +8,11 @@
<!-- general application configuration -->
<application>
<!-- jbossportal-facelets integration -->
- <property-resolver>org.jboss.portal.faces.el.DelegatingPropertyResolver</property-resolver>
- <view-handler>com.sun.facelets.FaceletPortletViewHandler</view-handler>
+ <!--property-resolver>org.jboss.portal.faces.el.DelegatingPropertyResolver</property-resolver>
+ <view-handler>com.sun.facelets.FaceletPortletViewHandler</view-handler-->
<!-- standalone facelets integration -->
- <!--view-handler>com.sun.facelets.FaceletViewHandler</view-handler-->
+ <view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
<!-- custom action listener with integrated authorization checking -->
<action-listener>org.jboss.portlet.forums.auth.AuthorizationListener</action-listener>
@@ -31,10 +31,10 @@
remove this in portal-environment. This is needed only for managing a transaction in standalone mode.
in portal mode, the portal takes care of this
-->
- <!--lifecycle>
+ <lifecycle>
<phase-listener>org.jboss.portlet.forums.ui.event.BeginTransactionListener</phase-listener>
<phase-listener>org.jboss.portlet.forums.ui.event.EndTransactionListener</phase-listener>
- </lifecycle-->
+ </lifecycle>
<!-- configuration for the shared EmptyController -->
More information about the jboss-svn-commits
mailing list