Class DB2024TEAM07_MenuDAO

java.lang.Object
com.jdbc.database.DB2024TEAM07_MenuDAO

public class DB2024TEAM07_MenuDAO extends Object
This class provides data access object (DAO) methods for interacting with the DB2024_Menu table in a database. It handles CRUD (Create, Read, Update, Delete) operations on menu data.
  • Field Details

  • Constructor Details

    • DB2024TEAM07_MenuDAO

      public DB2024TEAM07_MenuDAO()
      Constructor that establishes a connection to the database using the DB2024TEAM07_Database class.
  • Method Details

    • add

      public int add(DB2024TEAM07_Menu menu)
      Adds a new menu item to the database.
      Parameters:
      menu - the DB2024TEAM07_Menu object representing the menu item to add
      Returns:
      the number of rows affected (usually 1 for a successful insert)
    • searchByUsers

      public ResultSet searchByUsers(String res_name, String menu_name, Integer minPrice, Integer maxPrice)
      Searches for menus based on criteria specified by the user. This method uses a view (DB2024_MenuView) to efficiently join the DB2024_Menu and DB2024_Restaurant tables and retrieve user-relevant information (restaurant name, menu name, price) based on various filters.
      Parameters:
      res_name - the name of the restaurant (optional, can be filtered by a partial match using LIKE)
      menu_name - the name of the menu item (optional, can be filtered by a partial match using LIKE)
      minPrice - the minimum price (optional)
      maxPrice - the maximum price (optional)
      Returns:
      a ResultSet containing the search results
    • searchMenuByRestaurant

      public ResultSet searchMenuByRestaurant(int res_id)
      Retrieves all menus for a specific restaurant identified by its ID. This method utilizes an index (DB2024_idx_Menu) on the res_id column for efficient retrieval.
      Parameters:
      res_id - the ID of the restaurant
      Returns:
      a ResultSet containing all menus for the specified restaurant
    • searchByManager

      public ResultSet searchByManager(int res_id)
      Searches for menus managed by a restaurant with the specified ID. This method is intended for use by restaurant managers to view their restaurant's menus.
      Parameters:
      res_id - the ID of the restaurant
      Returns:
      a ResultSet containing all menus for the specified restaurant
    • update

      public int update(DB2024TEAM07_Menu menu, int pRes_id, int pMenu_id)
      Updates an existing menu item in the database.
      Parameters:
      menu - the DB2024TEAM07_Menu object containing the updated information for the menu item
      pRes_id - the original restaurant ID of the menu item (for identification)
      pMenu_id - the original menu ID of the menu item (for identification)
      Returns:
      the number of rows affected (usually 1 for a successful update)
    • delete

      public int delete(int res_id, int menu_id)
      Deletes a menu item from the database.
      Parameters:
      res_id - the ID of the restaurant the menu item belongs to
      menu_id - the ID of the menu item to delete
      Returns:
      the number of rows affected (usually 1 for a successful delete)
    • getAllMenuByRestaurant

      public ResultSet getAllMenuByRestaurant(int res_id)
      Retrieves all menu names and corresponding IDs for a specific restaurant.
      Parameters:
      res_id - the ID of the restaurant
      Returns:
      a ResultSet containing menu names and IDs