1 40 package com.mvnforum.common; 41 42 import java.sql.Timestamp ; 43 import java.util.Collection ; 44 import java.util.Iterator ; 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 66 public static void updateThreadStatistics(int threadID) 67 throws ObjectNotFoundException, IllegalArgumentException , 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 lastPostInThread = DAOFactory.getPostDAO().getLastEnablePosts_inThread_limit(threadID, 1); 76 Iterator iteratorInThread = lastPostInThread.iterator(); 77 if (iteratorInThread.hasNext()) { 78 PostBean lastPostBeanInThread = (PostBean)iteratorInThread.next(); 79 String lastPostMemberName = lastPostBeanInThread.getMemberName(); 80 Timestamp 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 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 int forumDisableThreadCount = DAOFactory.getThreadDAO().getNumberOfDisableThreads_inForum(forumID); 109 forumPostCount -= forumDisableThreadCount; 110 111 DAOFactory.getForumDAO().updateStatistics(forumID, forumThreadCount, forumPostCount); 112 113 Collection lastPostInForum = DAOFactory.getPostDAO().getLastEnablePosts_inForum_limit(forumID, 1); 114 Iterator iteratorInForum = lastPostInForum.iterator(); 115 if (iteratorInForum.hasNext()) { 116 PostBean lastPostBeanInForum = (PostBean)iteratorInForum.next(); 117 String lastPostMemberName = lastPostBeanInForum.getMemberName(); 118 Timestamp 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 |