001: /*
002: * $Header: /cvsroot/mvnforum/mvnforum/contrib/phpbb2mvnforum/src/org/mvnforum/phpbb2mvnforum/db/jdbc/PhpbbTopicsWatchDAOImpl.java,v 1.3 2007/01/15 10:27:11 dungbtm Exp $
003: * $Author: dungbtm $
004: * $Revision: 1.3 $
005: * $Date: 2007/01/15 10:27:11 $
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:
051: import org.mvnforum.phpbb2mvnforum.db.PhpbbTopicsWatch;
052: import org.mvnforum.phpbb2mvnforum.db.PhpbbTopicsWatchDAO;
053: import org.mvnforum.util.DBUtils;
054:
055: public class PhpbbTopicsWatchDAOImpl implements PhpbbTopicsWatchDAO {
056:
057: public Collection getBeansByUserID(int userID)
058: throws DatabaseException {
059:
060: Connection connection = null;
061: PreparedStatement statement = null;
062: ResultSet resultSet = null;
063: Collection retValue = new ArrayList();
064: StringBuffer sql = new StringBuffer(512);
065: sql.append("SELECT topic_id, user_id, notify_status");
066: sql.append(" FROM " + TABLE_NAME);
067: sql.append(" WHERE user_id=?"); // @todo: uncomment as needed
068: //sql.append(" ORDER BY ColumnName ASC|DESC "); // @todo: uncomment as needed
069: try {
070: connection = DBUtils.getPhpbbConnection();
071: statement = connection.prepareStatement(sql.toString());
072: statement.setInt(1, userID);
073: resultSet = statement.executeQuery();
074: while (resultSet.next()) {
075: PhpbbTopicsWatch bean = new PhpbbTopicsWatch();
076: bean.settopic_id(resultSet.getInt("topic_id"));
077: bean.setuser_id(resultSet.getInt("user_id"));
078: bean
079: .setnotify_status(resultSet
080: .getInt("notify_status"));
081: retValue.add(bean);
082: }
083: return retValue;
084: } catch (SQLException sqle) {
085: throw new DatabaseException(
086: "Error executing SQL in phpbb_topics_watchDAOImplJDBC.getBeans.");
087: } finally {
088: DBUtils.closeResultSet(resultSet);
089: DBUtils.closeStatement(statement);
090: DBUtils.closeConnection(connection);
091: }
092: }
093:
094: public Collection getBeans(int userID, int topicID)
095: throws DatabaseException {
096: Connection connection = null;
097: PreparedStatement statement = null;
098: ResultSet resultSet = null;
099: Collection retValue = new ArrayList();
100: StringBuffer sql = new StringBuffer(512);
101: sql.append("SELECT topic_id, user_id, notify_status");
102: sql.append(" FROM " + TABLE_NAME);
103: sql.append(" WHERE user_id=? and topic_id=?"); // @todo: uncomment as needed
104: //sql.append(" ORDER BY ColumnName ASC|DESC "); // @todo: uncomment as needed
105: try {
106: connection = DBUtils.getPhpbbConnection();
107: statement = connection.prepareStatement(sql.toString());
108: statement.setInt(1, userID);
109: statement.setInt(2, topicID);
110: resultSet = statement.executeQuery();
111: while (resultSet.next()) {
112: PhpbbTopicsWatch bean = new PhpbbTopicsWatch();
113: bean.settopic_id(resultSet.getInt("topic_id"));
114: bean.setuser_id(resultSet.getInt("user_id"));
115: bean
116: .setnotify_status(resultSet
117: .getInt("notify_status"));
118: retValue.add(bean);
119: }
120: return retValue;
121: } catch (SQLException sqle) {
122: sqle.printStackTrace();
123: throw new DatabaseException(
124: "Error executing SQL in phpbb_topics_watchDAOImplJDBC.getBeans.");
125: } finally {
126: DBUtils.closeResultSet(resultSet);
127: DBUtils.closeStatement(statement);
128: DBUtils.closeConnection(connection);
129: }
130:
131: }
132:
133: public Collection getBeansByTopicID(int topicID)
134: throws DatabaseException {
135: Connection connection = null;
136: PreparedStatement statement = null;
137: ResultSet resultSet = null;
138: Collection retValue = new ArrayList();
139: StringBuffer sql = new StringBuffer(512);
140: sql.append("SELECT topic_id, user_id, notify_status");
141: sql.append(" FROM " + TABLE_NAME);
142: sql.append(" WHERE topic_id=?"); // @todo: uncomment as needed
143: //sql.append(" ORDER BY ColumnName ASC|DESC "); // @todo: uncomment as needed
144: try {
145: connection = DBUtils.getPhpbbConnection();
146: statement = connection.prepareStatement(sql.toString());
147: statement.setInt(1, topicID);
148: resultSet = statement.executeQuery();
149: while (resultSet.next()) {
150: PhpbbTopicsWatch bean = new PhpbbTopicsWatch();
151: bean.settopic_id(resultSet.getInt("topic_id"));
152: bean.setuser_id(resultSet.getInt("user_id"));
153: bean
154: .setnotify_status(resultSet
155: .getInt("notify_status"));
156: retValue.add(bean);
157: }
158: return retValue;
159: } catch (SQLException sqle) {
160: throw new DatabaseException(
161: "Error executing SQL in phpbb_topics_watchDAOImplJDBC.getBeans.");
162: } finally {
163: DBUtils.closeResultSet(resultSet);
164: DBUtils.closeStatement(statement);
165: DBUtils.closeConnection(connection);
166: }
167: }
168:
169: }
|