gt:       Forum thisCategory = (Forum) i.next();
context: /*
   * ConcourseConnect
   * Copyright 2009 Concursive Corporation
   * http://www.concursive.com
   *
   * This file is part of ConcourseConnect, an open source social business
   * software and community platform.
   *
   * Concursive ConcourseConnect is free software: you can redistribute it and/or
   * modify it under the terms of the GNU Affero General Public License as published
   * by the Free Software Foundation, version 3 of the License.
   *
   * Under the terms of the GNU Affero General Public License you must release the
   * complete source code for any application that uses any part of ConcourseConnect
   * (system header files and libraries used by the operating system are excluded).
   * These terms must be included in any work that has ConcourseConnect components.
   * If you are developing and distributing open source applications under the
   * GNU Affero General Public License, then you are free to use ConcourseConnect
   * under the GNU Affero General Public License.
   *
   * If you are deploying a web site in which users interact with any portion of
   * ConcourseConnect over a network, the complete source code changes must be made
   * available.  For example, include a link to the source archive directly from
   * your web site.
   *
   * For OEMs, ISVs, SIs and VARs who distribute ConcourseConnect with their
   * products, and do not license and distribute their source code under the GNU
   * Affero General Public License, Concursive provides a flexible commercial
   * license.
   *
   * To anyone in doubt, we recommend the commercial license. Our commercial license
   * is competitively priced and will eliminate any confusion about how
   * ConcourseConnect can be used and distributed.
   *
   * ConcourseConnect is distributed in the hope that it will be useful, but WITHOUT
   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
   * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
   * details.
   *
   * You should have received a copy of the GNU Affero General Public License
   * along with ConcourseConnect.  If not, see <http://www.gnu.org/licenses/>.
   *
   * Attribution Notice: ConcourseConnect is an Original Work of software created
   * by Concursive Corporation
   */
  
  package com.concursive.connect.web.modules.discussion.dao;
  
  import com.concursive.commons.db.DatabaseUtils;
  import com.concursive.connect.Constants;
  import com.concursive.connect.web.utils.PagedListInfo;
  
  import java.sql.*;
  import java.util.ArrayList;
  import java.util.Iterator;
  
  /**
   * A collection of discussion forum objects
   *
   * @author matt rajkowski
   * @created January 15, 2003
   */
  public class ForumList extends ArrayList<Forum> {
  
    private PagedListInfo pagedListInfo = null;
    private int projectId = -1;
    private int enabled = -1;
    private int enteredBy = -1;
    private int modifiedBy = -1;
  
    /**
     * Constructor for the IssueCategoryList object
     */
    public ForumList() {
    }
  
  
    /**
     * Sets the pagedListInfo attribute of the IssueCategoryList object
     *
     * @param tmp The new pagedListInfo value
     */
    public void setPagedListInfo(PagedListInfo tmp) {
      this.pagedListInfo = tmp;
    }
  
  
    /**
     * Sets the projectId attribute of the IssueCategoryList object
     *
     * @param tmp The new projectId value
     */
    public void setProjectId(int tmp) {
      this.projectId = tmp;
    }
  
  
    public void setProjectId(String tmp) {
      this.projectId = Integer.parseInt(tmp);
    }
  
  
    /**
     * Sets the enabled attribute of the IssueCategoryList object
     *
     * @param tmp The new enabled value
     */
    public void setEnabled(int tmp) {
      this.enabled = tmp;
    }
  
  
    /**
     * Sets the enabled attribute of the IssueCategoryList object
     *
     * @param tmp The new enabled value
     */
    public void setEnabled(String tmp) {
      this.enabled = Integer.parseInt(tmp);
    }
  
    public int getEnteredBy() {
      return enteredBy;
    }
  
    public void setEnteredBy(int enteredBy) {
      this.enteredBy = enteredBy;
    }
  
    public void setEnteredBy(String enteredBy) {
      this.enteredBy = Integer.parseInt(enteredBy);
    }
  
    public int getModifiedBy() {
      return modifiedBy;
    }
  
    public void setModifiedBy(int modifiedBy) {
      this.modifiedBy = modifiedBy;
    }
  
    public void setModifiedBy(String modifiedBy) {
      this.modifiedBy = Integer.parseInt(modifiedBy);
    }
  
    /**
     * Description of the Method
     *
     * @param db Description of the Parameter
     * @throws SQLException Description of the Exception
     */
    public void buildList(Connection db) throws SQLException {
      PreparedStatement pst = null;
      ResultSet rs = null;
      int items = -1;
      StringBuffer sqlSelect = new StringBuffer();
      StringBuffer sqlCount = new StringBuffer();
      StringBuffer sqlFilter = new StringBuffer();
      StringBuffer sqlOrder = new StringBuffer();
      //Need to build a base SQL statement for counting records
      sqlCount.append(
          "SELECT COUNT(*) as recordcount " +
              "FROM project_issues_categories c " +
              "WHERE c.category_id > 0 ");
      createFilter(sqlFilter, db);
      if (pagedListInfo != null) {
        //Get the total number of records matching filter
        pst = db.prepareStatement(
            sqlCount.toString() +
                sqlFilter.toString());
        items = prepareFilter(pst);
        rs = pst.executeQuery();
        if (rs.next()) {
          int maxRecords = rs.getInt("recordcount");
          pagedListInfo.setMaxRecords(maxRecords);
        }
        rs.close();
        pst.close();
        //Determine column to sort by
        pagedListInfo.setDefaultSort("c.subject", null);
        pagedListInfo.appendSqlTail(db, sqlOrder);
      } else {
        sqlOrder.append("ORDER BY c.subject ");
      }
      //Need to build a base SQL statement for returning records
      if (pagedListInfo != null) {
        pagedListInfo.appendSqlSelectHead(db, sqlSelect);
      } else {
        sqlSelect.append("SELECT ");
      }
      sqlSelect.append(
          "* " +
              "FROM project_issues_categories c " +
              "WHERE c.category_id > 0 ");
      pst = db.prepareStatement(sqlSelect.toString() + sqlFilter.toString() + sqlOrder.toString());
      items = prepareFilter(pst);
      rs = pst.executeQuery();
      if (pagedListInfo != null) {
        pagedListInfo.doManualOffset(db, rs);
      }
      int count = 0;
      while (rs.next()) {
        if (pagedListInfo != null && pagedListInfo.getItemsPerPage() > 0 &&
            DatabaseUtils.getType(db) == DatabaseUtils.MSSQL &&
            count >= pagedListInfo.getItemsPerPage()) {
          break;
        }
        ++count;
        Forum thisCategory = new Forum(rs);
        thisCategory.setProjectId(projectId);
        this.add(thisCategory);
      }
      rs.close();
      pst.close();
    }
  
  
    /**
     * Description of the Method
     *
     * @param db Description of the Parameter
     * @throws SQLException Description of the Exception
     */
    public void delete(Connection db, String basePath) throws SQLException {
      Iterator i = this.iterator();
      while (i.hasNext()) {
        Forum forum = (Forum) i.next();
        forum.delete(db, basePath);
      }
    }
  
  
    /**
     * Description of the Method
     *
     * @param sqlFilter Description of the Parameter
     * @param db        Description of the Parameter
     */
    private void createFilter(StringBuffer sqlFilter, Connection db) {
      if (projectId > -1) {
        sqlFilter.append("AND project_id = ? ");
      }
      if (enabled != Constants.UNDEFINED) {
        sqlFilter.append("AND c.enabled = ? ");
      }
    }
  
  
    /**
     * Description of the Method
     *
     * @param pst Description of the Parameter
     * @return Description of the Return Value
     * @throws SQLException Description of the Exception
     */
    private int prepareFilter(PreparedStatement pst) throws SQLException {
      int i = 0;
      if (projectId > -1) {
        pst.setInt(++i, projectId);
      }
      if (enabled != Constants.UNDEFINED) {
        pst.setBoolean(++i, enabled == Constants.TRUE);
      }
      return i;
    }
  
    public void insert(Connection db) throws SQLException {
      Iterator i = this.iterator();
      while (i.hasNext()) {
  