001: /*
002: * $Header: /cvsroot/mvnforum/mvnforum/contrib/phpbb2mvnforum/src/org/mvnforum/phpbb2mvnforum/db/jdbc/MessageFolderDAOImplJDBC.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: import java.util.Collection;
048:
049: import org.mvnforum.util.DBUtils;
050:
051: import net.myvietnam.mvncore.exception.AssertionException;
052: import net.myvietnam.mvncore.exception.CreateException;
053: import net.myvietnam.mvncore.exception.DatabaseException;
054: import net.myvietnam.mvncore.exception.DuplicateKeyException;
055: import net.myvietnam.mvncore.exception.ForeignKeyNotFoundException;
056: import net.myvietnam.mvncore.exception.ObjectNotFoundException;
057:
058: import com.mvnforum.db.MessageFolderBean;
059: import com.mvnforum.db.MessageFolderDAO;
060:
061: public class MessageFolderDAOImplJDBC implements MessageFolderDAO {
062:
063: public void findByPrimaryKey(String folderName, int memberID)
064: throws ObjectNotFoundException, DatabaseException {
065:
066: Connection connection = null;
067: PreparedStatement statement = null;
068: ResultSet resultSet = null;
069: StringBuffer sql = new StringBuffer(512);
070: sql.append("SELECT FolderOrder");
071: sql.append(" FROM " + TABLE_NAME);
072: sql.append(" WHERE FolderName = ? AND MemberID = ?");
073: try {
074: connection = DBUtils.getMvnConnection();
075: statement = connection.prepareStatement(sql.toString());
076: statement.setString(1, folderName);
077: statement.setInt(2, memberID);
078: resultSet = statement.executeQuery();
079: if (!resultSet.next()) {
080: throw new ObjectNotFoundException(
081: "Cannot find the primary key (" + folderName
082: + ", " + memberID
083: + ") in table 'MessageFolder'.");
084: }
085: } catch (SQLException sqle) {
086: throw new DatabaseException(
087: "Error executing SQL in MessageFolderDAOImplJDBC.findByPrimaryKey.");
088: } finally {
089: DBUtils.closeResultSet(resultSet);
090: DBUtils.closeStatement(statement);
091: DBUtils.closeConnection(connection);
092: }
093:
094: }
095:
096: public void create(String folderName, int memberID,
097: int folderOrder, int folderStatus, int folderOption,
098: int folderType, Timestamp folderCreationDate,
099: Timestamp folderModifiedDate) throws CreateException,
100: DatabaseException, DuplicateKeyException,
101: ForeignKeyNotFoundException {
102: try {
103: //Check if primary key already exists
104: findByPrimaryKey(folderName, memberID);
105: //If so, then we have to throw an exception
106: throw new DuplicateKeyException(
107: "Primary key already exists. Cannot create new MessageFolder with the same [FolderName, MemberID] ("
108: + folderName + ", " + memberID + ").");
109: } catch (ObjectNotFoundException e) {
110: //Otherwise we can go ahead
111: }
112:
113: Connection connection = null;
114: PreparedStatement statement = null;
115: StringBuffer sql = new StringBuffer(512);
116: sql
117: .append("INSERT INTO "
118: + TABLE_NAME
119: + " (FolderName, MemberID, FolderOrder, FolderStatus, FolderOption, FolderType, FolderCreationDate, FolderModifiedDate)");
120: sql.append(" VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
121: try {
122: connection = DBUtils.getMvnConnection();
123: statement = connection.prepareStatement(sql.toString());
124:
125: statement.setString(1, folderName);
126: statement.setInt(2, memberID);
127: statement.setInt(3, folderOrder);
128: statement.setInt(4, folderStatus);
129: statement.setInt(5, folderOption);
130: statement.setInt(6, folderType);
131: statement.setTimestamp(7, folderCreationDate);
132: statement.setTimestamp(8, folderModifiedDate);
133:
134: if (statement.executeUpdate() != 1) {
135: throw new CreateException(
136: "Error adding a row into table 'MessageFolder'.");
137: }
138: } catch (SQLException sqle) {
139: throw new DatabaseException(
140: "Error executing SQL in MessageFolderDAOImplJDBC.create.");
141: } finally {
142: DBUtils.closeStatement(statement);
143: DBUtils.closeConnection(connection);
144: }
145:
146: }
147:
148: public void delete(String folderName, int memberID)
149: throws DatabaseException, ObjectNotFoundException {
150: // TODO Auto-generated method stub
151:
152: }
153:
154: public MessageFolderBean getMessageFolder(String folderName,
155: int memberID) throws ObjectNotFoundException,
156: DatabaseException {
157: // TODO Auto-generated method stub
158: return null;
159: }
160:
161: public Collection getMessageFolders_inMember(int memberID)
162: throws DatabaseException {
163: // TODO Auto-generated method stub
164: return null;
165: }
166:
167: public int getMaxFolderOrder(int memberID)
168: throws DatabaseException, AssertionException {
169: // TODO Auto-generated method stub
170: return 0;
171: }
172:
173: public void increaseFolderOrder(String folderName, int memberID,
174: Timestamp folderModifiedDate)
175: throws ObjectNotFoundException, DatabaseException {
176: // TODO Auto-generated method stub
177:
178: }
179:
180: public void decreaseFolderOrder(String folderName, int memberID,
181: Timestamp folderModifiedDate)
182: throws ObjectNotFoundException, DatabaseException {
183: // TODO Auto-generated method stub
184:
185: }
186:
187: }
|