/**
  * Description of the Method
  *
  * @param db Description of the Parameter
  * @throws SQLException Description of the Exception
  */
 public void buildFileList(Connection db) throws SQLException {
   fileItemList.setLinkModuleId(Constants.DOCUMENTS_CUSTOMER_PRODUCT);
   fileItemList.setLinkItemId(this.getId());
   fileItemList.buildList(db);
   // TODO: determine the actual place for this code
   Iterator i = fileItemList.iterator();
   while (i.hasNext()) {
     FileItem thisItem = (FileItem) i.next();
     thisItem.buildVersionList(db);
   }
 }
  /**
   * Description of the Method
   *
   * @param db Description of the Parameter
   * @return Description of the Return Value
   * @throws SQLException Description of the Exception
   */
  public boolean delete(Connection db, int itemId, String filePath) throws SQLException {
    if (this.getId() == -1) {
      throw new SQLException("Customer Product ID not specified");
    }
    boolean commit = true;
    boolean recordDeleted = false;
    try {
      commit = db.getAutoCommit();
      if (commit) {
        db.setAutoCommit(false);
      }

      // Delete all the files that are associated with this customer product
      FileItem thisItem =
          new FileItem(db, itemId, this.getId(), Constants.DOCUMENTS_CUSTOMER_PRODUCT);
      thisItem.delete(db, filePath);
      // System.out.println("CustomerProduct -> Deleted Files : " + thisItem.getId());

      // Delete all the quotes that were placed for this customer product
      PreparedStatement pst =
          db.prepareStatement(
              "SELECT quote_id FROM order_entry "
                  + "WHERE quote_id > -1 AND order_id IN "
                  + "(SELECT DISTINCT(order_id) "
                  + " FROM customer_product_history "
                  + " WHERE customer_product_id = ? "
                  + " AND order_id NOT IN ( SELECT order_id FROM customer_product WHERE "
                  + "                      customer_product_id = ? )) ");
      pst.setInt(1, this.getId());
      pst.setInt(2, this.getId());
      ResultSet rs = pst.executeQuery();
      while (rs.next()) {
        Quote thisQuote = new Quote(db, rs.getInt("quote_id"));
        // System.out.println("CustomerProduct -> calling delete on a quote : " +
        // thisQuote.getId());
        thisQuote.delete(db);
      }
      rs.close();
      pst.close();

      // Delete all the orders that were placed using this customer product
      pst =
          db.prepareStatement(
              "SELECT DISTINCT(order_id) "
                  + "FROM customer_product_history "
                  + "WHERE customer_product_id = ? "
                  + "AND order_id NOT IN ( SELECT order_id FROM customer_product WHERE "
                  + "                      customer_product_id = ? ) ");
      int i = 1;
      pst.setInt(1, this.getId());
      pst.setInt(2, this.getId());
      rs = pst.executeQuery();
      while (rs.next()) {
        Order thisOrder = new Order(db, rs.getInt("order_id"));
        // System.out.println("CustomerProduct -> calling delete on an order : " +
        // thisOrder.getId());
        thisOrder.delete(db);
      }
      rs.close();
      pst.close();

      // Delete all the order payments associated with the master order
      pst =
          db.prepareStatement(
              "SELECT payment_id, order_item_id FROM order_payment WHERE order_item_id IN "
                  + " (SELECT order_item_id FROM customer_product_history cph "
                  + "  WHERE customer_product_id = ? ) ");
      pst.setInt(1, this.getId());
      rs = pst.executeQuery();
      while (rs.next()) {
        OrderPayment thisPayment = new OrderPayment(db, rs.getInt("payment_id"));
        // System.out.println("CustomerProduct -> calling delete on a payment : " +
        // thisPayment.getId());
        thisPayment.delete(db);
      }
      rs.close();
      pst.close();

      // Delete the customer product history

      this.buildHistoryList(db);
      int size = this.getHistoryList().size();
      historyList.delete(db);
      // System.out.println("CustomerProduct -> Deleted history tems.....");

      // Delete this customer product
      pst = db.prepareStatement(" DELETE FROM customer_product WHERE customer_product_id = ? ");
      pst.setInt(1, this.getId());
      pst.execute();
      pst.close();
      // System.out.println("CustomerProduct -> Deleted Customer Product : " + this.getId());

      // Delete the master order product mapped with this customer product
      OrderProduct thisProduct = new OrderProduct(db, this.getOrderItemId());
      thisProduct.delete(db);
      // System.out.println("CustomerProduct -> Deleted the order product : " +
      // thisProduct.getId());

      // Delete the master order mapped with this customer product
      Order thisOrder = new Order(db, this.getOrderId());
      recordDeleted = thisOrder.delete(db);
      // System.out.println("CustomerProduct -> Deleted the order : " + thisOrder.getId());

      if (commit) {
        db.commit();
      }
    } catch (SQLException e) {
      if (commit) {
        db.rollback();
      }
      throw new SQLException(e.getMessage());
    } finally {
      if (commit) {
        db.setAutoCommit(true);
      }
    }
    return recordDeleted;
  }