KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mvnforum > common > StatisticsUtil


1 /*
2  * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/common/StatisticsUtil.java,v 1.9 2006/04/14 17:05:26 minhnn Exp $
3  * $Author: minhnn $
4  * $Revision: 1.9 $
5  * $Date: 2006/04/14 17:05:26 $
6  *
7  * ====================================================================
8  *
9  * Copyright (C) 2002-2006 by MyVietnam.net
10  *
11  * All copyright notices regarding mvnForum MUST remain
12  * intact in the scripts and in the outputted HTML.
13  * The "powered by" text/logo with a link back to
14  * http://www.mvnForum.com and http://www.MyVietnam.net in
15  * the footer of the pages MUST remain visible when the pages
16  * are viewed on the internet or intranet.
17  *
18  * This program is free software; you can redistribute it and/or modify
19  * it under the terms of the GNU General Public License as published by
20  * the Free Software Foundation; either version 2 of the License, or
21  * any later version.
22  *
23  * This program is distributed in the hope that it will be useful,
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26  * GNU General Public License for more details.
27  *
28  * You should have received a copy of the GNU General Public License
29  * along with this program; if not, write to the Free Software
30  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31  *
32  * Support can be obtained from support forums at:
33  * http://www.mvnForum.com/mvnforum/index
34  *
35  * Correspondence and Marketing Questions can be sent to:
36  * info at MyVietnam net
37  *
38  * @author: Minh Nguyen
39  */

40 package com.mvnforum.common;
41
42 import java.sql.Timestamp JavaDoc;
43 import java.util.Collection JavaDoc;
44 import java.util.Iterator JavaDoc;
45
46 import com.mvnforum.MVNForumConfig;
47 import com.mvnforum.db.DAOFactory;
48 import com.mvnforum.db.PostBean;
49 import net.myvietnam.mvncore.exception.*;
50
51 public class StatisticsUtil {
52
53     private StatisticsUtil() {
54     }
55
56     /**
57      * This method is used to update the thread statistics
58      * It updates these information: threadReplyCount, lastPostMemberName, threadLastPostDate
59      *
60      * @param threadID the thread to update its statistic
61      * @throws ObjectNotFoundException
62      * @throws java.lang.IllegalArgumentException
63      * @throws DatabaseException
64      * @throws AssertionException
65      */

66     public static void updateThreadStatistics(int threadID)
67         throws ObjectNotFoundException, IllegalArgumentException JavaDoc, DatabaseException, AssertionException {
68
69         int threadReplyCount = DAOFactory.getPostDAO().getNumberOfEnablePosts_inThread(threadID) - 1;
70         DAOFactory.getThreadDAO().updateReplyCount(threadID, threadReplyCount);
71
72         int attachCountInThread = DAOFactory.getAttachmentDAO().getNumberOfAttachments_inThread(threadID);
73         DAOFactory.getThreadDAO().updateThreadAttachCount(threadID, attachCountInThread);
74
75         Collection JavaDoc lastPostInThread = DAOFactory.getPostDAO().getLastEnablePosts_inThread_limit(threadID, 1);
76         Iterator JavaDoc iteratorInThread = lastPostInThread.iterator();
77         if (iteratorInThread.hasNext()) {
78             PostBean lastPostBeanInThread = (PostBean)iteratorInThread.next();
79             String JavaDoc lastPostMemberName = lastPostBeanInThread.getMemberName();
80             Timestamp JavaDoc threadLastPostDate = lastPostBeanInThread.getPostCreationDate();
81             try {
82                 DAOFactory.getThreadDAO().updateLastPostMemberName(threadID, lastPostMemberName);
83             } catch (ForeignKeyNotFoundException ex) {
84                 throw new AssertionException("Assertion: cannot update LastPostMemberName of Thread in StatisticsUtil.updateThreadStatistics");
85             }
86             DAOFactory.getThreadDAO().updateLastPostDate(threadID, threadLastPostDate);
87         }
88     }
89
90     /**
91      * This method is used to update the forum statistics
92      * It updates these information: forumThreadCount, forumPostCount, lastPostMemberName, forumLastPostDate
93      *
94      * @param forumID the forum to update its statistics
95      * @throws java.lang.IllegalArgumentException
96      * @throws ObjectNotFoundException
97      * @throws DatabaseException
98      * @throws AssertionException
99      */

100     public static void updateForumStatistics(int forumID)
101         throws ObjectNotFoundException, DatabaseException, AssertionException {
102
103         int forumThreadCount = DAOFactory.getThreadDAO().getNumberOfEnableThreads_inForum(forumID);
104         int forumPostCount = DAOFactory.getPostDAO().getNumberOfEnablePosts_inForum(forumID);
105
106         // because the disable thread has first post in enable, so the
107
// correct number of posts are the enable posts - disable threads
108
int forumDisableThreadCount = DAOFactory.getThreadDAO().getNumberOfDisableThreads_inForum(forumID);
109         forumPostCount -= forumDisableThreadCount;
110
111         DAOFactory.getForumDAO().updateStatistics(forumID, forumThreadCount, forumPostCount);
112
113         Collection JavaDoc lastPostInForum = DAOFactory.getPostDAO().getLastEnablePosts_inForum_limit(forumID, 1);
114         Iterator JavaDoc iteratorInForum = lastPostInForum.iterator();
115         if (iteratorInForum.hasNext()) {
116             PostBean lastPostBeanInForum = (PostBean)iteratorInForum.next();
117             String JavaDoc lastPostMemberName = lastPostBeanInForum.getMemberName();
118             Timestamp JavaDoc forumLastPostDate = lastPostBeanInForum.getPostCreationDate();
119             try {
120                 DAOFactory.getForumDAO().updateLastPostMemberName(forumID, lastPostMemberName);
121             } catch (ForeignKeyNotFoundException ex) {
122                 throw new AssertionException("Assertion: cannot update LastPostMemberName of Forum in StatisticsUtil.updateForumStatistics");
123             }
124             DAOFactory.getForumDAO().updateLastPostDate(forumID, forumLastPostDate);
125         }
126     }
127
128     public static void updateMemberStatistics(int memberID)
129         throws DatabaseException, AssertionException, ObjectNotFoundException {
130
131         int memberPostCount = DAOFactory.getPostDAO().getNumberOfPosts_inMember(memberID);
132         if ( MVNForumConfig.getEnablePortlet() == false) {
133             DAOFactory.getMemberDAO().updatePostCount(memberID, memberPostCount);
134         }
135     }
136
137 }
138
Popular Tags