001: /*
002: * $Header: /cvsroot/mvnforum/mvnforum/contrib/phpbb2mvnforum/src/org/mvnforum/phpbb2mvnforum/db/jdbc/PhpbbForumDAOImpl.java,v 1.4 2007/01/15 10:27:11 dungbtm Exp $
003: * $Author: dungbtm $
004: * $Revision: 1.4 $
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.PhpbbForum;
052: import org.mvnforum.phpbb2mvnforum.db.PhpbbForumDAO;
053: import org.mvnforum.util.DBUtils;
054:
055: public class PhpbbForumDAOImpl implements PhpbbForumDAO {
056:
057: /*
058: * Included columns: forum_id, cat_id, forum_name, forum_desc, forum_status,
059: * forum_order, forum_posts, forum_topics, forum_last_post_id, prune_next,
060: * prune_enable, auth_view, auth_read, auth_post, auth_reply,
061: * auth_edit, auth_delete, auth_sticky, auth_announce, auth_vote,
062: * auth_pollcreate, auth_attachments
063: * Excluded columns:
064: */
065: public Collection getBeans() throws DatabaseException {
066:
067: Connection connection = null;
068: PreparedStatement statement = null;
069: ResultSet resultSet = null;
070: Collection retValue = new ArrayList();
071: StringBuffer sql = new StringBuffer(512);
072: sql
073: .append("SELECT forum_id, cat_id, forum_name, forum_desc, forum_status, forum_order, forum_posts, forum_topics, forum_last_post_id, prune_next, prune_enable, auth_view, auth_read, auth_post, auth_reply, auth_edit, auth_delete, auth_sticky, auth_announce, auth_vote, auth_pollcreate, auth_attachments");
074: sql.append(" FROM " + TABLE_NAME);
075: //sql.append(" WHERE "); // @todo: uncomment as needed
076: //sql.append(" ORDER BY ColumnName ASC|DESC "); // @todo: uncomment as needed
077: try {
078: connection = DBUtils.getPhpbbConnection();
079: statement = connection.prepareStatement(sql.toString());
080: resultSet = statement.executeQuery();
081: while (resultSet.next()) {
082: PhpbbForum bean = new PhpbbForum();
083: bean.setforum_id(resultSet.getInt("forum_id"));
084: bean.setcat_id(resultSet.getInt("cat_id"));
085: bean.setforum_name(resultSet.getString("forum_name"));
086: bean.setforum_desc(resultSet.getString("forum_desc"));
087: bean.setforum_status(resultSet.getInt("forum_status"));
088: bean.setforum_order(resultSet.getInt("forum_order"));
089: bean.setforum_posts(resultSet.getInt("forum_posts"));
090: bean.setforum_topics(resultSet.getInt("forum_topics"));
091: bean.setforum_last_post_id(resultSet
092: .getInt("forum_last_post_id"));
093: bean.setprune_next(resultSet.getInt("prune_next"));
094: bean.setprune_enable(resultSet.getInt("prune_enable"));
095: bean.setauth_view(resultSet.getInt("auth_view"));
096: bean.setauth_read(resultSet.getInt("auth_read"));
097: bean.setauth_post(resultSet.getInt("auth_post"));
098: bean.setauth_reply(resultSet.getInt("auth_reply"));
099: bean.setauth_edit(resultSet.getInt("auth_edit"));
100: bean.setauth_delete(resultSet.getInt("auth_delete"));
101: bean.setauth_sticky(resultSet.getInt("auth_sticky"));
102: bean
103: .setauth_announce(resultSet
104: .getInt("auth_announce"));
105: bean.setauth_vote(resultSet.getInt("auth_vote"));
106: bean.setauth_pollcreate(resultSet
107: .getInt("auth_pollcreate"));
108: bean.setauth_attachments(resultSet
109: .getInt("auth_attachments"));
110: retValue.add(bean);
111: }
112: return retValue;
113: } catch (SQLException sqle) {
114: throw new DatabaseException(
115: "Error executing SQL in phpbb_forumsDAOImplJDBC.getBeans.");
116: } finally {
117: DBUtils.closeResultSet(resultSet);
118: DBUtils.closeStatement(statement);
119: DBUtils.closeConnection(connection);
120: }
121: }
122:
123: public Collection getBeansByCategoryID(int categoryID)
124: throws DatabaseException {
125:
126: Connection connection = null;
127: PreparedStatement statement = null;
128: ResultSet resultSet = null;
129: Collection retValue = new ArrayList();
130: StringBuffer sql = new StringBuffer(512);
131: sql
132: .append("SELECT forum_id, cat_id, forum_name, forum_desc, forum_status, forum_order, forum_posts, forum_topics, forum_last_post_id, prune_next, prune_enable, auth_view, auth_read, auth_post, auth_reply, auth_edit, auth_delete, auth_sticky, auth_announce, auth_vote, auth_pollcreate, auth_attachments");
133: sql.append(" FROM " + TABLE_NAME);
134: sql.append(" WHERE cat_id = ?"); // @todo: uncomment as needed
135: //sql.append(" ORDER BY ColumnName ASC|DESC "); // @todo: uncomment as needed
136: try {
137: connection = DBUtils.getPhpbbConnection();
138: statement = connection.prepareStatement(sql.toString());
139: statement.setInt(1, categoryID);
140: resultSet = statement.executeQuery();
141: //if (!resultSet.next()) return retValue;
142: while (resultSet.next()) {
143: PhpbbForum bean = new PhpbbForum();
144: bean.setforum_id(resultSet.getInt("forum_id"));
145: bean.setcat_id(resultSet.getInt("cat_id"));
146: bean.setforum_name(resultSet.getString("forum_name"));
147: bean.setforum_desc(resultSet.getString("forum_desc"));
148: bean.setforum_status(resultSet.getInt("forum_status"));
149: bean.setforum_order(resultSet.getInt("forum_order"));
150: bean.setforum_posts(resultSet.getInt("forum_posts"));
151: bean.setforum_topics(resultSet.getInt("forum_topics"));
152: bean.setforum_last_post_id(resultSet
153: .getInt("forum_last_post_id"));
154: bean.setprune_next(resultSet.getInt("prune_next"));
155: bean.setprune_enable(resultSet.getInt("prune_enable"));
156: bean.setauth_view(resultSet.getInt("auth_view"));
157: bean.setauth_read(resultSet.getInt("auth_read"));
158: bean.setauth_post(resultSet.getInt("auth_post"));
159: bean.setauth_reply(resultSet.getInt("auth_reply"));
160: bean.setauth_edit(resultSet.getInt("auth_edit"));
161: bean.setauth_delete(resultSet.getInt("auth_delete"));
162: bean.setauth_sticky(resultSet.getInt("auth_sticky"));
163: bean
164: .setauth_announce(resultSet
165: .getInt("auth_announce"));
166: bean.setauth_vote(resultSet.getInt("auth_vote"));
167: bean.setauth_pollcreate(resultSet
168: .getInt("auth_pollcreate"));
169: bean.setauth_attachments(resultSet
170: .getInt("auth_attachments"));
171: retValue.add(bean);
172: }
173: return retValue;
174: } catch (SQLException sqle) {
175: sqle.printStackTrace();
176: throw new DatabaseException(
177: "Error executing SQL in phpbb_forumsDAOImplJDBC.getBeans.");
178: } finally {
179: DBUtils.closeResultSet(resultSet);
180: DBUtils.closeStatement(statement);
181: DBUtils.closeConnection(connection);
182: }
183: }
184: }
|