?? statisticsutil.java
字號:
/*
* $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/common/StatisticsUtil.java,v 1.2 2004/04/06 19:38:01 minhnn Exp $
* $Author: minhnn $
* $Revision: 1.2 $
* $Date: 2004/04/06 19:38:01 $
*
* ====================================================================
*
* Copyright (C) 2002-2004 by MyVietnam.net
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or any later version.
*
* All copyright notices regarding mvnForum MUST remain intact
* in the scripts and in the outputted HTML.
* The "powered by" text/logo with a link back to
* http://www.mvnForum.com and http://www.MyVietnam.net in the
* footer of the pages MUST remain visible when the pages
* are viewed on the internet or intranet.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* Support can be obtained from support forums at:
* http://www.mvnForum.com/mvnforum/index
*
* Correspondence and Marketing Questions can be sent to:
* info@MyVietnam.net
*
* @author: Minh Nguyen minhnn@MyVietnam.net
*/
package com.mvnforum.common;
import java.sql.Timestamp;
import java.util.Collection;
import java.util.Iterator;
import com.mvnforum.db.DAOFactory;
import com.mvnforum.db.PostBean;
import net.myvietnam.mvncore.exception.*;
import net.myvietnam.mvncore.exception.AssertionException;
import net.myvietnam.mvncore.exception.ObjectNotFoundException;
public class StatisticsUtil {
private StatisticsUtil() {
}
/**
* This method is used to update the thread statistics
* It updates these information: threadReplyCount, lastPostMemberName, threadLastPostDate
*
* @param threadID the thread to update its statistic
* @throws ObjectNotFoundException
* @throws java.lang.IllegalArgumentException
* @throws DatabaseException
* @throws AssertionException
*/
public static void updateThreadStatistics(int threadID)
throws ObjectNotFoundException, IllegalArgumentException, DatabaseException, AssertionException {
int threadReplyCount = DAOFactory.getPostDAO().getNumberOfEnablePosts_inThread(threadID) - 1;
DAOFactory.getThreadDAO().updateReplyCount(threadID, threadReplyCount);
Collection lastPostInThread = DAOFactory.getPostDAO().getLastEnablePosts_inThread_limit(threadID, 1);
Iterator iteratorInThread = lastPostInThread.iterator();
if (iteratorInThread.hasNext()) {
PostBean lastPostBeanInThread = (PostBean)iteratorInThread.next();
String lastPostMemberName = lastPostBeanInThread.getMemberName();
Timestamp threadLastPostDate = lastPostBeanInThread.getPostCreationDate();
try {
DAOFactory.getThreadDAO().updateLastPostMemberName(threadID, lastPostMemberName);
} catch (ForeignKeyNotFoundException ex) {
throw new AssertionException("Assertion: cannot update LastPostMemberName of Thread in StatisticsUtil.updateThreadStatistics");
}
DAOFactory.getThreadDAO().updateLastPostDate(threadID, threadLastPostDate);
}
}
/**
* This method is used to update the forum statistics
* It updates these information: forumThreadCount, forumPostCount, lastPostMemberName, forumLastPostDate
*
* @param forumID the forum to update its statistics
* @throws java.lang.IllegalArgumentException
* @throws ObjectNotFoundException
* @throws DatabaseException
* @throws AssertionException
*/
public static void updateForumStatistics(int forumID)
throws ObjectNotFoundException, DatabaseException, AssertionException {
int forumThreadCount = DAOFactory.getThreadDAO().getNumberOfEnableBeans_inForum(forumID);
int forumPostCount = DAOFactory.getPostDAO().getNumberOfEnablePosts_inForum(forumID);
// because the disable thread has first post in enable, so the
// correct number of posts are the enable posts - disable threads
int forumDisableThreadCount = DAOFactory.getThreadDAO().getNumberOfDisableBeans_inForum(forumID);
forumPostCount -= forumDisableThreadCount;
DAOFactory.getForumDAO().updateStatistics(forumID, forumThreadCount, forumPostCount);
Collection lastPostInForum = DAOFactory.getPostDAO().getLastEnablePosts_inForum_limit(forumID, 1);
Iterator iteratorInForum = lastPostInForum.iterator();
if (iteratorInForum.hasNext()) {
PostBean lastPostBeanInForum = (PostBean)iteratorInForum.next();
String lastPostMemberName = lastPostBeanInForum.getMemberName();
Timestamp forumLastPostDate = lastPostBeanInForum.getPostCreationDate();
try {
DAOFactory.getForumDAO().updateLastPostMemberName(forumID, lastPostMemberName);
} catch (ForeignKeyNotFoundException ex) {
throw new AssertionException("Assertion: cannot update LastPostMemberName of Forum in StatisticsUtil.updateForumStatistics");
}
DAOFactory.getForumDAO().updateLastPostDate(forumID, forumLastPostDate);
}
}
public static void updateMemberStatistics(int memberID)
throws DatabaseException, AssertionException, ObjectNotFoundException {
int memberPostCount = DAOFactory.getPostDAO().getNumberOfPosts_inMember(memberID);
DAOFactory.getMemberDAO().updatePostCount(memberID, memberPostCount);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -