001: /*
002: * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/common/StatisticsUtil.java,v 1.15 2007/10/09 11:09:16 lexuanttkhtn Exp $
003: * $Author: lexuanttkhtn $
004: * $Revision: 1.15 $
005: * $Date: 2007/10/09 11:09:16 $
006: *
007: * ====================================================================
008: *
009: * Copyright (C) 2002-2007 by MyVietnam.net
010: *
011: * All copyright notices regarding mvnForum MUST remain
012: * intact in the scripts and in the outputted HTML.
013: * The "powered by" text/logo with a link back to
014: * http://www.mvnForum.com and http://www.MyVietnam.net in
015: * the footer of the pages MUST remain visible when the pages
016: * are viewed on the internet or intranet.
017: *
018: * This program is free software; you can redistribute it and/or modify
019: * it under the terms of the GNU General Public License as published by
020: * the Free Software Foundation; either version 2 of the License, or
021: * any later version.
022: *
023: * This program is distributed in the hope that it will be useful,
024: * but WITHOUT ANY WARRANTY; without even the implied warranty of
025: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
026: * GNU General Public License for more details.
027: *
028: * You should have received a copy of the GNU General Public License
029: * along with this program; if not, write to the Free Software
030: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
031: *
032: * Support can be obtained from support forums at:
033: * http://www.mvnForum.com/mvnforum/index
034: *
035: * Correspondence and Marketing Questions can be sent to:
036: * info at MyVietnam net
037: *
038: * @author: Minh Nguyen
039: */
040: package com.mvnforum.common;
041:
042: import java.sql.Timestamp;
043: import java.util.Collection;
044: import java.util.Iterator;
045:
046: import net.myvietnam.mvncore.exception.*;
047: import net.myvietnam.mvncore.util.AssertionUtil;
048:
049: import com.mvnforum.db.DAOFactory;
050: import com.mvnforum.db.PostBean;
051:
052: public class StatisticsUtil {
053:
054: private StatisticsUtil() {
055: }
056:
057: /**
058: * This method is used to update the thread statistics
059: * It updates these information: threadReplyCount, lastPostMemberName, threadLastPostDate
060: *
061: * @param threadID the thread to update its statistic
062: * @throws ObjectNotFoundException
063: * @throws java.lang.IllegalArgumentException
064: * @throws DatabaseException
065: */
066: public static void updateThreadStatistics(int threadID)
067: throws ObjectNotFoundException, IllegalArgumentException,
068: DatabaseException {
069:
070: int threadReplyCount = DAOFactory.getPostDAO()
071: .getNumberOfEnablePosts_inThread(threadID) - 1;
072: DAOFactory.getThreadDAO().updateReplyCount(threadID,
073: threadReplyCount);
074:
075: int attachCountInThread = DAOFactory.getAttachmentDAO()
076: .getNumberOfAttachments_inThread(threadID);
077: DAOFactory.getThreadDAO().updateThreadAttachCount(threadID,
078: attachCountInThread);
079:
080: Collection lastPostInThread = DAOFactory.getPostDAO()
081: .getLastEnablePosts_inThread_limit(threadID, 1);
082: Iterator iteratorInThread = lastPostInThread.iterator();
083: if (iteratorInThread.hasNext()) {
084: PostBean lastPostBeanInThread = (PostBean) iteratorInThread
085: .next();
086: String lastPostMemberName = lastPostBeanInThread
087: .getMemberName();
088: Timestamp threadLastPostDate = lastPostBeanInThread
089: .getPostCreationDate();
090: try {
091: DAOFactory.getThreadDAO().updateLastPostMemberName(
092: threadID, lastPostMemberName);
093: } catch (ForeignKeyNotFoundException ex) {
094: AssertionUtil
095: .doAssert(
096: false,
097: "Assertion: cannot update LastPostMemberName of Thread in StatisticsUtil.updateThreadStatistics");
098: }
099: DAOFactory.getThreadDAO().updateLastPostDate(threadID,
100: threadLastPostDate);
101: }
102: }
103:
104: /**
105: * This method is used to update the forum statistics
106: * It updates these information: forumThreadCount, forumPostCount, lastPostMemberName, forumLastPostDate
107: *
108: * @param forumID the forum to update its statistics
109: * @throws java.lang.IllegalArgumentException
110: * @throws ObjectNotFoundException
111: * @throws DatabaseException
112: */
113: public static void updateForumStatistics(int forumID)
114: throws ObjectNotFoundException, DatabaseException {
115:
116: int forumThreadCount = DAOFactory.getThreadDAO()
117: .getNumberOfEnableThreads_inForum(forumID);
118: int forumPostCount = DAOFactory.getPostDAO()
119: .getNumberOfEnablePosts_inForum(forumID);
120:
121: // because the disable thread has first post in enable, so the
122: // correct number of posts are the enable posts - disable threads
123: int forumDisableThreadCount = DAOFactory.getThreadDAO()
124: .getNumberOfDisableThreads_inForum(forumID);
125: forumPostCount -= forumDisableThreadCount;
126:
127: DAOFactory.getForumDAO().updateStatistics(forumID,
128: forumThreadCount, forumPostCount);
129:
130: Collection lastPostInForum = DAOFactory.getPostDAO()
131: .getLastEnablePosts_inForum_limit(forumID, 1);
132: Iterator iteratorInForum = lastPostInForum.iterator();
133: if (iteratorInForum.hasNext()) {
134: PostBean lastPostBeanInForum = (PostBean) iteratorInForum
135: .next();
136: String lastPostMemberName = lastPostBeanInForum
137: .getMemberName();
138: Timestamp forumLastPostDate = lastPostBeanInForum
139: .getPostCreationDate();
140: try {
141: DAOFactory.getForumDAO().updateLastPostMemberName(
142: forumID, lastPostMemberName);
143: } catch (ForeignKeyNotFoundException ex) {
144: AssertionUtil
145: .doAssert(
146: false,
147: "Assertion: cannot update LastPostMemberName of Forum in StatisticsUtil.updateForumStatistics");
148: }
149: DAOFactory.getForumDAO().updateLastPostDate(forumID,
150: forumLastPostDate);
151: }
152: }
153:
154: public static void updateMemberStatistics(int memberID)
155: throws DatabaseException, ObjectNotFoundException {
156:
157: int memberPostCount = DAOFactory.getPostDAO()
158: .getNumberOfPosts_inMember(memberID);
159: if (DAOFactory.getMemberDAO().isSupportUpdatePostCount()) {
160: DAOFactory.getMemberDAO().updatePostCount(memberID,
161: memberPostCount);
162: }
163: }
164:
165: }
|