001: /*
002: * $Header: /cvsroot/mvnforum/mvnforum/contrib/phpbb2mvnforum/src/org/mvnforum/phpbb2mvnforum/db/jdbc/MessageDAOImplJDBC.java,v 1.3 2007/01/15 10:27:12 dungbtm Exp $
003: * $Author: dungbtm $
004: * $Revision: 1.3 $
005: * $Date: 2007/01/15 10:27:12 $
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:
039: */
040: package org.mvnforum.phpbb2mvnforum.db.jdbc;
041:
042: import java.sql.Connection;
043: import java.sql.PreparedStatement;
044: import java.sql.ResultSet;
045: import java.sql.SQLException;
046: import java.sql.Timestamp;
047:
048: import net.myvietnam.mvncore.exception.CreateException;
049: import net.myvietnam.mvncore.exception.DatabaseException;
050: import net.myvietnam.mvncore.exception.DuplicateKeyException;
051: import net.myvietnam.mvncore.exception.ObjectNotFoundException;
052:
053: import org.mvnforum.phpbb2mvnforum.db.MessageDAO;
054: import org.mvnforum.util.DBUtils;
055:
056: public class MessageDAOImplJDBC implements MessageDAO {
057:
058: public void findByPrimaryKey(int messageID)
059: throws ObjectNotFoundException, DatabaseException {
060:
061: Connection connection = null;
062: PreparedStatement statement = null;
063: ResultSet resultSet = null;
064: StringBuffer sql = new StringBuffer(512);
065: sql.append("SELECT MessageID");
066: sql.append(" FROM " + TABLE_NAME);
067: sql.append(" WHERE MessageID = ?");
068: try {
069: connection = DBUtils.getMvnConnection();
070: statement = connection.prepareStatement(sql.toString());
071: statement.setInt(1, messageID);
072: resultSet = statement.executeQuery();
073: if (!resultSet.next()) {
074: throw new ObjectNotFoundException(
075: "Cannot find the primary key (" + messageID
076: + ") in table 'message'.");
077: }
078: } catch (SQLException sqle) {
079: throw new DatabaseException(
080: "Error executing SQL in messageDAOImplJDBC.findByPrimaryKey.");
081: } finally {
082: DBUtils.closeResultSet(resultSet);
083: DBUtils.closeStatement(statement);
084: DBUtils.closeConnection(connection);
085: }
086: }
087:
088: /*
089: * Included columns: MessageID, FolderName, MemberID, MessageSenderID, MessageSenderName,
090: * MessageToList, MessageCcList, MessageBccList, MessageTopic, MessageBody,
091: * MessageType, MessageOption, MessageStatus, MessageReadStatus, MessageNotify,
092: * MessageIcon, MessageAttachCount, MessageIP, MessageCreationDate
093: * Excluded columns:
094: */
095: public int create(String folderName, int memberID,
096: int messageSenderID, String messageSenderName,
097: String messageToList, String messageCcList,
098: String messageBccList, String messageTopic,
099: String messageBody, int messageType, int messageOption,
100: int messageStatus, int messageReadStatus,
101: int messageNotify, String messageIcon,
102: int messageAttachCount, String messageIP,
103: Timestamp messageCreationDate) throws CreateException,
104: DatabaseException, DuplicateKeyException {
105:
106: Connection connection = null;
107: PreparedStatement statement = null;
108: StringBuffer sql = new StringBuffer(512);
109: sql
110: .append("INSERT INTO "
111: + TABLE_NAME
112: + " (FolderName, MemberID, MessageSenderID, MessageSenderName, MessageToList, MessageCcList, MessageBccList, MessageTopic, MessageBody, MessageType, MessageOption, MessageStatus, MessageReadStatus, MessageNotify, MessageIcon, MessageAttachCount, MessageIP, MessageCreationDate)");
113: sql
114: .append(" VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
115: try {
116: connection = DBUtils.getMvnConnection();
117: statement = connection.prepareStatement(sql.toString());
118:
119: statement.setString(1, folderName);
120: statement.setInt(2, memberID);
121: statement.setInt(3, messageSenderID);
122: statement.setString(4, messageSenderName);
123: statement.setString(5, messageToList);
124: statement.setString(6, messageCcList);
125: statement.setString(7, messageBccList);
126: statement.setString(8, messageTopic);
127: statement.setString(9, messageBody);
128: statement.setInt(10, messageType);
129: statement.setInt(11, messageOption);
130: statement.setInt(12, messageStatus);
131: statement.setInt(13, messageReadStatus);
132: statement.setInt(14, messageNotify);
133: statement.setString(15, messageIcon);
134: statement.setInt(16, messageAttachCount);
135: statement.setString(17, messageIP);
136: statement.setTimestamp(18, messageCreationDate);
137:
138: if (statement.executeUpdate() != 1) {
139: throw new CreateException(
140: "Error adding a row into table 'message'.");
141: }
142: return 0;
143: } catch (SQLException sqle) {
144: throw new DatabaseException(
145: "Error executing SQL in messageDAOImplJDBC.create.");
146: } finally {
147: DBUtils.closeStatement(statement);
148: DBUtils.closeConnection(connection);
149: }
150: }
151: }
|