Package com.jdbc.database
Class DB2024TEAM07_RestaurantDAO
java.lang.Object
com.jdbc.database.DB2024TEAM07_RestaurantDAO
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 Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionConstructor that establishes a connection to the database using the DB2024TEAM07_Database class. -
Method Summary
Modifier and TypeMethodDescriptionintadd(DB2024TEAM07_Restaurant restaurant) Adds a new restaurant to the database (Admin functionality).intdelete(int res_id) Deletes a restaurant from the database based on the provided restaurant ID.Retrieves all restaurants from the database and returns a list containing basic information for each restaurant.static DB2024TEAM07_RestaurantRetrieves a random restaurant from the database.Searches for restaurants based on a combination of criteria (Admin functionality).searchRestaurantByCategory(String cuisine_type) Retrieves a list of restaurants based on the specified cuisine type.intupdate(DB2024TEAM07_Restaurant restaurant, int pRes_id) Updates the information of an existing restaurant in the database (Admin functionality).
-
Field Details
-
conn
-
pStmt
-
-
Constructor Details
-
DB2024TEAM07_RestaurantDAO
public DB2024TEAM07_RestaurantDAO()Constructor that establishes a connection to the database using the DB2024TEAM07_Database class.
-
-
Method Details
-
add
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_Restaurantthat satisfy the given criteria.
-
searchRestaurantByCategory
Retrieves a list of restaurants based on the specified cuisine type.- Parameters:
cuisine_type- The type of cuisine to search for.- Returns:
- A
ResultSetcontaining restaurant information.
-
update
Updates the information of an existing restaurant in the database (Admin functionality).- Parameters:
restaurant- TheDB2024TEAM07_Restaurantobject 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
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
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.
-