Class DAO

java.lang.Object
no.ntnu.idatt1002.demo.dao.DAO

public class DAO extends Object
This class provides methods for accessing all tables in the database.
  • Field Details

  • Constructor Details

  • Method Details

    • addToDatabase

      public void addToDatabase(Storable obj) throws RuntimeException
      This method adds a storable object to the database.
      Parameters:
      obj - the Storable object to add
      Throws:
      RuntimeException - if an error occurs while storing the object
    • deleteFromDatabase

      public void deleteFromDatabase(Storable obj)
      This method deletes a stoable object from the database.
      Parameters:
      obj - the Storable object to be deleted
    • updateDatabase

      public void updateDatabase(Storable obj) throws RuntimeException
      This method updates a storable object in the database.
      Parameters:
      obj - the Storable 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 from
      joinTable - the table to join with if needed
      joinColumn - 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 in
      name - the name to search for (can also be only part of the name)
      joinTable - the table to join with if needed
      joinColumn - 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 from
      filterColumn - the column to filter by
      filter - the filter to use
      joinTable - the table to join with if needed
      joinColumn - 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

      private List<String> getColumnsFromTable(String table) throws RuntimeException
      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