001: /*
002: * $Header: /cvsroot/mvnforum/mvnforum/contrib/phpbb2mvnforum/src/org/mvnforum/phpbb2mvnforum/db/jdbc/PhpbbUserDAOImpl.java,v 1.5 2007/01/15 10:27:11 dungbtm Exp $
003: * $Author: dungbtm $
004: * $Revision: 1.5 $
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: import net.myvietnam.mvncore.exception.ObjectNotFoundException;
051:
052: import org.mvnforum.phpbb2mvnforum.db.PhpbbUserDAO;
053: import org.mvnforum.phpbb2mvnforum.db.PhpbbUsers;
054: import org.mvnforum.util.DBUtils;
055:
056: public class PhpbbUserDAOImpl implements PhpbbUserDAO {
057:
058: public static String TABLE_NAME = "phpbb_users";
059:
060: public String getUserNameFromUserID(int userID)
061: throws ObjectNotFoundException, DatabaseException {
062:
063: Connection connection = null;
064: PreparedStatement statement = null;
065: ResultSet resultSet = null;
066:
067: StringBuffer sql = new StringBuffer(512);
068: sql.append("SELECT username");
069: sql.append(" FROM " + TABLE_NAME);
070: sql.append(" WHERE user_id = ?");
071:
072: String memName = "";
073:
074: try {
075: connection = DBUtils.getPhpbbConnection();
076: statement = connection.prepareStatement(sql.toString());
077: statement.setInt(1, userID);
078: resultSet = statement.executeQuery();
079: if (!resultSet.next()) {
080: throw new ObjectNotFoundException(
081: "Cannot find user [userID] (" + userID
082: + ") in table 'phpbb_users'.");
083: }
084: memName = resultSet.getString("username");
085: } catch (SQLException sqle) {
086: sqle.printStackTrace();
087: throw new DatabaseException(
088: "Error executing SQL in PhpbbUserDAOImpl.getUserNameFromUserID");
089: } finally {
090: DBUtils.closeResultSet(resultSet);
091: DBUtils.closeStatement(statement);
092: DBUtils.closeConnection(connection);
093: }
094: return memName;
095: }
096:
097: /*
098: * Included columns: user_id, user_active, username, user_password, user_session_time,
099: * user_session_page, user_lastvisit, user_regdate, user_level, user_posts,
100: * user_timezone, user_style, user_lang, user_dateformat, user_new_privmsg,
101: * user_unread_privmsg, user_last_privmsg, user_emailtime, user_viewemail, user_attachsig,
102: * user_allowhtml, user_allowbbcode, user_allowsmile, user_allowavatar, user_allow_pm,
103: * user_allow_viewonline, user_notify, user_notify_pm, user_popup_pm, user_rank,
104: * user_avatar, user_avatar_type, user_email, user_icq, user_website,
105: * user_from, user_sig, user_sig_bbcode_uid, user_aim, user_yim,
106: * user_msnm, user_occ, user_interests, user_actkey, user_newpasswd
107: * Excluded columns:
108: */
109: public Collection getBeans() throws DatabaseException {
110:
111: Connection connection = null;
112: PreparedStatement statement = null;
113: ResultSet resultSet = null;
114: Collection retValue = new ArrayList();
115: StringBuffer sql = new StringBuffer(512);
116: sql
117: .append("SELECT user_id, user_active, username, user_password, user_session_time, user_session_page, user_lastvisit, user_regdate, user_level, user_posts, user_timezone, user_style, user_lang, user_dateformat, user_new_privmsg, user_unread_privmsg, user_last_privmsg, user_emailtime, user_viewemail, user_attachsig, user_allowhtml, user_allowbbcode, user_allowsmile, user_allowavatar, user_allow_pm, user_allow_viewonline, user_notify, user_notify_pm, user_popup_pm, user_rank, user_avatar, user_avatar_type, user_email, user_icq, user_website, user_from, user_sig, user_sig_bbcode_uid, user_aim, user_yim, user_msnm, user_occ, user_interests, user_actkey, user_newpasswd");
118: sql.append(" FROM " + TABLE_NAME);
119: //sql.append(" WHERE "); // @todo: uncomment as needed
120: //sql.append(" ORDER BY ColumnName ASC|DESC "); // @todo: uncomment as needed
121: try {
122: connection = DBUtils.getPhpbbConnection();
123: statement = connection.prepareStatement(sql.toString());
124: resultSet = statement.executeQuery();
125: while (resultSet.next()) {
126: PhpbbUsers bean = new PhpbbUsers();
127: bean.setUserId(resultSet.getInt("user_id"));
128: bean.setUserActive(resultSet.getInt("user_active"));
129: bean.setUsername(resultSet.getString("username"));
130: bean.setUserPassword(resultSet
131: .getString("user_password"));
132: bean.setUserSessionTime(resultSet
133: .getLong("user_session_time"));
134: bean.setUserSessionPage(resultSet
135: .getInt("user_session_page"));
136: bean.setUserLastvisit(resultSet
137: .getLong("user_lastvisit"));
138: bean.setUserRegdate(resultSet.getLong("user_regdate"));
139: bean.setUserLevel(resultSet.getInt("user_level"));
140: bean.setUserPosts(resultSet.getInt("user_posts"));
141: bean.setUserTimezone(resultSet
142: .getBigDecimal("user_timezone"));
143: bean.setUserStyle(resultSet.getInt("user_style"));
144: bean.setUserLang(resultSet.getString("user_lang"));
145: bean.setUserDateformat(resultSet
146: .getString("user_dateformat"));
147: bean.setUserNewPrivmsg(resultSet
148: .getInt("user_new_privmsg"));
149: bean.setUserUnreadPrivmsg(resultSet
150: .getInt("user_unread_privmsg"));
151: bean.setUserLastPrivmsg(resultSet
152: .getLong("user_last_privmsg"));
153: bean.setUserEmailtime(resultSet
154: .getInt("user_emailtime"));
155: bean.setUserViewemail(resultSet
156: .getInt("user_viewemail"));
157: bean.setUserAttachsig(resultSet
158: .getInt("user_attachsig"));
159: bean.setUserAllowhtml(resultSet
160: .getInt("user_allowhtml"));
161: bean.setUserAllowbbcode(resultSet
162: .getInt("user_allowbbcode"));
163: bean.setUserAllowsmile(resultSet
164: .getInt("user_allowsmile"));
165: bean.setUserAllowavatar(resultSet
166: .getInt("user_allowavatar"));
167: bean.setUserAllowPm(resultSet.getInt("user_allow_pm"));
168: bean.setUserAllowViewonline(resultSet
169: .getInt("user_allow_viewonline"));
170: bean.setUserNotify(resultSet.getInt("user_notify"));
171: bean
172: .setUserNotifyPm(resultSet
173: .getInt("user_notify_pm"));
174: bean.setUserPopupPm(resultSet.getInt("user_popup_pm"));
175: bean.setUserRank(resultSet.getInt("user_rank"));
176: bean.setUserAvatar(resultSet.getString("user_avatar"));
177: bean.setUserAvatarType(resultSet
178: .getInt("user_avatar_type"));
179: bean.setUserEmail(resultSet.getString("user_email"));
180: bean.setUserIcq(resultSet.getString("user_icq"));
181: bean
182: .setUserWebsite(resultSet
183: .getString("user_website"));
184: bean.setUserFrom(resultSet.getString("user_from"));
185: bean.setUserSig(resultSet.getString("user_sig"));
186: bean.setUserSigBbcodeUid(resultSet
187: .getString("user_sig_bbcode_uid"));
188: bean.setUserAim(resultSet.getString("user_aim"));
189: bean.setUserYim(resultSet.getString("user_yim"));
190: bean.setUserMsnm(resultSet.getString("user_msnm"));
191: bean.setUserOcc(resultSet.getString("user_occ"));
192: bean.setUserInterests(resultSet
193: .getString("user_interests"));
194: bean.setUserActkey(resultSet.getString("user_actkey"));
195: bean.setUserNewpasswd(resultSet
196: .getString("user_newpasswd"));
197: retValue.add(bean);
198: }
199: return retValue;
200: } catch (SQLException sqle) {
201: throw new DatabaseException(
202: "Error executing SQL in phpbb_usersDAOImplJDBC.getBeans.");
203: } finally {
204: DBUtils.closeResultSet(resultSet);
205: DBUtils.closeStatement(statement);
206: DBUtils.closeConnection(connection);
207: }
208: }
209:
210: }
|