001: /*
002: * $Header: /cvsroot/mvnforum/mvnforum/contrib/phpbb2mvnforum/src/org/mvnforum/phpbb2mvnforum/db/jdbc/PhpbbPostTextDAOImpl.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:
047: import net.myvietnam.mvncore.exception.DatabaseException;
048: import net.myvietnam.mvncore.exception.ObjectNotFoundException;
049:
050: import org.mvnforum.phpbb2mvnforum.db.PhpbbPostText;
051: import org.mvnforum.phpbb2mvnforum.db.PhpbbPostTextDAO;
052: import org.mvnforum.util.DBUtils;
053:
054: public class PhpbbPostTextDAOImpl implements PhpbbPostTextDAO {
055:
056: /*
057: * Included columns: post_id, bbcode_uid, post_subject, post_text
058: * Excluded columns:
059: */
060: public PhpbbPostText getBean(int post_id)
061: throws ObjectNotFoundException, DatabaseException {
062:
063: Connection connection = null;
064: PreparedStatement statement = null;
065: ResultSet resultSet = null;
066: StringBuffer sql = new StringBuffer(512);
067: sql
068: .append("SELECT post_id, bbcode_uid, post_subject, post_text");
069: sql.append(" FROM " + TABLE_NAME);
070: sql.append(" WHERE post_id = ?");
071: try {
072: connection = DBUtils.getPhpbbConnection();
073: statement = connection.prepareStatement(sql.toString());
074: statement.setInt(1, post_id);
075: resultSet = statement.executeQuery();
076: if (!resultSet.next()) {
077: throw new ObjectNotFoundException(
078: "Cannot find the row in table phpbb_posts_text where primary key = ("
079: + post_id + ").");
080: }
081:
082: PhpbbPostText bean = new PhpbbPostText();
083: bean.setpost_id(resultSet.getInt("post_id"));
084: bean.setbbcode_uid(resultSet.getString("bbcode_uid"));
085: bean.setpost_subject(resultSet.getString("post_subject"));
086: bean.setpost_text(resultSet.getString("post_text"));
087: return bean;
088: } catch (SQLException sqle) {
089: throw new DatabaseException(
090: "Error executing SQL in phpbb_posts_textDAOImplJDBC.getBean(pk).");
091: } finally {
092: DBUtils.closeResultSet(resultSet);
093: DBUtils.closeStatement(statement);
094: DBUtils.closeConnection(connection);
095: }
096: }
097:
098: /*
099: * Included columns: post_id, bbcode_uid, post_subject, post_text
100: * Excluded columns:
101: */
102: public String getPostTextFromPostID(int post_id)
103: throws ObjectNotFoundException, DatabaseException {
104:
105: Connection connection = null;
106: PreparedStatement statement = null;
107: ResultSet resultSet = null;
108: StringBuffer sql = new StringBuffer(512);
109: sql.append("SELECT post_text");
110: sql.append(" FROM " + TABLE_NAME);
111: sql.append(" WHERE post_id = ?");
112: try {
113: connection = DBUtils.getPhpbbConnection();
114: statement = connection.prepareStatement(sql.toString());
115: statement.setInt(1, post_id);
116: resultSet = statement.executeQuery();
117: if (!resultSet.next()) {
118: throw new ObjectNotFoundException(
119: "Cannot find the row in table phpbb_posts_text where primary key = ("
120: + post_id + ").");
121: }
122: return resultSet.getString("post_text");
123: } catch (SQLException sqle) {
124: throw new DatabaseException(
125: "Error executing SQL in phpbb_posts_textDAOImplJDBC.getBean(pk).");
126: } finally {
127: DBUtils.closeResultSet(resultSet);
128: DBUtils.closeStatement(statement);
129: DBUtils.closeConnection(connection);
130: }
131: }
132:
133: }
|