Package no.ntnu.idatt1002.demo.dao
Class DAO
java.lang.Object
no.ntnu.idatt1002.demo.dao.DAO
This class provides methods for accessing all tables in the database.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addToDatabase
(Storable obj) This method adds a storable object to the database.void
This method deletes a stoable object from the database.filterFromTable
(String table, String filterColumn, String filter, String joinTable, String joinColumn) This method filters objects by a given column in the database.getAllFromTable
(String table, String joinTable, String joinColumn) Returns all attributes from a table.getColumnsFromTable
(String table) Returns all columns from a table.searchFromTable
(String table, String name, String joinTable, String joinColumn) This method searches for objects by name in the database.void
updateDatabase
(Storable obj) This method updates a storable object in the database.
-
Field Details
-
connectionProvider
-
-
Constructor Details
-
DAO
Constructor for the DAO class.Sets the Database Connection Provider.
- Parameters:
connectionProvider
- theDBConnectionProvider
provider
-
-
Method Details
-
addToDatabase
This method adds a storable object to the database.- Parameters:
obj
- theStorable
object to add- Throws:
RuntimeException
- if an error occurs while storing the object
-
deleteFromDatabase
This method deletes a stoable object from the database.- Parameters:
obj
- theStorable
object to be deleted
-
updateDatabase
This method updates a storable object in the database.- Parameters:
obj
- theStorable
object to be updated- Throws:
RuntimeException
- if an error occurs while updating the object
-
getAllFromTable
public List<List<String>> getAllFromTable(String table, String joinTable, String joinColumn) throws RuntimeException Returns all attributes from a table.- Parameters:
table
- the table to get attributes fromjoinTable
- the table to join with if neededjoinColumn
- the column to join on if needed- Returns:
- a list of lists containing the attributes of the objects in the table
- Throws:
RuntimeException
- if an error occurs while getting all items
-
searchFromTable
public List<List<String>> searchFromTable(String table, String name, String joinTable, String joinColumn) throws RuntimeException This method searches for objects by name in the database.- Parameters:
table
- the table to search inname
- the name to search for (can also be only part of the name)joinTable
- the table to join with if neededjoinColumn
- the column to join on if needed- Returns:
- a list of lists containing the attributes of the objects with the given name
- Throws:
RuntimeException
- if an error occurs while searching for items
-
filterFromTable
public List<List<String>> filterFromTable(String table, String filterColumn, String filter, String joinTable, String joinColumn) throws RuntimeException This method filters objects by a given column in the database.- Parameters:
table
- the table to filter fromfilterColumn
- the column to filter byfilter
- the filter to usejoinTable
- the table to join with if neededjoinColumn
- the column to join on if needed- Returns:
- a list of items with the given category
- Throws:
RuntimeException
- if an error occurs while filtering items
-
getColumnsFromTable
Returns all columns from a table.- Parameters:
table
- the table to get columns from- Returns:
- a list of column names
- Throws:
RuntimeException
- if an error occurs while retrieving column names
-