001: /*
002: * $Header: /cvsroot/mvnforum/mvnforum/contrib/phpbb2mvnforum/src/org/mvnforum/phpbb2mvnforum/db/jdbc/PhpbbTopicsDAOImpl.java,v 1.6 2007/12/18 04:58:44 minhnn Exp $
003: * $Author: minhnn $
004: * $Revision: 1.6 $
005: * $Date: 2007/12/18 04:58:44 $
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.util.ArrayList;
047: import java.util.Collection;
048:
049: import net.myvietnam.mvncore.exception.DatabaseException;
050: import net.myvietnam.mvncore.exception.ObjectNotFoundException;
051:
052: import org.mvnforum.phpbb2mvnforum.db.PhpbbTopics;
053: import org.mvnforum.phpbb2mvnforum.db.PhpbbTopicsDAO;
054: import org.mvnforum.util.DBUtils;
055:
056: public class PhpbbTopicsDAOImpl implements PhpbbTopicsDAO {
057:
058: /*
059: * Included columns: topic_id, forum_id, topic_title, topic_poster, topic_time,
060: * topic_views, topic_replies, topic_status, topic_vote, topic_type,
061: * topic_first_post_id, topic_last_post_id, topic_moved_id
062: * Excluded columns:
063: */
064: public Collection getBeans() throws DatabaseException {
065:
066: Connection connection = null;
067: PreparedStatement statement = null;
068: ResultSet resultSet = null;
069: Collection retValue = new ArrayList();
070: StringBuffer sql = new StringBuffer(512);
071: sql
072: .append("SELECT topic_id, forum_id, topic_title, topic_poster, topic_time, topic_views, topic_replies, topic_status, topic_vote, topic_type, topic_first_post_id, topic_last_post_id, topic_moved_id");
073: sql.append(" FROM " + TABLE_NAME);
074: //sql.append(" WHERE "); // @todo: uncomment as needed
075: //sql.append(" ORDER BY ColumnName ASC|DESC "); // @todo: uncomment as needed
076: try {
077: connection = DBUtils.getPhpbbConnection();
078: statement = connection.prepareStatement(sql.toString());
079: resultSet = statement.executeQuery();
080: while (resultSet.next()) {
081: PhpbbTopics bean = new PhpbbTopics();
082: bean.settopic_id(resultSet.getInt("topic_id"));
083: bean.setforum_id(resultSet.getInt("forum_id"));
084: bean.settopic_title(resultSet.getString("topic_title"));
085: bean.settopic_poster(resultSet.getInt("topic_poster"));
086: bean.settopic_time(resultSet.getInt("topic_time"));
087: bean.settopic_views(resultSet.getInt("topic_views"));
088: bean
089: .settopic_replies(resultSet
090: .getInt("topic_replies"));
091: bean.settopic_status(resultSet.getInt("topic_status"));
092: bean.settopic_vote(resultSet.getInt("topic_vote"));
093: bean.settopic_type(resultSet.getInt("topic_type"));
094: bean.settopic_first_post_id(resultSet
095: .getInt("topic_first_post_id"));
096: bean.settopic_last_post_id(resultSet
097: .getInt("topic_last_post_id"));
098: bean.settopic_moved_id(resultSet
099: .getInt("topic_moved_id"));
100: retValue.add(bean);
101: }
102: return retValue;
103: } catch (SQLException sqle) {
104: throw new DatabaseException(
105: "Error executing SQL in phpbb_topicsDAOImplJDBC.getBeans.");
106: } finally {
107: DBUtils.closeResultSet(resultSet);
108: DBUtils.closeStatement(statement);
109: DBUtils.closeConnection(connection);
110: }
111: }
112:
113: public Collection getBeansByForumID(int forumID)
114: throws DatabaseException {
115: // TODO Auto-generated method stub
116: Connection connection = null;
117: PreparedStatement statement = null;
118: ResultSet resultSet = null;
119: Collection retValue = new ArrayList();
120: StringBuffer sql = new StringBuffer(512);
121: sql
122: .append("SELECT topic_id, forum_id, topic_title, topic_poster, topic_time, topic_views, topic_replies, topic_status, topic_vote, topic_type, topic_first_post_id, topic_last_post_id, topic_moved_id");
123: sql.append(" FROM " + TABLE_NAME);
124: sql.append(" WHERE forum_id = ?");
125: //sql.append(" ORDER BY ColumnName ASC|DESC "); // @todo: uncomment as needed
126: try {
127: connection = DBUtils.getPhpbbConnection();
128: statement = connection.prepareStatement(sql.toString());
129: statement.setInt(1, forumID);
130: resultSet = statement.executeQuery();
131: while (resultSet.next()) {
132: PhpbbTopics bean = new PhpbbTopics();
133: bean.settopic_id(resultSet.getInt("topic_id"));
134: bean.setforum_id(resultSet.getInt("forum_id"));
135: bean.settopic_title(resultSet.getString("topic_title"));
136: bean.settopic_poster(resultSet.getInt("topic_poster"));
137: bean.settopic_time(resultSet.getInt("topic_time"));
138: bean.settopic_views(resultSet.getInt("topic_views"));
139: bean
140: .settopic_replies(resultSet
141: .getInt("topic_replies"));
142: bean.settopic_status(resultSet.getInt("topic_status"));
143: bean.settopic_vote(resultSet.getInt("topic_vote"));
144: bean.settopic_type(resultSet.getInt("topic_type"));
145: bean.settopic_first_post_id(resultSet
146: .getInt("topic_first_post_id"));
147: bean.settopic_last_post_id(resultSet
148: .getInt("topic_last_post_id"));
149: bean.settopic_moved_id(resultSet
150: .getInt("topic_moved_id"));
151: retValue.add(bean);
152: }
153: return retValue;
154: } catch (SQLException sqle) {
155: throw new DatabaseException(
156: "Error executing SQL in phpbb_topicsDAOImplJDBC.getBeans.");
157: } finally {
158: DBUtils.closeResultSet(resultSet);
159: DBUtils.closeStatement(statement);
160: DBUtils.closeConnection(connection);
161: }
162: }
163:
164: public PhpbbTopics getBeans(int topicID)
165: throws ObjectNotFoundException, DatabaseException {
166:
167: Connection connection = null;
168: PreparedStatement statement = null;
169: ResultSet resultSet = null;
170: StringBuffer sql = new StringBuffer(512);
171: sql
172: .append("SELECT topic_id, forum_id, topic_title, topic_poster, topic_time, topic_views, topic_replies, topic_status, topic_vote, topic_type, topic_first_post_id, topic_last_post_id, topic_moved_id");
173: sql.append(" FROM " + TABLE_NAME);
174: sql.append(" WHERE topic_id = ?");
175: try {
176: connection = DBUtils.getPhpbbConnection();
177: statement = connection.prepareStatement(sql.toString());
178: statement.setInt(1, topicID);
179: resultSet = statement.executeQuery();
180: if (!resultSet.next()) {
181: throw new ObjectNotFoundException(
182: "Cannot find the row in table phpbb_topics where primary key = ("
183: + topicID + ").");
184: }
185:
186: PhpbbTopics bean = new PhpbbTopics();
187: // @todo: uncomment the following line(s) as needed
188: //bean.settopic_id(topic_id);
189: bean.settopic_id(resultSet.getInt("topic_id"));
190: bean.setforum_id(resultSet.getInt("forum_id"));
191: bean.settopic_title(resultSet.getString("topic_title"));
192: bean.settopic_poster(resultSet.getInt("topic_poster"));
193: bean.settopic_time(resultSet.getInt("topic_time"));
194: bean.settopic_views(resultSet.getInt("topic_views"));
195: bean.settopic_replies(resultSet.getInt("topic_replies"));
196: bean.settopic_status(resultSet.getInt("topic_status"));
197: bean.settopic_vote(resultSet.getInt("topic_vote"));
198: bean.settopic_type(resultSet.getInt("topic_type"));
199: bean.settopic_first_post_id(resultSet
200: .getInt("topic_first_post_id"));
201: bean.settopic_last_post_id(resultSet
202: .getInt("topic_last_post_id"));
203: bean.settopic_moved_id(resultSet.getInt("topic_moved_id"));
204: return bean;
205: } catch (SQLException sqle) {
206: throw new DatabaseException(
207: "Error executing SQL in phpbb_topicsDAOImplJDBC.getBean(pk).");
208: } finally {
209: DBUtils.closeResultSet(resultSet);
210: DBUtils.closeStatement(statement);
211: DBUtils.closeConnection(connection);
212: }
213: }
214: }
|