Class DB2024TEAM07_RestaurantDAO

java.lang.Object
com.jdbc.database.DB2024TEAM07_RestaurantDAO

public class DB2024TEAM07_RestaurantDAO extends Object
This class provides data access object (DAO) methods for interacting with the DB2024_Restaurant table in a database. It manages various functionalities related to restaurant registration, retrieval, update, and deletion.
  • Field Details

  • Constructor Details

    • DB2024TEAM07_RestaurantDAO

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

    • add

      public int add(DB2024TEAM07_Restaurant restaurant)
      Adds a new restaurant to the database (Admin functionality).
      Parameters:
      restaurant - the restaurant object containing details like name, ID, phone number, address, etc.
      Returns:
      1 on successful insertion, 0 if failed
    • search

      public List<DB2024TEAM07_Restaurant> search(String res_name, String cuisine_type, String location, Float rating)
      Searches for restaurants based on a combination of criteria (Admin functionality).
      Parameters:
      res_name - Name of the restaurant (optional)
      cuisine_type - Type of cuisine (optional)
      location - Location of the restaurant (optional)
      rating - Minimum rating (optional)
      Returns:
      A list of DB2024TEAM07_Restaurant that satisfy the given criteria.
    • searchRestaurantByCategory

      public ResultSet searchRestaurantByCategory(String cuisine_type)
      Retrieves a list of restaurants based on the specified cuisine type.
      Parameters:
      cuisine_type - The type of cuisine to search for.
      Returns:
      A ResultSet containing restaurant information.
    • update

      public int update(DB2024TEAM07_Restaurant restaurant, int pRes_id)
      Updates the information of an existing restaurant in the database (Admin functionality).
      Parameters:
      restaurant - The DB2024TEAM07_Restaurant object containing the updated information.
      pRes_id - The ID of the restaurant to be updated.
      Returns:
      The number of rows affected by the update statement.
    • delete

      public int delete(int res_id)
      Deletes a restaurant from the database based on the provided restaurant ID. This method is intended for administrators to remove restaurants.
      Parameters:
      res_id - The ID of the restaurant to be deleted.
      Returns:
      The number of rows affected by the DELETE operation. This should be 1 if the deletion was successful. Returns 0 if no rows were affected (i.e., the restaurant with the provided ID was not found).
    • getRandomRestaurant

      public static DB2024TEAM07_Restaurant getRandomRestaurant()
      Retrieves a random restaurant from the database.
      Returns:
      A DB2024TEAM07_Restaurant object representing the retrieved random restaurant, or null if no restaurants are found.
    • getAllRestaurants

      public List<DB2024TEAM07_Restaurant> getAllRestaurants()
      Retrieves all restaurants from the database and returns a list containing basic information for each restaurant. This method includes only the restaurant ID and name.
      Returns:
      A List of DB2024TEAM07_Restaurant objects containing only ID and name for each restaurant.