001: /*
002: * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/common/PrivateMessageUtil.java,v 1.8 2007/10/09 11:09:16 lexuanttkhtn Exp $
003: * $Author: lexuanttkhtn $
004: * $Revision: 1.8 $
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: * @author: Mai Nguyen
040: */
041: package com.mvnforum.common;
042:
043: import java.util.*;
044:
045: import com.mvnforum.db.*;
046: import net.myvietnam.mvncore.exception.DatabaseException;
047: import net.myvietnam.mvncore.exception.ObjectNotFoundException;
048: import org.apache.commons.logging.Log;
049: import org.apache.commons.logging.LogFactory;
050:
051: public class PrivateMessageUtil {
052:
053: private static Log log = LogFactory
054: .getLog(PrivateMessageUtil.class);
055:
056: private PrivateMessageUtil() {
057: }
058:
059: /**
060: * This is a utility method that should only called after all checking
061: * The caller should check existence of data and try to avoid the ObjectNotFoundException
062: *
063: * @param locale Locale
064: * @param messageID int
065: * @param memberID int
066: * @throws DatabaseException
067: * @throws ObjectNotFoundException
068: */
069: public static void deleteMessageInDatabase(int messageID,
070: int memberID) throws DatabaseException,
071: ObjectNotFoundException {
072:
073: log.debug("Delete Private Message with MessageID = "
074: + messageID);
075:
076: // call this first to check the valid of memberID
077: DAOFactory.getMessageDAO().deleteMessage(messageID, memberID);
078:
079: // the call this after
080: DAOFactory.getPmAttachMessageDAO().delete_inMessage(messageID);
081: }
082:
083: /**
084: * This is a utility method that should only called after all checking
085: * The caller should check existence of data and try to avoid the ObjectNotFoundException
086: *
087: * @param locale Locale
088: * @param folderName String
089: * @param memberID int
090: * @throws ObjectNotFoundException
091: * @throws DatabaseException
092: */
093: public static void deleteMessageFolderInDatabase(String folderName,
094: int memberID) throws ObjectNotFoundException,
095: DatabaseException {
096:
097: // Delete the MessagePmAttach
098: Collection messageBeans = DAOFactory
099: .getMessageDAO()
100: .getAllMessages_inMember_inFolder_withSortSupport_limit(
101: memberID, folderName, 0, 10000,
102: "MessageCreationDate", "ASC");
103: for (Iterator iter = messageBeans.iterator(); iter.hasNext();) {
104: MessageBean messageBean = (MessageBean) iter.next();
105:
106: DAOFactory.getPmAttachMessageDAO().delete_inMessage(
107: messageBean.getMessageID());
108: }
109:
110: // Then delete all messages belong to this folder
111: DAOFactory.getMessageDAO()
112: .deleteMessages_inFolderName_inMember(folderName,
113: memberID);
114:
115: // Finally delete a folder name
116: DAOFactory.getMessageFolderDAO().delete(folderName, memberID);
117: }
118:
119: public static void deleteMessageFoldersInDatabase(int memberID)
120: throws ObjectNotFoundException, DatabaseException {
121:
122: Collection folderBeans = DAOFactory.getMessageFolderDAO()
123: .getMessageFolders_inMember(memberID);
124: for (Iterator iter = folderBeans.iterator(); iter.hasNext();) {
125: MessageFolderBean messageFolderBean = (MessageFolderBean) iter
126: .next();
127:
128: deleteMessageFolderInDatabase(messageFolderBean
129: .getFolderName(), memberID);
130: }
131: }
132: }
|