001: /*
002: * $Header: /cvsroot/mvnforum/mvnforum/contrib/phpbb2mvnforum/src/org/mvnforum/phpbb2mvnforum/db/jdbc/PhpbbAuthAccessDAOImpl.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.util.ArrayList;
047: import java.util.Collection;
048:
049: import net.myvietnam.mvncore.exception.DatabaseException;
050:
051: import org.mvnforum.phpbb2mvnforum.db.PhpbbAuthAccess;
052: import org.mvnforum.phpbb2mvnforum.db.PhpbbAuthAccessDAO;
053: import org.mvnforum.util.DBUtils;
054:
055: public class PhpbbAuthAccessDAOImpl implements PhpbbAuthAccessDAO {
056:
057: public Collection getBeans() throws DatabaseException {
058: Connection connection = null;
059: PreparedStatement statement = null;
060: ResultSet resultSet = null;
061: Collection retValue = new ArrayList();
062: StringBuffer sql = new StringBuffer(512);
063: sql
064: .append("SELECT group_id, forum_id, auth_view, auth_read, auth_post, auth_reply, auth_edit, auth_delete, auth_sticky, auth_announce, auth_vote, auth_pollcreate, auth_attachments, auth_mod");
065: sql.append(" FROM " + TABLE_NAME);
066: //sql.append(" WHERE "); // @todo: uncomment as needed
067: //sql.append(" ORDER BY ColumnName ASC|DESC "); // @todo: uncomment as needed
068: try {
069: connection = DBUtils.getPhpbbConnection();
070: statement = connection.prepareStatement(sql.toString());
071: resultSet = statement.executeQuery();
072: while (resultSet.next()) {
073: PhpbbAuthAccess bean = new PhpbbAuthAccess();
074: bean.setgroup_id(resultSet.getInt("group_id"));
075: bean.setforum_id(resultSet.getInt("forum_id"));
076: bean.setauth_view(resultSet.getInt("auth_view"));
077: bean.setauth_read(resultSet.getInt("auth_read"));
078: bean.setauth_post(resultSet.getInt("auth_post"));
079: bean.setauth_reply(resultSet.getInt("auth_reply"));
080: bean.setauth_edit(resultSet.getInt("auth_edit"));
081: bean.setauth_delete(resultSet.getInt("auth_delete"));
082: bean.setauth_sticky(resultSet.getInt("auth_sticky"));
083: bean
084: .setauth_announce(resultSet
085: .getInt("auth_announce"));
086: bean.setauth_vote(resultSet.getInt("auth_vote"));
087: bean.setauth_pollcreate(resultSet
088: .getInt("auth_pollcreate"));
089: bean.setauth_attachments(resultSet
090: .getInt("auth_attachments"));
091: bean.setauth_mod(resultSet.getInt("auth_mod"));
092: retValue.add(bean);
093: }
094: return retValue;
095: } catch (SQLException sqle) {
096: throw new DatabaseException(
097: "Error executing SQL in phpbb_auth_accessDAOImplJDBC.getBeans.");
098: } finally {
099: DBUtils.closeResultSet(resultSet);
100: DBUtils.closeStatement(statement);
101: DBUtils.closeConnection(connection);
102: }
103: }
104:
105: public Collection getBeansByForumID(int forumId)
106: throws DatabaseException {
107:
108: Connection connection = null;
109: PreparedStatement statement = null;
110: ResultSet resultSet = null;
111: Collection retValue = new ArrayList();
112: StringBuffer sql = new StringBuffer(512);
113: sql
114: .append("SELECT group_id, forum_id, auth_view, auth_read, auth_post, auth_reply, auth_edit, auth_delete, auth_sticky, auth_announce, auth_vote, auth_pollcreate, auth_attachments, auth_mod");
115: sql.append(" FROM " + TABLE_NAME);
116: sql.append(" WHERE forum_id=?");
117: try {
118: connection = DBUtils.getPhpbbConnection();
119: statement = connection.prepareStatement(sql.toString());
120: statement.setInt(1, forumId);
121: resultSet = statement.executeQuery();
122: while (resultSet.next()) {
123: PhpbbAuthAccess bean = new PhpbbAuthAccess();
124: bean.setgroup_id(resultSet.getInt("group_id"));
125: bean.setforum_id(resultSet.getInt("forum_id"));
126: bean.setauth_view(resultSet.getInt("auth_view"));
127: bean.setauth_read(resultSet.getInt("auth_read"));
128: bean.setauth_post(resultSet.getInt("auth_post"));
129: bean.setauth_reply(resultSet.getInt("auth_reply"));
130: bean.setauth_edit(resultSet.getInt("auth_edit"));
131: bean.setauth_delete(resultSet.getInt("auth_delete"));
132: bean.setauth_sticky(resultSet.getInt("auth_sticky"));
133: bean
134: .setauth_announce(resultSet
135: .getInt("auth_announce"));
136: bean.setauth_vote(resultSet.getInt("auth_vote"));
137: bean.setauth_pollcreate(resultSet
138: .getInt("auth_pollcreate"));
139: bean.setauth_attachments(resultSet
140: .getInt("auth_attachments"));
141: bean.setauth_mod(resultSet.getInt("auth_mod"));
142: retValue.add(bean);
143: }
144: return retValue;
145: } catch (SQLException sqle) {
146: throw new DatabaseException(
147: "Error executing SQL in phpbb_auth_accessDAOImplJDBC.getBeans.");
148: } finally {
149: DBUtils.closeResultSet(resultSet);
150: DBUtils.closeStatement(statement);
151: DBUtils.closeConnection(connection);
152: }
153: }
154: }
|