Package Common

Class Database

java.lang.Object
Common.Database
Direct Known Subclasses:
AccountDatabase, AppointmentOutcomeDatabase, DoctorSchedule, InventoryDatabase, InventoryRequestDatabase, MedicalRecordDatabase

public abstract class Database extends Object
The Database class serves as an abstract base class for managing collections of DatabaseItems. It provides methods for extracting items from a CSV file, storing items to a CSV file, and managing database records.
  • Field Details

  • Constructor Details

    • Database

      public Database()
  • Method Details

    • setcsvPath

      public void setcsvPath(String path)
      Sets the path to the CSV file used for storing and retrieving data.
      Parameters:
      path - the path to the CSV file
    • extractFromCSV

      public void extractFromCSV()
      Extracts database items from the specified CSV file. This method reads from the CSV file, skipping the header, and populates the records list with items created using the createDatabaseItem(String[]) method.
    • storeToCSV

      public void storeToCSV()
      Stores all database items to the specified CSV file. This method writes the header format followed by each item's serialized representation to the CSV file.
    • setHeaderFormat

      protected void setHeaderFormat(String headerFormat)
      Sets the header format for the CSV file.
      Parameters:
      headerFormat - a string representing the header format
    • printItems

      protected void printItems(String title)
      Prints all items in the database with a specified title.
      Parameters:
      title - the title to be printed before listing items
    • addItem

      public void addItem(DatabaseItems item)
      Adds a new item to the database records.
      Parameters:
      item - the DatabaseItems object to be added
    • getRecords

      public List<DatabaseItems> getRecords()
      Returns a list of all database items.
      Returns:
      a list of DatabaseItems objects in this database
    • createDatabaseItem

      protected abstract DatabaseItems createDatabaseItem(String[] values)
      Creates a specific DatabaseItems object from an array of values. This method must be implemented by subclasses to define how database items are created from CSV data.
      Parameters:
      values - an array of strings containing data for creating an item
      Returns:
      a new instance of DatabaseItems
    • printItems

      public abstract void printItems()
      Prints all items in this database. This method must be implemented by subclasses to provide specific printing functionality.
    • removeItem

      public abstract boolean removeItem(String id)
      Removes an item from the database using its unique identifier.
      Parameters:
      id - the unique identifier of the item to be removed
      Returns:
      true if the item was successfully removed; false otherwise
    • searchItem

      public abstract DatabaseItems searchItem(String id)
      Searches for an item in the database using its unique identifier.
      Parameters:
      id - the unique identifier of the item to search for
      Returns:
      the found DatabaseItems object, or null if not found