001: /*
002: * $Header: /cvsroot/mvnforum/mvnforum/contrib/phpbb2mvnforum/src/org/mvnforum/phpbb2mvnforum/db/jdbc/PhpbbGroupDAOImpl.java,v 1.5 2007/12/18 04:58:44 minhnn Exp $
003: * $Author: minhnn $
004: * $Revision: 1.5 $
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.PhpbbGroup;
053: import org.mvnforum.phpbb2mvnforum.db.PhpbbGroupDAO;
054: import org.mvnforum.util.DBUtils;
055:
056: public class PhpbbGroupDAOImpl implements PhpbbGroupDAO {
057:
058: public Collection getBeans() throws DatabaseException {
059: Connection connection = null;
060: PreparedStatement statement = null;
061: ResultSet resultSet = null;
062: Collection retValue = new ArrayList();
063: StringBuffer sql = new StringBuffer(512);
064: sql
065: .append("SELECT group_id, group_type, group_name, group_description, group_moderator, group_single_user");
066: sql.append(" FROM " + TABLE_NAME);
067: //sql.append(" WHERE "); // @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: resultSet = statement.executeQuery();
073: while (resultSet.next()) {
074: PhpbbGroup bean = new PhpbbGroup();
075: bean.setgroup_id(resultSet.getInt("group_id"));
076: bean.setgroup_type(resultSet.getInt("group_type"));
077: bean.setgroup_name(resultSet.getString("group_name"));
078: bean.setgroup_description(resultSet
079: .getString("group_description"));
080: bean.setgroup_moderator(resultSet
081: .getInt("group_moderator"));
082: bean.setgroup_single_user(resultSet
083: .getInt("group_single_user"));
084: retValue.add(bean);
085: }
086: return retValue;
087: } catch (SQLException sqle) {
088: throw new DatabaseException(
089: "Error executing SQL in phpbb_groupsDAOImplJDBC.getBeans.");
090: } finally {
091: DBUtils.closeResultSet(resultSet);
092: DBUtils.closeStatement(statement);
093: DBUtils.closeConnection(connection);
094: }
095: }
096:
097: public PhpbbGroup getBean(int groupID)
098: throws ObjectNotFoundException, DatabaseException {
099: Connection connection = null;
100: PreparedStatement statement = null;
101: ResultSet resultSet = null;
102: StringBuffer sql = new StringBuffer(512);
103: sql
104: .append("SELECT group_id, group_type, group_name, group_description, group_moderator, group_single_user");
105: sql.append(" FROM " + TABLE_NAME);
106: sql.append(" WHERE group_id = ?");
107: try {
108: connection = DBUtils.getPhpbbConnection();
109: statement = connection.prepareStatement(sql.toString());
110: statement.setInt(1, groupID);
111: resultSet = statement.executeQuery();
112: if (!resultSet.next()) {
113: throw new ObjectNotFoundException(
114: "Cannot find the row in table phpbb_groups where primary key = ("
115: + groupID + ").");
116: }
117:
118: PhpbbGroup bean = new PhpbbGroup();
119: bean.setgroup_id(resultSet.getInt("group_id"));
120: bean.setgroup_type(resultSet.getInt("group_type"));
121: bean.setgroup_name(resultSet.getString("group_name"));
122: bean.setgroup_description(resultSet
123: .getString("group_description"));
124: bean
125: .setgroup_moderator(resultSet
126: .getInt("group_moderator"));
127: bean.setgroup_single_user(resultSet
128: .getInt("group_single_user"));
129: return bean;
130: } catch (SQLException sqle) {
131: throw new DatabaseException(
132: "Error executing SQL in phpbb_groupsDAOImplJDBC.getBean(pk).");
133: } finally {
134: DBUtils.closeResultSet(resultSet);
135: DBUtils.closeStatement(statement);
136: DBUtils.closeConnection(connection);
137: }
138: }
139:
140: public PhpbbGroup getTruthGroup(int groupID)
141: throws ObjectNotFoundException, DatabaseException {
142: Connection connection = null;
143: PreparedStatement statement = null;
144: ResultSet resultSet = null;
145: StringBuffer sql = new StringBuffer(512);
146: sql
147: .append("SELECT group_id, group_type, group_name, group_description, group_moderator, group_single_user");
148: sql.append(" FROM " + TABLE_NAME);
149: sql.append(" WHERE group_id=? and group_single_user=?");
150: try {
151: connection = DBUtils.getPhpbbConnection();
152: statement = connection.prepareStatement(sql.toString());
153: statement.setInt(1, groupID);
154: statement.setInt(2, 0);
155: resultSet = statement.executeQuery();
156: if (!resultSet.next()) {
157: //throw new ObjectNotFoundException("Cannot find the row in table phpbb_groups where primary key = (" + groupID + ").");
158: return null;
159: }
160:
161: PhpbbGroup bean = new PhpbbGroup();
162: bean.setgroup_id(resultSet.getInt("group_id"));
163: bean.setgroup_type(resultSet.getInt("group_type"));
164: bean.setgroup_name(resultSet.getString("group_name"));
165: bean.setgroup_description(resultSet
166: .getString("group_description"));
167: bean
168: .setgroup_moderator(resultSet
169: .getInt("group_moderator"));
170: bean.setgroup_single_user(resultSet
171: .getInt("group_single_user"));
172: return bean;
173: } catch (SQLException sqle) {
174: throw new DatabaseException(
175: "Error executing SQL in phpbb_groupsDAOImplJDBC.getBean(pk).");
176: } finally {
177: DBUtils.closeResultSet(resultSet);
178: DBUtils.closeStatement(statement);
179: DBUtils.closeConnection(connection);
180: }
181:
182: }
183: }
|