0001: /*
0002: * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/db/jdbc/ForumDAOImplJDBC.java,v 1.38 2008/01/15 11:17:53 minhnn Exp $
0003: * $Author: minhnn $
0004: * $Revision: 1.38 $
0005: * $Date: 2008/01/15 11:17:53 $
0006: *
0007: * ====================================================================
0008: *
0009: * Copyright (C) 2002-2007 by MyVietnam.net
0010: *
0011: * All copyright notices regarding mvnForum MUST remain
0012: * intact in the scripts and in the outputted HTML.
0013: * The "powered by" text/logo with a link back to
0014: * http://www.mvnForum.com and http://www.MyVietnam.net in
0015: * the footer of the pages MUST remain visible when the pages
0016: * are viewed on the internet or intranet.
0017: *
0018: * This program is free software; you can redistribute it and/or modify
0019: * it under the terms of the GNU General Public License as published by
0020: * the Free Software Foundation; either version 2 of the License, or
0021: * any later version.
0022: *
0023: * This program is distributed in the hope that it will be useful,
0024: * but WITHOUT ANY WARRANTY; without even the implied warranty of
0025: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0026: * GNU General Public License for more details.
0027: *
0028: * You should have received a copy of the GNU General Public License
0029: * along with this program; if not, write to the Free Software
0030: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0031: *
0032: * Support can be obtained from support forums at:
0033: * http://www.mvnForum.com/mvnforum/index
0034: *
0035: * Correspondence and Marketing Questions can be sent to:
0036: * info at MyVietnam net
0037: *
0038: * @author: Minh Nguyen
0039: * @author: Mai Nguyen
0040: */
0041: package com.mvnforum.db.jdbc;
0042:
0043: import java.io.StringReader;
0044: import java.sql.*;
0045: import java.util.ArrayList;
0046: import java.util.Collection;
0047:
0048: import com.mvnforum.db.*;
0049:
0050: import net.myvietnam.mvncore.db.DBUtils;
0051: import net.myvietnam.mvncore.exception.*;
0052:
0053: import org.apache.commons.logging.Log;
0054: import org.apache.commons.logging.LogFactory;
0055:
0056: public class ForumDAOImplJDBC implements ForumDAO {
0057:
0058: private static Log log = LogFactory.getLog(ForumDAOImplJDBC.class);
0059:
0060: // this variable will support caching if cache for this class is needed
0061: private static boolean m_dirty = true;
0062:
0063: public ForumDAOImplJDBC() {
0064: }
0065:
0066: public static boolean isDirty() {
0067: return m_dirty;
0068: }
0069:
0070: public static void setDirty(boolean dirty) {
0071: m_dirty = dirty;
0072: }
0073:
0074: public void findByPrimaryKey(int forumID)
0075: throws ObjectNotFoundException, DatabaseException {
0076:
0077: Connection connection = null;
0078: PreparedStatement statement = null;
0079: ResultSet resultSet = null;
0080: StringBuffer sql = new StringBuffer(512);
0081: sql.append("SELECT ForumID");
0082: sql.append(" FROM " + TABLE_NAME);
0083: sql.append(" WHERE ForumID = ?");
0084: try {
0085: connection = DBUtils.getConnection();
0086: statement = connection.prepareStatement(sql.toString());
0087: statement.setInt(1, forumID);
0088: resultSet = statement.executeQuery();
0089: if (!resultSet.next()) {
0090: throw new ObjectNotFoundException(
0091: "Cannot find the primary key (" + forumID
0092: + ") in table 'Forum'.");
0093: }
0094: } catch (SQLException sqle) {
0095: log.error("Sql Execution Error!", sqle);
0096: throw new DatabaseException(
0097: "Error executing SQL in ForumDAOImplJDBC.findByPrimaryKey.");
0098: } finally {
0099: DBUtils.closeResultSet(resultSet);
0100: DBUtils.closeStatement(statement);
0101: DBUtils.closeConnection(connection);
0102: }
0103: }
0104:
0105: public void findByAlternateKey_ForumName_CategoryID(
0106: String forumName, int categoryID)
0107: throws ObjectNotFoundException, DatabaseException {
0108:
0109: Connection connection = null;
0110: PreparedStatement statement = null;
0111: ResultSet resultSet = null;
0112: StringBuffer sql = new StringBuffer(512);
0113: sql.append("SELECT ForumName, CategoryID");
0114: sql.append(" FROM " + TABLE_NAME);
0115: if (DBUtils.isCaseSensitiveDatebase()) {
0116: sql
0117: .append(" WHERE lower(ForumName) = lower(?) AND CategoryID = ?");
0118: } else {
0119: sql.append(" WHERE ForumName = ? AND CategoryID = ?");
0120: }
0121: try {
0122: connection = DBUtils.getConnection();
0123: statement = connection.prepareStatement(sql.toString());
0124: statement.setString(1, forumName);
0125: statement.setInt(2, categoryID);
0126: resultSet = statement.executeQuery();
0127: if (!resultSet.next()) {
0128: throw new ObjectNotFoundException(
0129: "Cannot find the alternate key [ForumName, CategoryID] ("
0130: + forumName + ", " + categoryID
0131: + ") in table 'Forum'.");
0132: }
0133: } catch (SQLException sqle) {
0134: log.error("Sql Execution Error!", sqle);
0135: throw new DatabaseException(
0136: "Error executing SQL in ForumDAOImplJDBC.findByAlternateKey_ForumName_CategoryID.");
0137: } finally {
0138: DBUtils.closeResultSet(resultSet);
0139: DBUtils.closeStatement(statement);
0140: DBUtils.closeConnection(connection);
0141: }
0142: }
0143:
0144: /*
0145: * Included columns: CategoryID, ForumOwnerName, LastPostMemberName, ForumName, ForumDesc, ForumCreationDate,
0146: * ForumModifiedDate, ForumLastPostDate, ForumOrder, ForumType, ForumFormatOption,
0147: * ForumOption, ForumStatus, ForumModerationMode, ForumPassword, ForumThreadCount,
0148: * ForumPostCount
0149: * Excluded columns: ForumID
0150: */
0151: public void create(int categoryID, String forumOwnerName,
0152: String lastPostMemberName, String forumName,
0153: String forumDesc, Timestamp forumCreationDate,
0154: Timestamp forumModifiedDate, Timestamp forumLastPostDate,
0155: int forumOrder, int forumType, int forumFormatOption,
0156: int forumOption, int forumStatus, int forumModerationMode,
0157: String forumPassword, int forumThreadCount,
0158: int forumPostCount) throws CreateException,
0159: DatabaseException, DuplicateKeyException,
0160: ForeignKeyNotFoundException {
0161:
0162: // check valid
0163: ForumBean.validateForumType(forumType);
0164: ForumBean.validateForumFormatOption(forumFormatOption);
0165: ForumBean.validateForumOption(forumOption);
0166: ForumBean.validateForumStatus(forumStatus);
0167: ForumBean.validateForumModerationMode(forumModerationMode);
0168:
0169: // @todo: Comment this try-catch block if the needed columns dont have attribute 'include'
0170: // If this is the case, then it is highly recommended that you regenerate this method with the attribute 'include' turned on
0171: try {
0172: //Check if alternate key already exists
0173: findByAlternateKey_ForumName_CategoryID(forumName,
0174: categoryID);
0175: //If so, then we have to throw an exception
0176: throw new DuplicateKeyException(
0177: "Alternate key already exists. Cannot create new Forum with the same [ForumName, CategoryID] ("
0178: + forumName + ", " + categoryID + ").");
0179: } catch (ObjectNotFoundException e) {
0180: //Otherwise we can go ahead
0181: }
0182:
0183: try {
0184: // @todo: modify the parameter list as needed
0185: // You may have to regenerate this method if the needed columns dont have attribute 'include'
0186: DAOFactory.getCategoryDAO().findByPrimaryKey(categoryID);
0187: } catch (ObjectNotFoundException e) {
0188: throw new ForeignKeyNotFoundException(
0189: "Foreign key refers to table 'Category' does not exist. Cannot create new Forum.");
0190: }
0191:
0192: try {
0193: // @todo: modify the parameter list as needed
0194: // You may have to regenerate this method if the needed columns dont have attribute 'include'
0195: if (forumOwnerName.length() > 0) {
0196: DAOFactory.getMemberDAO()
0197: .findByAlternateKey_MemberName(forumOwnerName);
0198: }
0199: } catch (ObjectNotFoundException e) {
0200: throw new ForeignKeyNotFoundException(
0201: "Foreign key refers to table 'Member' does not exist. Cannot create new Forum.");
0202: }
0203:
0204: Connection connection = null;
0205: PreparedStatement statement = null;
0206: StringBuffer sql = new StringBuffer(512);
0207: sql
0208: .append("INSERT INTO "
0209: + TABLE_NAME
0210: + " (CategoryID, ForumOwnerName, LastPostMemberName, ForumName, ForumDesc, ForumCreationDate, ForumModifiedDate, ForumLastPostDate, ForumOrder, ForumType, ForumFormatOption, ForumOption, ForumStatus, ForumModerationMode, ForumPassword, ForumThreadCount, ForumPostCount)");
0211: sql
0212: .append(" VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
0213: try {
0214: connection = DBUtils.getConnection();
0215: statement = connection.prepareStatement(sql.toString());
0216:
0217: statement.setInt(1, categoryID);
0218: statement.setString(2, forumOwnerName);
0219: statement.setString(3, lastPostMemberName);
0220: statement.setString(4, forumName);
0221: if (DBUtils.getDatabaseType() == DBUtils.DATABASE_ORACLE) {
0222: statement.setCharacterStream(5, new StringReader(
0223: forumDesc), forumDesc.length());
0224: } else {
0225: statement.setString(5, forumDesc);
0226: }
0227: statement.setTimestamp(6, forumCreationDate);
0228: statement.setTimestamp(7, forumModifiedDate);
0229: statement.setTimestamp(8, forumLastPostDate);
0230: statement.setInt(9, forumOrder);
0231: statement.setInt(10, forumType);
0232: statement.setInt(11, forumFormatOption);
0233: statement.setInt(12, forumOption);
0234: statement.setInt(13, forumStatus);
0235: statement.setInt(14, forumModerationMode);
0236: statement.setString(15, forumPassword);
0237: statement.setInt(16, forumThreadCount);
0238: statement.setInt(17, forumPostCount);
0239:
0240: if (statement.executeUpdate() != 1) {
0241: throw new CreateException(
0242: "Error adding a row into table 'Forum'.");
0243: }
0244: m_dirty = true;
0245: } catch (SQLException sqle) {
0246: log.error("Sql Execution Error!", sqle);
0247: throw new DatabaseException(
0248: "Error executing SQL in ForumDAOImplJDBC.create.");
0249: } finally {
0250: DBUtils.closeStatement(statement);
0251: DBUtils.closeConnection(connection);
0252: }
0253: }
0254:
0255: /*
0256: * Included columns: CategoryID, LastPostMemberName, ForumName, ForumDesc, ForumCreationDate,
0257: * ForumModifiedDate, ForumLastPostDate, ForumOrder, ForumType, ForumFormatOption,
0258: * ForumOption, ForumStatus, ForumModerationMode, ForumPassword, ForumThreadCount,
0259: * ForumPostCount
0260: * Excluded columns: ForumID
0261: */
0262: public int createForum(int categoryID, String forumOwnerName,
0263: String lastPostMemberName, String forumName,
0264: String forumDesc, Timestamp forumCreationDate,
0265: Timestamp forumModifiedDate, Timestamp forumLastPostDate,
0266: int forumOrder, int forumType, int forumFormatOption,
0267: int forumOption, int forumStatus, int forumModerationMode,
0268: String forumPassword, int forumThreadCount,
0269: int forumPostCount) throws CreateException,
0270: DatabaseException, DuplicateKeyException,
0271: ForeignKeyNotFoundException {
0272:
0273: create(categoryID, forumOwnerName, lastPostMemberName,
0274: forumName, forumDesc, forumCreationDate,
0275: forumModifiedDate, forumLastPostDate, forumOrder,
0276: forumType, forumFormatOption, forumOption, forumStatus,
0277: forumModerationMode, forumPassword, forumThreadCount,
0278: forumPostCount);
0279:
0280: ForumBean forumBean = null;
0281: try {
0282: forumBean = getBean_byAlternateKey_ForumName_CategoryID(
0283: forumName, categoryID);
0284: } catch (ObjectNotFoundException ex) {
0285: log.error("Cannot find ForumID after creating forum.", ex);
0286: }
0287: return forumBean.getForumID();
0288: }
0289:
0290: public void delete(int forumID) throws DatabaseException,
0291: ObjectNotFoundException {
0292:
0293: Connection connection = null;
0294: PreparedStatement statement = null;
0295: StringBuffer sql = new StringBuffer(512);
0296: sql.append("DELETE FROM " + TABLE_NAME);
0297: sql.append(" WHERE ForumID = ?");
0298:
0299: try {
0300: connection = DBUtils.getConnection();
0301: statement = connection.prepareStatement(sql.toString());
0302: statement.setInt(1, forumID);
0303: if (statement.executeUpdate() != 1) {
0304: throw new ObjectNotFoundException(
0305: "Cannot delete a row in table Forum where primary key = ("
0306: + forumID + ").");
0307: }
0308: m_dirty = true;
0309: } catch (SQLException sqle) {
0310: log.error("Sql Execution Error!", sqle);
0311: throw new DatabaseException(
0312: "Error executing SQL in ForumDAOImplJDBC.delete.");
0313: } finally {
0314: DBUtils.closeStatement(statement);
0315: DBUtils.closeConnection(connection);
0316: }
0317: }
0318:
0319: /*
0320: * Included columns: CategoryID, ForumOwnerName, ForumName, ForumDesc, ForumModifiedDate, ForumOrder,
0321: * ForumType, ForumFormatOption, ForumOption, ForumStatus, ForumModerationMode
0322: * Excluded columns: ForumID, LastPostMemberName, ForumCreationDate, ForumLastPostDate, ForumPassword,
0323: * ForumThreadCount, ForumPostCount
0324: */
0325: public void update(
0326: int forumID, // primary key
0327: int categoryID, String forumOwnerName, String forumName,
0328: String forumDesc, Timestamp forumModifiedDate,
0329: int forumOrder, int forumType, int forumFormatOption,
0330: int forumOption, int forumStatus, int forumModerationMode)
0331: throws ObjectNotFoundException, DatabaseException,
0332: DuplicateKeyException, ForeignKeyNotFoundException,
0333: IllegalArgumentException {
0334:
0335: // check valid
0336: ForumBean.validateForumType(forumType);
0337: ForumBean.validateForumFormatOption(forumFormatOption);
0338: ForumBean.validateForumOption(forumOption);
0339: ForumBean.validateForumStatus(forumStatus);
0340: ForumBean.validateForumModerationMode(forumModerationMode);
0341:
0342: ForumBean bean = getForum(forumID);
0343:
0344: if ((forumName.equalsIgnoreCase(bean.getForumName()) == false)
0345: || (categoryID != bean.getCategoryID())) {
0346: // Forum tries to change its alternate key <ForumName, CategoryID>, so we must check if it already exist
0347: try {
0348: findByAlternateKey_ForumName_CategoryID(forumName,
0349: categoryID);
0350: throw new DuplicateKeyException(
0351: "Alternate key [ForumName, CategoryID] ("
0352: + forumName
0353: + ", "
0354: + categoryID
0355: + ") already exists. Cannot update Forum.");
0356: } catch (ObjectNotFoundException e) {
0357: //Otherwise we can go ahead
0358: }
0359: }
0360:
0361: try {
0362: // @todo: modify the parameter list as needed
0363: // If this method does not change the foreign key columns, you can comment this block of code.
0364: DAOFactory.getCategoryDAO().findByPrimaryKey(categoryID);
0365: } catch (ObjectNotFoundException e) {
0366: throw new ForeignKeyNotFoundException(
0367: "Foreign key refers to table 'Category' does not exist. Cannot update table 'Forum'.");
0368: }
0369:
0370: try {
0371: // @todo : modify the parameter list as needed
0372: // You may have to regenerate this method if the needed columns dont have attribute 'include'
0373: if (forumOwnerName.length() > 0) {
0374: DAOFactory.getMemberDAO()
0375: .findByAlternateKey_MemberName(forumOwnerName);
0376: }
0377: } catch (ObjectNotFoundException e) {
0378: throw new ForeignKeyNotFoundException(
0379: "Foreign key refers to table 'Member' does not exist. Cannot update Forum.");
0380: }
0381:
0382: Connection connection = null;
0383: PreparedStatement statement = null;
0384: StringBuffer sql = new StringBuffer(512);
0385: sql
0386: .append("UPDATE "
0387: + TABLE_NAME
0388: + " SET CategoryID = ?, ForumOwnerName = ?, ForumName = ?, ForumDesc = ?, ForumModifiedDate = ?, ForumOrder = ?, ForumType = ?, ForumFormatOption = ?, ForumOption = ?, ForumStatus = ?, ForumModerationMode = ?");
0389: sql.append(" WHERE ForumID = ?");
0390: try {
0391: connection = DBUtils.getConnection();
0392: statement = connection.prepareStatement(sql.toString());
0393:
0394: // // column(s) to update
0395: statement.setInt(1, categoryID);
0396: statement.setString(2, forumOwnerName);
0397: statement.setString(3, forumName);
0398: if (DBUtils.getDatabaseType() == DBUtils.DATABASE_ORACLE) {
0399: statement.setCharacterStream(4, new StringReader(
0400: forumDesc), forumDesc.length());
0401: } else {
0402: statement.setString(4, forumDesc);
0403: }
0404: statement.setTimestamp(5, forumModifiedDate);
0405: statement.setInt(6, forumOrder);
0406: statement.setInt(7, forumType);
0407: statement.setInt(8, forumFormatOption);
0408: statement.setInt(9, forumOption);
0409: statement.setInt(10, forumStatus);
0410: statement.setInt(11, forumModerationMode);
0411:
0412: // primary key column(s)
0413: statement.setInt(12, forumID);
0414:
0415: if (statement.executeUpdate() != 1) {
0416: throw new ObjectNotFoundException(
0417: "Cannot update table Forum where primary key = ("
0418: + forumID + ").");
0419: }
0420: m_dirty = true;
0421: } catch (SQLException sqle) {
0422: log.error("Sql Execution Error!", sqle);
0423: throw new DatabaseException(
0424: "Error executing SQL in ForumDAOImplJDBC.update.");
0425: } finally {
0426: DBUtils.closeStatement(statement);
0427: DBUtils.closeConnection(connection);
0428: }
0429: }
0430:
0431: /*
0432: * Included columns: LastPostMemberName
0433: * Excluded columns: ForumID, CategoryID, ForumOwnerName, ForumName, ForumDesc, ForumCreationDate,
0434: * ForumModifiedDate, ForumLastPostDate, ForumOrder, ForumType, ForumFormatOption,
0435: * ForumOption, ForumStatus, ForumModerationMode, ForumPassword, ForumThreadCount,
0436: * ForumPostCount
0437: */
0438: public void updateLastPostMemberName(int forumID, // primary key
0439: String lastPostMemberName) throws ObjectNotFoundException,
0440: DatabaseException, ForeignKeyNotFoundException {
0441:
0442: //allow anonymous/guests to send posts (if admin allows that)
0443: if ((lastPostMemberName != null)
0444: && (lastPostMemberName.length() > 0)) {
0445: try {
0446: // @todo: modify the parameter list as needed
0447: // If this method does not change the foreign key columns, you can comment this block of code.
0448: DAOFactory.getMemberDAO()
0449: .findByAlternateKey_MemberName(
0450: lastPostMemberName);
0451: } catch (ObjectNotFoundException e) {
0452: throw new ForeignKeyNotFoundException(
0453: "Foreign key refers to table 'Member' does not exist. Cannot update table 'Forum'.");
0454: }
0455: } else
0456: lastPostMemberName = ""; //so we don't get 'null' in sql query
0457:
0458: Connection connection = null;
0459: PreparedStatement statement = null;
0460: StringBuffer sql = new StringBuffer(512);
0461: sql.append("UPDATE " + TABLE_NAME
0462: + " SET LastPostMemberName = ?");
0463: sql.append(" WHERE ForumID = ?");
0464: try {
0465: connection = DBUtils.getConnection();
0466: statement = connection.prepareStatement(sql.toString());
0467:
0468: // // column(s) to update
0469: statement.setString(1, lastPostMemberName);
0470:
0471: // primary key column(s)
0472: statement.setInt(2, forumID);
0473:
0474: if (statement.executeUpdate() != 1) {
0475: // Some drivers dont update database if it detect old and new data are the same
0476: // @todo: should check driver, not check database
0477: // Currently there is only one driver: Caucho MySql driver
0478: if (DBUtils.getDatabaseType() != DBUtils.DATABASE_MYSQL) {
0479: throw new ObjectNotFoundException(
0480: "Cannot update table Forum where primary key = ("
0481: + forumID + ").");
0482: } else {
0483: log
0484: .warn("WARNING: By pass the check for Caucho MySql driver.");
0485: }
0486: }
0487: //@todo: coi lai cho nay
0488: //ATTENTION
0489: setDirty(true);
0490: } catch (SQLException sqle) {
0491: log.error("Sql Execution Error!", sqle);
0492: throw new DatabaseException(
0493: "Error executing SQL in ForumDAOImplJDBC.updateLastPostMemberName.");
0494: } finally {
0495: DBUtils.closeStatement(statement);
0496: DBUtils.closeConnection(connection);
0497: }
0498: }
0499:
0500: /*
0501: * Included columns: ForumLastPostDate
0502: * Excluded columns: ForumID, CategoryID, ForumOwnerName, LastPostMemberName, ForumName, ForumDesc,
0503: * ForumCreationDate, ForumModifiedDate, ForumOrder, ForumType, ForumFormatOption,
0504: * ForumOption, ForumStatus, ForumModerationMode, ForumPassword, ForumThreadCount,
0505: * ForumPostCount
0506: */
0507: public void updateLastPostDate(int forumID, // primary key
0508: Timestamp forumLastPostDate)
0509: throws ObjectNotFoundException, DatabaseException {
0510:
0511: Connection connection = null;
0512: PreparedStatement statement = null;
0513: StringBuffer sql = new StringBuffer(512);
0514: sql.append("UPDATE " + TABLE_NAME
0515: + " SET ForumLastPostDate = ?");
0516: sql.append(" WHERE ForumID = ?");
0517: try {
0518: connection = DBUtils.getConnection();
0519: statement = connection.prepareStatement(sql.toString());
0520:
0521: // // column(s) to update
0522: statement.setTimestamp(1, forumLastPostDate);
0523:
0524: // primary key column(s)
0525: statement.setInt(2, forumID);
0526:
0527: if (statement.executeUpdate() != 1) {
0528: throw new ObjectNotFoundException(
0529: "Cannot update table Forum where primary key = ("
0530: + forumID + ").");
0531: }
0532: m_dirty = true;
0533: } catch (SQLException sqle) {
0534: log.error("Sql Execution Error!", sqle);
0535: throw new DatabaseException(
0536: "Error executing SQL in ForumDAOImplJDBC.updateLastPostDate.");
0537: } finally {
0538: DBUtils.closeStatement(statement);
0539: DBUtils.closeConnection(connection);
0540: }
0541: }
0542:
0543: public void resetForumOwnerNameWhenDeleteMember(String memberName)
0544: throws DatabaseException {
0545:
0546: if ((memberName == null) || (memberName.length() == 0)) {
0547: return;
0548: }
0549:
0550: Connection connection = null;
0551: PreparedStatement statement = null;
0552: StringBuffer sql = new StringBuffer(512);
0553: sql.append("UPDATE " + TABLE_NAME);
0554: if (DBUtils.isCaseSensitiveDatebase()) {
0555: sql
0556: .append(" SET ForumOwnerName = '' WHERE lower(ForumOwnerName) = lower(?)");
0557: } else {
0558: sql
0559: .append(" SET ForumOwnerName = '' WHERE ForumOwnerName = ?");
0560: }
0561: try {
0562: connection = DBUtils.getConnection();
0563: statement = connection.prepareStatement(sql.toString());
0564: statement.setString(1, memberName);
0565: statement.executeUpdate();
0566: } catch (SQLException sqlException) {
0567: log.error("SQL execution error!", sqlException);
0568: throw new DatabaseException(
0569: "Error when executing SQL in ForumDAOImplJDBC.resetForumOwnerNameWhenDeleteMember");
0570: } finally {
0571: DBUtils.closeStatement(statement);
0572: DBUtils.closeConnection(connection);
0573: }
0574: }
0575:
0576: /*
0577: * Included columns: ForumThreadCount, ForumPostCount
0578: * Excluded columns: ForumID, CategoryID, ForumOwnerName, LastPostMemberName, ForumName, ForumDesc,
0579: * ForumCreationDate, ForumModifiedDate, ForumLastPostDate, ForumOrder, ForumType,
0580: * ForumFormatOption, ForumOption, ForumStatus, ForumModerationMode, ForumPassword
0581: */
0582: public void updateStatistics(int forumID, // primary key
0583: int forumThreadCount, int forumPostCount)
0584: throws ObjectNotFoundException, DatabaseException {
0585:
0586: Connection connection = null;
0587: PreparedStatement statement = null;
0588: StringBuffer sql = new StringBuffer(512);
0589: sql.append("UPDATE " + TABLE_NAME
0590: + " SET ForumThreadCount = ?, ForumPostCount = ?");
0591: sql.append(" WHERE ForumID = ?");
0592: try {
0593: connection = DBUtils.getConnection();
0594: statement = connection.prepareStatement(sql.toString());
0595:
0596: // // column(s) to update
0597: statement.setInt(1, forumThreadCount);
0598: statement.setInt(2, forumPostCount);
0599:
0600: // primary key column(s)
0601: statement.setInt(3, forumID);
0602:
0603: if (statement.executeUpdate() != 1) {
0604: throw new ObjectNotFoundException(
0605: "Cannot update table Forum where primary key = ("
0606: + forumID + ").");
0607: }
0608: m_dirty = true;
0609: } catch (SQLException sqle) {
0610: log.error("Sql Execution Error!", sqle);
0611: throw new DatabaseException(
0612: "Error executing SQL in ForumDAOImplJDBC.updateStatistics.");
0613: } finally {
0614: DBUtils.closeStatement(statement);
0615: DBUtils.closeConnection(connection);
0616: }
0617: }
0618:
0619: /**
0620: * This method should be call only when we can make sure that threadID is in database
0621: */
0622: public void increasePostCount(int forumID)
0623: throws DatabaseException, ObjectNotFoundException {
0624:
0625: Connection connection = null;
0626: PreparedStatement statement = null;
0627: String sql = "UPDATE "
0628: + TABLE_NAME
0629: + " SET ForumPostCount = ForumPostCount + 1 WHERE ForumID = ?";
0630: try {
0631: connection = DBUtils.getConnection();
0632: statement = connection.prepareStatement(sql);
0633: statement.setInt(1, forumID);
0634: if (statement.executeUpdate() != 1) {
0635: throw new ObjectNotFoundException(
0636: "Cannot update the ForumPostCount in table Forum. Please contact Web site Administrator.");
0637: }
0638: //@todo: coi lai cho nay
0639: // ATTENTION !!!
0640: setDirty(true);
0641: } catch (SQLException sqle) {
0642: log.error("Sql Execution Error!", sqle);
0643: throw new DatabaseException(
0644: "Error executing SQL in ForumDAOImplJDBC.increasePostCount.");
0645: } finally {
0646: DBUtils.closeStatement(statement);
0647: DBUtils.closeConnection(connection);
0648: }
0649: }
0650:
0651: /**
0652: * This method should be call only when we can make sure that threadID is in database
0653: */
0654: public void increaseThreadCount(int forumID)
0655: throws DatabaseException, ObjectNotFoundException {
0656:
0657: Connection connection = null;
0658: PreparedStatement statement = null;
0659: String sql = "UPDATE "
0660: + TABLE_NAME
0661: + " SET ForumThreadCount = ForumThreadCount + 1 WHERE ForumID = ?";
0662: try {
0663: connection = DBUtils.getConnection();
0664: statement = connection.prepareStatement(sql);
0665: statement.setInt(1, forumID);
0666: if (statement.executeUpdate() != 1) {
0667: throw new ObjectNotFoundException(
0668: "Cannot update the ForumThreadCount in table Forum. Please contact Web site Administrator.");
0669: }
0670: setDirty(true);
0671: } catch (SQLException sqle) {
0672: log.error("Sql Execution Error!", sqle);
0673: throw new DatabaseException(
0674: "Error executing SQL in ForumDAOImplJDBC.increaseThreadCount.");
0675: } finally {
0676: DBUtils.closeStatement(statement);
0677: DBUtils.closeConnection(connection);
0678: }
0679: }
0680:
0681: /**
0682: * This method should be call only when we can make sure that threadID is in database
0683: */
0684: public void decreaseThreadCount(int forumID)
0685: throws DatabaseException, ObjectNotFoundException {
0686:
0687: Connection connection = null;
0688: PreparedStatement statement = null;
0689: String sql = "UPDATE "
0690: + TABLE_NAME
0691: + " SET ForumThreadCount = ForumThreadCount - 1 WHERE ForumID = ?";
0692: try {
0693: connection = DBUtils.getConnection();
0694: statement = connection.prepareStatement(sql);
0695: statement.setInt(1, forumID);
0696: if (statement.executeUpdate() != 1) {
0697: throw new ObjectNotFoundException(
0698: "Cannot update the ForumThreadCount in table Forum. Please contact Web site Administrator.");
0699: }
0700: setDirty(true);
0701: } catch (SQLException sqle) {
0702: log.error("Sql Execution Error!", sqle);
0703: throw new DatabaseException(
0704: "Error executing SQL in ForumDAOImplJDBC.decreaseThreadCount.");
0705: } finally {
0706: DBUtils.closeStatement(statement);
0707: DBUtils.closeConnection(connection);
0708: }
0709: }
0710:
0711: /*
0712: * Included columns: CategoryID, ForumOwnerName, LastPostMemberName, ForumName, ForumDesc, ForumCreationDate,
0713: * ForumModifiedDate, ForumLastPostDate, ForumOrder, ForumType, ForumFormatOption,
0714: * ForumOption, ForumStatus, ForumModerationMode, ForumPassword, ForumThreadCount,
0715: * ForumPostCount
0716: * Excluded columns: ForumID
0717: */
0718: public ForumBean getForum(int forumID)
0719: throws ObjectNotFoundException, DatabaseException {
0720:
0721: Connection connection = null;
0722: PreparedStatement statement = null;
0723: ResultSet resultSet = null;
0724: StringBuffer sql = new StringBuffer(512);
0725: sql
0726: .append("SELECT CategoryID, ForumOwnerName, LastPostMemberName, ForumName, ForumDesc, ForumCreationDate, ForumModifiedDate, ForumLastPostDate, ForumOrder, ForumType, ForumFormatOption, ForumOption, ForumStatus, ForumModerationMode, ForumPassword, ForumThreadCount, ForumPostCount");
0727: sql.append(" FROM " + TABLE_NAME);
0728: sql.append(" WHERE ForumID = ?");
0729: try {
0730: connection = DBUtils.getConnection();
0731: statement = connection.prepareStatement(sql.toString());
0732: statement.setInt(1, forumID);
0733: resultSet = statement.executeQuery();
0734: if (!resultSet.next()) {
0735: throw new ObjectNotFoundException(
0736: "Cannot find the row in table Forum where primary key = ("
0737: + forumID + ").");
0738: }
0739:
0740: ForumBean bean = new ForumBean();
0741: // @todo: uncomment the following line(s) as needed
0742: bean.setForumID(forumID);
0743: bean.setCategoryID(resultSet.getInt("CategoryID"));
0744: bean.setForumOwnerName(resultSet
0745: .getString("ForumOwnerName"));
0746: bean.setLastPostMemberName(resultSet
0747: .getString("LastPostMemberName"));
0748: bean.setForumName(resultSet.getString("ForumName"));
0749: bean.setForumDesc(resultSet.getString("ForumDesc"));
0750: bean.setForumCreationDate(resultSet
0751: .getTimestamp("ForumCreationDate"));
0752: bean.setForumModifiedDate(resultSet
0753: .getTimestamp("ForumModifiedDate"));
0754: bean.setForumLastPostDate(resultSet
0755: .getTimestamp("ForumLastPostDate"));
0756: bean.setForumOrder(resultSet.getInt("ForumOrder"));
0757: bean.setForumType(resultSet.getInt("ForumType"));
0758: bean.setForumFormatOption(resultSet
0759: .getInt("ForumFormatOption"));
0760: bean.setForumOption(resultSet.getInt("ForumOption"));
0761: bean.setForumStatus(resultSet.getInt("ForumStatus"));
0762: bean.setForumModerationMode(resultSet
0763: .getInt("ForumModerationMode"));
0764: bean.setForumPassword(resultSet.getString("ForumPassword"));
0765: bean.setForumThreadCount(resultSet
0766: .getInt("ForumThreadCount"));
0767: bean.setForumPostCount(resultSet.getInt("ForumPostCount"));
0768: return bean;
0769: } catch (SQLException sqle) {
0770: log.error("Sql Execution Error!", sqle);
0771: throw new DatabaseException(
0772: "Error executing SQL in ForumDAOImplJDBC.getForum(pk).");
0773: } finally {
0774: DBUtils.closeResultSet(resultSet);
0775: DBUtils.closeStatement(statement);
0776: DBUtils.closeConnection(connection);
0777: }
0778: }
0779:
0780: /*
0781: * Included columns: ForumID, CategoryID, ForumOwnerName, LastPostMemberName, ForumName, ForumDesc,
0782: * ForumCreationDate, ForumModifiedDate, ForumLastPostDate, ForumOrder, ForumType,
0783: * ForumFormatOption, ForumOption, ForumStatus, ForumModerationMode, ForumPassword,
0784: * ForumThreadCount, ForumPostCount
0785: * Excluded columns:
0786: */
0787: public Collection getForums() throws DatabaseException {
0788:
0789: Connection connection = null;
0790: PreparedStatement statement = null;
0791: ResultSet resultSet = null;
0792: Collection retValue = new ArrayList();
0793: StringBuffer sql = new StringBuffer(512);
0794: sql
0795: .append("SELECT ForumID, CategoryID, ForumOwnerName, LastPostMemberName, ForumName, ForumDesc, ForumCreationDate, ForumModifiedDate, ForumLastPostDate, ForumOrder, ForumType, ForumFormatOption, ForumOption, ForumStatus, ForumModerationMode, ForumPassword, ForumThreadCount, ForumPostCount");
0796: sql.append(" FROM " + TABLE_NAME);
0797: //sql.append(" WHERE "); // @todo: uncomment as needed
0798: sql.append(" ORDER BY CategoryID ASC, ForumOrder ASC "); // @todo: uncomment as needed
0799: try {
0800: connection = DBUtils.getConnection();
0801: statement = connection.prepareStatement(sql.toString());
0802: resultSet = statement.executeQuery();
0803: while (resultSet.next()) {
0804: ForumBean bean = new ForumBean();
0805: bean.setForumID(resultSet.getInt("ForumID"));
0806: bean.setCategoryID(resultSet.getInt("CategoryID"));
0807: bean.setForumOwnerName(resultSet
0808: .getString("ForumOwnerName"));
0809: bean.setLastPostMemberName(resultSet
0810: .getString("LastPostMemberName"));
0811: bean.setForumName(resultSet.getString("ForumName"));
0812: bean.setForumDesc(resultSet.getString("ForumDesc"));
0813: bean.setForumCreationDate(resultSet
0814: .getTimestamp("ForumCreationDate"));
0815: bean.setForumModifiedDate(resultSet
0816: .getTimestamp("ForumModifiedDate"));
0817: bean.setForumLastPostDate(resultSet
0818: .getTimestamp("ForumLastPostDate"));
0819: bean.setForumOrder(resultSet.getInt("ForumOrder"));
0820: bean.setForumType(resultSet.getInt("ForumType"));
0821: bean.setForumFormatOption(resultSet
0822: .getInt("ForumFormatOption"));
0823: bean.setForumOption(resultSet.getInt("ForumOption"));
0824: bean.setForumStatus(resultSet.getInt("ForumStatus"));
0825: bean.setForumModerationMode(resultSet
0826: .getInt("ForumModerationMode"));
0827: bean.setForumPassword(resultSet
0828: .getString("ForumPassword"));
0829: bean.setForumThreadCount(resultSet
0830: .getInt("ForumThreadCount"));
0831: bean.setForumPostCount(resultSet
0832: .getInt("ForumPostCount"));
0833: retValue.add(bean);
0834: }
0835: return retValue;
0836: } catch (SQLException sqle) {
0837: log.error("Sql Execution Error!", sqle);
0838: throw new DatabaseException(
0839: "Error executing SQL in ForumDAOImplJDBC.getForums.");
0840: } finally {
0841: DBUtils.closeResultSet(resultSet);
0842: DBUtils.closeStatement(statement);
0843: DBUtils.closeConnection(connection);
0844: }
0845: }
0846:
0847: /*
0848: * Included columns: ForumID, CategoryID, ForumOwnerName, LastPostMemberName, ForumName, ForumDesc,
0849: * ForumCreationDate, ForumModifiedDate, ForumLastPostDate, ForumOrder, ForumType,
0850: * ForumFormatOption, ForumOption, ForumStatus, ForumModerationMode, ForumPassword,
0851: * ForumThreadCount, ForumPostCount
0852: * Excluded columns:
0853: */
0854: public Collection getForums_inCategory(int categoryID)
0855: throws DatabaseException {
0856:
0857: Connection connection = null;
0858: PreparedStatement statement = null;
0859: ResultSet resultSet = null;
0860: Collection retValue = new ArrayList();
0861: StringBuffer sql = new StringBuffer(512);
0862: sql
0863: .append("SELECT ForumID, CategoryID, ForumOwnerName, LastPostMemberName, ForumName, ForumDesc, ForumCreationDate, ForumModifiedDate, ForumLastPostDate, ForumOrder, ForumType, ForumFormatOption, ForumOption, ForumStatus, ForumModerationMode, ForumPassword, ForumThreadCount, ForumPostCount");
0864: sql.append(" FROM " + TABLE_NAME);
0865: sql.append(" WHERE CategoryID = ?");
0866: sql.append(" ORDER BY CategoryID ASC, ForumOrder ASC "); // @todo: uncomment as needed
0867: try {
0868: connection = DBUtils.getConnection();
0869: statement = connection.prepareStatement(sql.toString());
0870: statement.setInt(1, categoryID);
0871: resultSet = statement.executeQuery();
0872: while (resultSet.next()) {
0873: ForumBean bean = new ForumBean();
0874: bean.setForumID(resultSet.getInt("ForumID"));
0875: bean.setCategoryID(resultSet.getInt("CategoryID"));
0876: bean.setForumOwnerName(resultSet
0877: .getString("ForumOwnerName"));
0878: bean.setLastPostMemberName(resultSet
0879: .getString("LastPostMemberName"));
0880: bean.setForumName(resultSet.getString("ForumName"));
0881: bean.setForumDesc(resultSet.getString("ForumDesc"));
0882: bean.setForumCreationDate(resultSet
0883: .getTimestamp("ForumCreationDate"));
0884: bean.setForumModifiedDate(resultSet
0885: .getTimestamp("ForumModifiedDate"));
0886: bean.setForumLastPostDate(resultSet
0887: .getTimestamp("ForumLastPostDate"));
0888: bean.setForumOrder(resultSet.getInt("ForumOrder"));
0889: bean.setForumType(resultSet.getInt("ForumType"));
0890: bean.setForumFormatOption(resultSet
0891: .getInt("ForumFormatOption"));
0892: bean.setForumOption(resultSet.getInt("ForumOption"));
0893: bean.setForumStatus(resultSet.getInt("ForumStatus"));
0894: bean.setForumModerationMode(resultSet
0895: .getInt("ForumModerationMode"));
0896: bean.setForumPassword(resultSet
0897: .getString("ForumPassword"));
0898: bean.setForumThreadCount(resultSet
0899: .getInt("ForumThreadCount"));
0900: bean.setForumPostCount(resultSet
0901: .getInt("ForumPostCount"));
0902: retValue.add(bean);
0903: }
0904: return retValue;
0905: } catch (SQLException sqle) {
0906: log.error("Sql Execution Error!", sqle);
0907: throw new DatabaseException(
0908: "Error executing SQL in ForumDAOImplJDBC.getForums_inCategory.");
0909: } finally {
0910: DBUtils.closeResultSet(resultSet);
0911: DBUtils.closeStatement(statement);
0912: DBUtils.closeConnection(connection);
0913: }
0914: }
0915:
0916: /************************************************
0917: * Customized methods come below
0918: ************************************************/
0919:
0920: /**
0921: * This method should be call only when we can make sure that memberID is in database
0922: */
0923: public void decreaseForumOrder(int forumID,
0924: Timestamp forumModifiedDate) throws DatabaseException,
0925: ObjectNotFoundException {
0926:
0927: Connection connection = null;
0928: PreparedStatement statement = null;
0929: String sql = "UPDATE "
0930: + TABLE_NAME
0931: + " SET ForumOrder = ForumOrder - 1, ForumModifiedDate = ? WHERE ForumID = ?";
0932: try {
0933: connection = DBUtils.getConnection();
0934: statement = connection.prepareStatement(sql);
0935: statement.setTimestamp(1, forumModifiedDate);
0936: statement.setInt(2, forumID);
0937: if (statement.executeUpdate() != 1) {
0938: throw new ObjectNotFoundException(
0939: "Cannot update the ForumOrder in table Forum. Please contact Web site Administrator.");
0940: }
0941: //@todo: coi lai cho nay
0942: // ATTENTION !!!
0943: setDirty(true);
0944: } catch (SQLException sqle) {
0945: log.error("Sql Execution Error!", sqle);
0946: throw new DatabaseException(
0947: "Error executing SQL in ForumDAOImplJDBC.decreaseForumOrder.");
0948: } finally {
0949: DBUtils.closeStatement(statement);
0950: DBUtils.closeConnection(connection);
0951: }
0952: }
0953:
0954: /**
0955: * This method should be call only when we can make sure that memberID is in database
0956: */
0957: public void increaseForumOrder(int forumID,
0958: Timestamp forumModifiedDate) throws DatabaseException,
0959: ObjectNotFoundException {
0960:
0961: Connection connection = null;
0962: PreparedStatement statement = null;
0963: String sql = "UPDATE "
0964: + TABLE_NAME
0965: + " SET ForumOrder = ForumOrder + 1, ForumModifiedDate = ? WHERE ForumID = ?";
0966: try {
0967: connection = DBUtils.getConnection();
0968: statement = connection.prepareStatement(sql);
0969: statement.setTimestamp(1, forumModifiedDate);
0970: statement.setInt(2, forumID);
0971: if (statement.executeUpdate() != 1) {
0972: throw new ObjectNotFoundException(
0973: "Cannot update the ForumOrder in table Forum. Please contact Web site Administrator.");
0974: }
0975: //@todo: coi lai cho nay
0976: // ATTENTION !!!
0977: setDirty(true);
0978: } catch (SQLException sqle) {
0979: log.error("Sql Execution Error!", sqle);
0980: throw new DatabaseException(
0981: "Error executing SQL in ForumDAOImplJDBC.increaseForumOrder.");
0982: } finally {
0983: DBUtils.closeStatement(statement);
0984: DBUtils.closeConnection(connection);
0985: }
0986: }
0987:
0988: /*
0989: * Included columns: ForumID, CategoryID, ForumOwnerName, LastPostMemberName, ForumName, ForumDesc,
0990: * ForumCreationDate, ForumModifiedDate, ForumLastPostDate, ForumOrder, ForumType,
0991: * ForumFormatOption, ForumOption, ForumStatus, ForumModerationMode, ForumPassword,
0992: * ForumThreadCount, ForumPostCount
0993: * Excluded columns:
0994: */
0995: protected static ForumBean getBean_byAlternateKey_ForumName_CategoryID(
0996: String forumName, int categoryID)
0997: throws ObjectNotFoundException, DatabaseException {
0998:
0999: Connection connection = null;
1000: PreparedStatement statement = null;
1001: ResultSet resultSet = null;
1002: StringBuffer sql = new StringBuffer(512);
1003: sql
1004: .append("SELECT ForumID, CategoryID, ForumOwnerName, LastPostMemberName, ForumName, ForumDesc, ForumCreationDate, ForumModifiedDate, ForumLastPostDate, ForumOrder, ForumType, ForumFormatOption, ForumOption, ForumStatus, ForumModerationMode, ForumPassword, ForumThreadCount, ForumPostCount");
1005: sql.append(" FROM " + TABLE_NAME);
1006: sql.append(" WHERE ForumName = ? AND CategoryID = ?");
1007: try {
1008: connection = DBUtils.getConnection();
1009: statement = connection.prepareStatement(sql.toString());
1010: statement.setString(1, forumName);
1011: statement.setInt(2, categoryID);
1012: resultSet = statement.executeQuery();
1013: if (!resultSet.next()) {
1014: throw new ObjectNotFoundException(
1015: "Cannot find the row in table Forum where alternate key [ForumName, CategoryID] = ("
1016: + forumName + ", " + categoryID + ").");
1017: }
1018:
1019: ForumBean bean = new ForumBean();
1020: // @todo: uncomment the following line(s) as needed
1021: //bean.setForumName(forumName);
1022: //bean.setCategoryID(categoryID);
1023: bean.setForumID(resultSet.getInt("ForumID"));
1024: bean.setCategoryID(resultSet.getInt("CategoryID"));
1025: bean.setForumOwnerName(resultSet
1026: .getString("ForumOwnerName"));
1027: bean.setLastPostMemberName(resultSet
1028: .getString("LastPostMemberName"));
1029: bean.setForumName(resultSet.getString("ForumName"));
1030: bean.setForumDesc(resultSet.getString("ForumDesc"));
1031: bean.setForumCreationDate(resultSet
1032: .getTimestamp("ForumCreationDate"));
1033: bean.setForumModifiedDate(resultSet
1034: .getTimestamp("ForumModifiedDate"));
1035: bean.setForumLastPostDate(resultSet
1036: .getTimestamp("ForumLastPostDate"));
1037: bean.setForumOrder(resultSet.getInt("ForumOrder"));
1038: bean.setForumType(resultSet.getInt("ForumType"));
1039: bean.setForumFormatOption(resultSet
1040: .getInt("ForumFormatOption"));
1041: bean.setForumOption(resultSet.getInt("ForumOption"));
1042: bean.setForumStatus(resultSet.getInt("ForumStatus"));
1043: bean.setForumModerationMode(resultSet
1044: .getInt("ForumModerationMode"));
1045: bean.setForumPassword(resultSet.getString("ForumPassword"));
1046: bean.setForumThreadCount(resultSet
1047: .getInt("ForumThreadCount"));
1048: bean.setForumPostCount(resultSet.getInt("ForumPostCount"));
1049: return bean;
1050: } catch (SQLException sqle) {
1051: log.error("Sql Execution Error!", sqle);
1052: throw new DatabaseException(
1053: "Error executing SQL in ForumDAOImplJDBC.getBean_byAlternateKey_ForumName_CategoryID(ak).");
1054: } finally {
1055: DBUtils.closeResultSet(resultSet);
1056: DBUtils.closeStatement(statement);
1057: DBUtils.closeConnection(connection);
1058: }
1059: }
1060:
1061: /*
1062: *
1063: */
1064: public Collection getBeans_withSortSupport_limit_general(
1065: int offset, int rowsToReturn, String sort, String order)
1066: throws IllegalArgumentException, DatabaseException {
1067:
1068: if (offset < 0)
1069: throw new IllegalArgumentException(
1070: "The offset < 0 is not allowed.");
1071: if (rowsToReturn <= 0)
1072: throw new IllegalArgumentException(
1073: "The rowsToReturn <= 0 is not allowed.");
1074:
1075: if ((!sort.equals("ForumLastPostDate"))
1076: && (!sort.equals("ForumCreationDate"))
1077: && (!sort.equals("ForumName"))
1078: && (!sort.equals("ForumPostCount"))
1079: && (!sort.equals("ForumThreadCount"))) {
1080: throw new IllegalArgumentException(
1081: "Cannot sort, reason: dont understand the criteria '"
1082: + sort + "'.");
1083: }
1084:
1085: if ((!order.equals("ASC")) && (!order.equals("DESC"))) {
1086: throw new IllegalArgumentException(
1087: "Cannot sort, reason: dont understand the order '"
1088: + order + "'.");
1089: }
1090:
1091: Connection connection = null;
1092: PreparedStatement statement = null;
1093: ResultSet resultSet = null;
1094: Collection retValue = new ArrayList();
1095: StringBuffer sql = new StringBuffer(512);
1096:
1097: sql
1098: .append("SELECT ForumID, CategoryID, ForumOwnerName, LastPostMemberName, ForumName, ForumDesc, ForumCreationDate, ForumModifiedDate, ForumLastPostDate, ForumOrder, ForumType, ForumFormatOption, ForumOption, ForumStatus, ForumModerationMode, ForumPassword, ForumThreadCount, ForumPostCount");
1099: sql.append(" FROM " + TABLE_NAME);
1100: sql.append(" ORDER BY " + sort + " " + order);// ColumnName, ASC|DESC
1101: try {
1102: connection = DBUtils.getConnection();
1103: statement = connection.prepareStatement(sql.toString(),
1104: ResultSet.TYPE_SCROLL_INSENSITIVE,
1105: ResultSet.CONCUR_READ_ONLY);
1106:
1107: statement.setMaxRows(offset + rowsToReturn);
1108: try {
1109: statement.setFetchSize(Math.min(rowsToReturn,
1110: DBUtils.MAX_FETCH_SIZE));
1111: } catch (SQLException sqle) {
1112: //do nothing, postgreSQL does not support this method
1113: }
1114: resultSet = statement.executeQuery();
1115: boolean loop = resultSet.absolute(offset + 1);// the absolute method begin with 1 instead of 0 as in the LIMIT clause
1116: while (loop) {
1117: ForumBean bean = new ForumBean();
1118: bean.setForumID(resultSet.getInt("ForumID"));
1119: bean.setCategoryID(resultSet.getInt("CategoryID"));
1120: bean.setForumOwnerName(resultSet
1121: .getString("ForumOwnerName"));
1122: bean.setLastPostMemberName(resultSet
1123: .getString("LastPostMemberName"));
1124: bean.setForumName(resultSet.getString("ForumName"));
1125: bean.setForumDesc(resultSet.getString("ForumDesc"));
1126: bean.setForumCreationDate(resultSet
1127: .getTimestamp("ForumCreationDate"));
1128: bean.setForumModifiedDate(resultSet
1129: .getTimestamp("ForumModifiedDate"));
1130: bean.setForumLastPostDate(resultSet
1131: .getTimestamp("ForumLastPostDate"));
1132: bean.setForumOrder(resultSet.getInt("ForumOrder"));
1133: bean.setForumType(resultSet.getInt("ForumType"));
1134: bean.setForumFormatOption(resultSet
1135: .getInt("ForumFormatOption"));
1136: bean.setForumOption(resultSet.getInt("ForumOption"));
1137: bean.setForumStatus(resultSet.getInt("ForumStatus"));
1138: bean.setForumModerationMode(resultSet
1139: .getInt("ForumModerationMode"));
1140: bean.setForumPassword(resultSet
1141: .getString("ForumPassword"));
1142: bean.setForumThreadCount(resultSet
1143: .getInt("ForumThreadCount"));
1144: bean.setForumPostCount(resultSet
1145: .getInt("ForumPostCount"));
1146: retValue.add(bean);
1147: if (retValue.size() == rowsToReturn)
1148: break;// Fix the Sybase bug
1149: loop = resultSet.next();
1150: }//while
1151: return retValue;
1152: } catch (SQLException sqle) {
1153: log.error("Sql Execution Error!", sqle);
1154: throw new DatabaseException(
1155: "Error executing SQL in ForumDAOImplJDBC.getBeans_withSortSupport_limit_general.");
1156: } finally {
1157: DBUtils.closeResultSet(resultSet);
1158: DBUtils.resetStatement(statement);
1159: DBUtils.closeStatement(statement);
1160: DBUtils.closeConnection(connection);
1161: }
1162: }
1163:
1164: /*
1165: *
1166: */
1167: public Collection getBeans_withSortSupport_limit_mysql(int offset,
1168: int rowsToReturn, String sort, String order)
1169: throws IllegalArgumentException, DatabaseException {
1170: if (offset < 0)
1171: throw new IllegalArgumentException(
1172: "The offset < 0 is not allowed.");
1173: if (rowsToReturn <= 0)
1174: throw new IllegalArgumentException(
1175: "The rowsToReturn <= 0 is not allowed.");
1176:
1177: if ((!sort.equals("ForumLastPostDate"))
1178: && (!sort.equals("ForumCreationDate"))
1179: && (!sort.equals("ForumName"))
1180: && (!sort.equals("ForumPostCount"))
1181: && (!sort.equals("ForumThreadCount"))) {
1182: throw new IllegalArgumentException(
1183: "Cannot sort, reason: dont understand the criteria '"
1184: + sort + "'.");
1185: }
1186:
1187: if ((!order.equals("ASC")) && (!order.equals("DESC"))) {
1188: throw new IllegalArgumentException(
1189: "Cannot sort, reason: dont understand the order '"
1190: + order + "'.");
1191: }
1192:
1193: Connection connection = null;
1194: PreparedStatement statement = null;
1195: ResultSet resultSet = null;
1196: Collection retValue = new ArrayList();
1197: StringBuffer sql = new StringBuffer(512);
1198:
1199: sql
1200: .append("SELECT ForumID, CategoryID, ForumOwnerName, LastPostMemberName, ForumName, ForumDesc, ForumCreationDate, ForumModifiedDate, ForumLastPostDate, ForumOrder, ForumType, ForumFormatOption, ForumOption, ForumStatus, ForumModerationMode, ForumPassword, ForumThreadCount, ForumPostCount");
1201: sql.append(" FROM " + TABLE_NAME);
1202: sql.append(" ORDER BY " + sort + " " + order);// ColumnName, ASC|DESC
1203: sql.append(" LIMIT ?, ?");
1204:
1205: try {
1206: connection = DBUtils.getConnection();
1207: statement = connection.prepareStatement(sql.toString(),
1208: ResultSet.TYPE_SCROLL_INSENSITIVE,
1209: ResultSet.CONCUR_READ_ONLY);
1210:
1211: statement.setMaxRows(offset + rowsToReturn);
1212: statement.setInt(1, offset);
1213: statement.setInt(2, rowsToReturn);
1214: try {
1215: statement.setFetchSize(Math.min(rowsToReturn,
1216: DBUtils.MAX_FETCH_SIZE));
1217: } catch (SQLException sqle) {
1218: //do nothing, postgreSQL does not support this method
1219: }
1220: resultSet = statement.executeQuery();
1221: System.out.println("===sql mysql: " + sql);
1222: int rowIndex = -1;
1223: while (resultSet.next()) {
1224: rowIndex++;
1225: if (rowIndex < offset)
1226: continue;
1227: ForumBean bean = new ForumBean();
1228: bean.setForumID(resultSet.getInt("ForumID"));
1229: bean.setCategoryID(resultSet.getInt("CategoryID"));
1230: bean.setForumOwnerName(resultSet
1231: .getString("ForumOwnerName"));
1232: bean.setLastPostMemberName(resultSet
1233: .getString("LastPostMemberName"));
1234: bean.setForumName(resultSet.getString("ForumName"));
1235: bean.setForumDesc(resultSet.getString("ForumDesc"));
1236: bean.setForumCreationDate(resultSet
1237: .getTimestamp("ForumCreationDate"));
1238: bean.setForumModifiedDate(resultSet
1239: .getTimestamp("ForumModifiedDate"));
1240: bean.setForumLastPostDate(resultSet
1241: .getTimestamp("ForumLastPostDate"));
1242: bean.setForumOrder(resultSet.getInt("ForumOrder"));
1243: bean.setForumType(resultSet.getInt("ForumType"));
1244: bean.setForumFormatOption(resultSet
1245: .getInt("ForumFormatOption"));
1246: bean.setForumOption(resultSet.getInt("ForumOption"));
1247: bean.setForumStatus(resultSet.getInt("ForumStatus"));
1248: bean.setForumModerationMode(resultSet
1249: .getInt("ForumModerationMode"));
1250: bean.setForumPassword(resultSet
1251: .getString("ForumPassword"));
1252: bean.setForumThreadCount(resultSet
1253: .getInt("ForumThreadCount"));
1254: bean.setForumPostCount(resultSet
1255: .getInt("ForumPostCount"));
1256: retValue.add(bean);
1257: if (retValue.size() == rowsToReturn)
1258: break;// Fix the Sybase bug
1259: }
1260: return retValue;
1261: } catch (SQLException sqle) {
1262: log.error("Sql Execution Error!", sqle);
1263: throw new DatabaseException(
1264: "Error executing SQL in ForumDAOImplJDBC.getBeans_withSortSupport_limit_general.");
1265: } finally {
1266: DBUtils.closeResultSet(resultSet);
1267: DBUtils.resetStatement(statement);
1268: DBUtils.closeStatement(statement);
1269: DBUtils.closeConnection(connection);
1270: }
1271: }
1272:
1273: /*
1274: *
1275: */
1276: public Collection getBeans_withSortSupport_limit_noscroll(
1277: int offset, int rowsToReturn, String sort, String order)
1278: throws IllegalArgumentException, DatabaseException {
1279: if (offset < 0)
1280: throw new IllegalArgumentException(
1281: "The offset < 0 is not allowed.");
1282: if (rowsToReturn <= 0)
1283: throw new IllegalArgumentException(
1284: "The rowsToReturn <= 0 is not allowed.");
1285:
1286: if ((!sort.equals("ForumLastPostDate"))
1287: && (!sort.equals("ForumCreationDate"))
1288: && (!sort.equals("ForumName"))
1289: && (!sort.equals("ForumPostCount"))
1290: && (!sort.equals("ForumThreadCount"))) {
1291: throw new IllegalArgumentException(
1292: "Cannot sort, reason: dont understand the criteria '"
1293: + sort + "'.");
1294: }
1295:
1296: if ((!order.equals("ASC")) && (!order.equals("DESC"))) {
1297: throw new IllegalArgumentException(
1298: "Cannot sort, reason: dont understand the order '"
1299: + order + "'.");
1300: }
1301:
1302: Connection connection = null;
1303: PreparedStatement statement = null;
1304: ResultSet resultSet = null;
1305: Collection retValue = new ArrayList();
1306: StringBuffer sql = new StringBuffer(512);
1307:
1308: sql
1309: .append("SELECT ForumID, CategoryID, ForumOwnerName, LastPostMemberName, ForumName, ForumDesc, ForumCreationDate, ForumModifiedDate, ForumLastPostDate, ForumOrder, ForumType, ForumFormatOption, ForumOption, ForumStatus, ForumModerationMode, ForumPassword, ForumThreadCount, ForumPostCount");
1310: sql.append(" FROM " + TABLE_NAME);
1311: sql.append(" ORDER BY " + sort + " " + order);// ColumnName, ASC|DESC
1312:
1313: try {
1314: connection = DBUtils.getConnection();
1315: statement = connection.prepareStatement(sql.toString(),
1316: ResultSet.TYPE_SCROLL_INSENSITIVE,
1317: ResultSet.CONCUR_READ_ONLY);
1318:
1319: statement.setMaxRows(offset + rowsToReturn);
1320: try {
1321: statement.setFetchSize(Math.min(rowsToReturn,
1322: DBUtils.MAX_FETCH_SIZE));
1323: } catch (SQLException sqle) {
1324: //do nothing, postgreSQL does not support this method
1325: }
1326: System.out.println("===sql noscroll: " + sql);
1327: resultSet = statement.executeQuery();
1328: int rowIndex = -1;
1329: while (resultSet.next()) {
1330: rowIndex++;
1331: if (rowIndex < offset)
1332: continue;
1333: ForumBean bean = new ForumBean();
1334: bean.setForumID(resultSet.getInt("ForumID"));
1335: bean.setCategoryID(resultSet.getInt("CategoryID"));
1336: bean.setForumOwnerName(resultSet
1337: .getString("ForumOwnerName"));
1338: bean.setLastPostMemberName(resultSet
1339: .getString("LastPostMemberName"));
1340: bean.setForumName(resultSet.getString("ForumName"));
1341: bean.setForumDesc(resultSet.getString("ForumDesc"));
1342: bean.setForumCreationDate(resultSet
1343: .getTimestamp("ForumCreationDate"));
1344: bean.setForumModifiedDate(resultSet
1345: .getTimestamp("ForumModifiedDate"));
1346: bean.setForumLastPostDate(resultSet
1347: .getTimestamp("ForumLastPostDate"));
1348: bean.setForumOrder(resultSet.getInt("ForumOrder"));
1349: bean.setForumType(resultSet.getInt("ForumType"));
1350: bean.setForumFormatOption(resultSet
1351: .getInt("ForumFormatOption"));
1352: bean.setForumOption(resultSet.getInt("ForumOption"));
1353: bean.setForumStatus(resultSet.getInt("ForumStatus"));
1354: bean.setForumModerationMode(resultSet
1355: .getInt("ForumModerationMode"));
1356: bean.setForumPassword(resultSet
1357: .getString("ForumPassword"));
1358: bean.setForumThreadCount(resultSet
1359: .getInt("ForumThreadCount"));
1360: bean.setForumPostCount(resultSet
1361: .getInt("ForumPostCount"));
1362: retValue.add(bean);
1363: if (retValue.size() == rowsToReturn)
1364: break;// Fix the Sybase bug
1365: }
1366: return retValue;
1367: } catch (SQLException sqle) {
1368: log.error("Sql Execution Error!", sqle);
1369: throw new DatabaseException(
1370: "Error executing SQL in ForumDAOImplJDBC.getBeans_withSortSupport_limit_general.");
1371: } finally {
1372: DBUtils.closeResultSet(resultSet);
1373: DBUtils.resetStatement(statement);
1374: DBUtils.closeStatement(statement);
1375: DBUtils.closeConnection(connection);
1376: }
1377: }
1378:
1379: /*
1380: *
1381: */
1382: public Collection getForums_withSortSupport_limit(int offset,
1383: int rowsToReturn, String sort, String order)
1384: throws IllegalArgumentException, DatabaseException {
1385: if (DBUtils.getDatabaseType() == DBUtils.DATABASE_MYSQL) {
1386: return getBeans_withSortSupport_limit_mysql(offset,
1387: rowsToReturn, sort, order);
1388: } else if (DBUtils.getDatabaseType() == DBUtils.DATABASE_NOSCROLL) {
1389: return getBeans_withSortSupport_limit_noscroll(offset,
1390: rowsToReturn, sort, order);
1391: }
1392: return getBeans_withSortSupport_limit_general(offset,
1393: rowsToReturn, sort, order);
1394: }
1395:
1396: /*
1397: *
1398: */
1399: public Collection getForums_withSortSupport_limit_ViewCount(
1400: int offset, int rowsToReturn, String sort, String order)
1401: throws IllegalArgumentException, DatabaseException {
1402: if (DBUtils.getDatabaseType() == DBUtils.DATABASE_MYSQL) {
1403: return getBeans_withSortSupport_limit_ViewCount_mysql(
1404: offset, rowsToReturn, sort, order);
1405: } else if (DBUtils.getDatabaseType() == DBUtils.DATABASE_ORACLE) {
1406: return getBeans_withSortSupport_limit_ViewCount_oracle(
1407: offset, rowsToReturn, sort, order);
1408: }
1409: throw new DatabaseException(
1410: "No suport Database for getForums_withSortSupport_limit_ViewCount method !");
1411: }
1412:
1413: public Collection getBeans_withSortSupport_limit_ViewCount_mysql(
1414: int offset, int rowsToReturn, String sort, String order)
1415: throws IllegalArgumentException, DatabaseException {
1416:
1417: if (offset < 0)
1418: throw new IllegalArgumentException(
1419: "The offset < 0 is not allowed.");
1420: if (rowsToReturn <= 0)
1421: throw new IllegalArgumentException(
1422: "The rowsToReturn <= 0 is not allowed.");
1423:
1424: if ((!sort.equals("ForumLastPostDate"))
1425: && (!sort.equals("ForumCreationDate"))
1426: && (!sort.equals("ForumName"))
1427: && (!sort.equals("ForumPostCount"))
1428: && (!sort.equals("ViewCount"))
1429: && (!sort.equals("ForumThreadCount"))) {
1430: throw new IllegalArgumentException(
1431: "Cannot sort, reason: dont understand the criteria '"
1432: + sort + "'.");
1433: }
1434:
1435: if ((!order.equals("ASC")) && (!order.equals("DESC"))) {
1436: throw new IllegalArgumentException(
1437: "Cannot sort, reason: dont understand the order '"
1438: + order + "'.");
1439: }
1440:
1441: Connection connection = null;
1442: PreparedStatement statement = null;
1443: ResultSet resultSet = null;
1444: Collection retValue = new ArrayList();
1445: StringBuffer sql = new StringBuffer(512);
1446:
1447: sql
1448: .append("SELECT DISTINCT mvnforumForum.ForumID, CategoryID, ForumOwnerName,mvnforumForum.LastPostMemberName, "
1449: + "ForumName, ForumDesc,ForumCreationDate, ForumModifiedDate, ForumLastPostDate, ForumOrder, ForumType, "
1450: + "ForumFormatOption, ForumOption, ForumStatus, ForumModerationMode, ForumPassword, ForumThreadCount, "
1451: + "ForumPostCount,SUM(mvnforumThread.ThreadViewCount) AS ViewCount "
1452: + "FROM mvnforumForum LEFT OUTER JOIN mvnforumThread ON mvnforumForum.ForumID=mvnforumThread.ForumID "
1453: + "GROUP BY mvnforumForum.ForumID");
1454: sql.append(" ORDER BY " + sort + " " + order);// ColumnName, ASC|DESC
1455: try {
1456: connection = DBUtils.getConnection();
1457: statement = connection.prepareStatement(sql.toString(),
1458: ResultSet.TYPE_SCROLL_INSENSITIVE,
1459: ResultSet.CONCUR_READ_ONLY);
1460:
1461: statement.setMaxRows(offset + rowsToReturn);
1462: try {
1463: statement.setFetchSize(Math.min(rowsToReturn,
1464: DBUtils.MAX_FETCH_SIZE));
1465: } catch (SQLException sqle) {
1466: //do nothing, postgreSQL does not support this method
1467: }
1468: System.out.println("===sql general viewcount: " + sql);
1469: resultSet = statement.executeQuery();
1470: boolean loop = resultSet.absolute(offset + 1);// the absolute method begin with 1 instead of 0 as in the LIMIT clause
1471: while (loop) {
1472: ForumBean bean = new ForumBean();
1473: bean.setForumID(resultSet.getInt("ForumID"));
1474: bean.setCategoryID(resultSet.getInt("CategoryID"));
1475: bean.setForumOwnerName(resultSet
1476: .getString("ForumOwnerName"));
1477: bean.setLastPostMemberName(resultSet
1478: .getString("LastPostMemberName"));
1479: bean.setForumName(resultSet.getString("ForumName"));
1480: bean.setForumDesc(resultSet.getString("ForumDesc"));
1481: bean.setForumCreationDate(resultSet
1482: .getTimestamp("ForumCreationDate"));
1483: bean.setForumModifiedDate(resultSet
1484: .getTimestamp("ForumModifiedDate"));
1485: bean.setForumLastPostDate(resultSet
1486: .getTimestamp("ForumLastPostDate"));
1487: bean.setForumOrder(resultSet.getInt("ForumOrder"));
1488: bean.setForumType(resultSet.getInt("ForumType"));
1489: bean.setForumFormatOption(resultSet
1490: .getInt("ForumFormatOption"));
1491: bean.setForumOption(resultSet.getInt("ForumOption"));
1492: bean.setForumStatus(resultSet.getInt("ForumStatus"));
1493: bean.setForumModerationMode(resultSet
1494: .getInt("ForumModerationMode"));
1495: bean.setForumPassword(resultSet
1496: .getString("ForumPassword"));
1497: bean.setForumThreadCount(resultSet
1498: .getInt("ForumThreadCount"));
1499: bean.setForumPostCount(resultSet
1500: .getInt("ForumPostCount"));
1501: bean.setViewCount(resultSet.getInt("ViewCount"));
1502: retValue.add(bean);
1503: if (retValue.size() == rowsToReturn)
1504: break;// Fix the Sybase bug
1505: loop = resultSet.next();
1506: }//while
1507: return retValue;
1508: } catch (SQLException sqle) {
1509: log.error("Sql Execution Error!", sqle);
1510: throw new DatabaseException(
1511: "Error executing SQL in ForumDAOImplJDBC.getBeans_withSortSupport_limit_general.");
1512: } finally {
1513: DBUtils.closeResultSet(resultSet);
1514: DBUtils.resetStatement(statement);
1515: DBUtils.closeStatement(statement);
1516: DBUtils.closeConnection(connection);
1517: }
1518: }
1519:
1520: public Collection getBeans_withSortSupport_limit_ViewCount_oracle(
1521: int offset, int rowsToReturn, String sort, String order)
1522: throws IllegalArgumentException, DatabaseException {
1523:
1524: if (offset < 0)
1525: throw new IllegalArgumentException(
1526: "The offset < 0 is not allowed.");
1527: if (rowsToReturn <= 0)
1528: throw new IllegalArgumentException(
1529: "The rowsToReturn <= 0 is not allowed.");
1530:
1531: if ((!sort.equals("ForumLastPostDate"))
1532: && (!sort.equals("ForumCreationDate"))
1533: && (!sort.equals("ForumName"))
1534: && (!sort.equals("ForumPostCount"))
1535: && (!sort.equals("ViewCount"))
1536: && (!sort.equals("ForumThreadCount"))) {
1537: throw new IllegalArgumentException(
1538: "Cannot sort, reason: dont understand the criteria '"
1539: + sort + "'.");
1540: }
1541:
1542: if ((!order.equals("ASC")) && (!order.equals("DESC"))) {
1543: throw new IllegalArgumentException(
1544: "Cannot sort, reason: dont understand the order '"
1545: + order + "'.");
1546: }
1547:
1548: Connection connection = null;
1549: PreparedStatement statement = null;
1550: ResultSet resultSet = null;
1551: Collection retValue = new ArrayList();
1552: StringBuffer sql = new StringBuffer(512);
1553:
1554: sql
1555: .append("SELECT mvnforumForum.ForumID, CategoryID, ForumOwnerName, mvnforumForum.LastPostMemberName, "
1556: + "ForumName, ForumDesc, ForumCreationDate, ForumModifiedDate, ForumLastPostDate, ForumOrder, ForumType, "
1557: + "ForumFormatOption, ForumOption, ForumStatus, ForumModerationMode, ForumPassword, ForumThreadCount, "
1558: + "ForumPostCount, ViewCount FROM (SELECT mvnforumForum.ForumID AS id, SUM(mvnforumThread.ThreadViewCount) AS ViewCount "
1559: + "From mvnforumForum, mvnforumThread WHERE mvnforumForum.ForumID = mvnforumThread.ForumID (+) "
1560: + "Group BY mvnforumForum.ForumID), mvnforumForum Where mvnforumForum.ForumID = id");
1561: sql.append(" ORDER BY " + sort + " " + order);// ColumnName, ASC|DESC
1562: try {
1563: connection = DBUtils.getConnection();
1564: statement = connection.prepareStatement(sql.toString(),
1565: ResultSet.TYPE_SCROLL_INSENSITIVE,
1566: ResultSet.CONCUR_READ_ONLY);
1567:
1568: statement.setMaxRows(offset + rowsToReturn);
1569: try {
1570: statement.setFetchSize(Math.min(rowsToReturn,
1571: DBUtils.MAX_FETCH_SIZE));
1572: } catch (SQLException sqle) {
1573: //do nothing, postgreSQL does not support this method
1574: }
1575: System.out.println("===sql general viewcount: " + sql);
1576: resultSet = statement.executeQuery();
1577: boolean loop = resultSet.absolute(offset + 1);// the absolute method begin with 1 instead of 0 as in the LIMIT clause
1578: while (loop) {
1579: ForumBean bean = new ForumBean();
1580: bean.setForumID(resultSet.getInt("ForumID"));
1581: bean.setCategoryID(resultSet.getInt("CategoryID"));
1582: bean.setForumOwnerName(resultSet
1583: .getString("ForumOwnerName"));
1584: bean.setLastPostMemberName(resultSet
1585: .getString("LastPostMemberName"));
1586: bean.setForumName(resultSet.getString("ForumName"));
1587: bean.setForumDesc(resultSet.getString("ForumDesc"));
1588: bean.setForumCreationDate(resultSet
1589: .getTimestamp("ForumCreationDate"));
1590: bean.setForumModifiedDate(resultSet
1591: .getTimestamp("ForumModifiedDate"));
1592: bean.setForumLastPostDate(resultSet
1593: .getTimestamp("ForumLastPostDate"));
1594: bean.setForumOrder(resultSet.getInt("ForumOrder"));
1595: bean.setForumType(resultSet.getInt("ForumType"));
1596: bean.setForumFormatOption(resultSet
1597: .getInt("ForumFormatOption"));
1598: bean.setForumOption(resultSet.getInt("ForumOption"));
1599: bean.setForumStatus(resultSet.getInt("ForumStatus"));
1600: bean.setForumModerationMode(resultSet
1601: .getInt("ForumModerationMode"));
1602: bean.setForumPassword(resultSet
1603: .getString("ForumPassword"));
1604: bean.setForumThreadCount(resultSet
1605: .getInt("ForumThreadCount"));
1606: bean.setForumPostCount(resultSet
1607: .getInt("ForumPostCount"));
1608: bean.setViewCount(resultSet.getInt("ViewCount"));
1609: retValue.add(bean);
1610: if (retValue.size() == rowsToReturn)
1611: break;// Fix the Sybase bug
1612: loop = resultSet.next();
1613: }//while
1614: return retValue;
1615: } catch (SQLException sqle) {
1616: log.error("Sql Execution Error!", sqle);
1617: throw new DatabaseException(
1618: "Error executing SQL in ForumDAOImplJDBC.getBeans_withSortSupport_limit_general.");
1619: } finally {
1620: DBUtils.closeResultSet(resultSet);
1621: DBUtils.resetStatement(statement);
1622: DBUtils.closeStatement(statement);
1623: DBUtils.closeConnection(connection);
1624: }
1625: }
1626:
1627: } // end of class ForumDAOImplJDBC
|