Class PersonDAOImpl

java.lang.Object
edu.pdx.cs.joy.family.PersonDAOImpl
All Implemented Interfaces:
PersonDAO

public class PersonDAOImpl extends Object implements PersonDAO
Data Access Object implementation for managing Person entities in the database.
  • Constructor Details

    • PersonDAOImpl

      public PersonDAOImpl(Connection connection)
      Creates a new PersonDAOImpl with the specified database connection.
      Parameters:
      connection - the database connection to use
  • Method Details

    • dropTable

      public static void dropTable(Connection connection) throws SQLException
      Drops the persons table from the database if it exists.
      Parameters:
      connection - the database connection to use
      Throws:
      SQLException - if a database error occurs
    • createTable

      public static void createTable(Connection connection) throws SQLException
      Creates the persons table in the database.
      Parameters:
      connection - the database connection to use
      Throws:
      SQLException - if a database error occurs
    • save

      public void save(Person person) throws SQLException
      Saves a person to the database.
      Specified by:
      save in interface PersonDAO
      Parameters:
      person - the person to save
      Throws:
      SQLException - if a database error occurs
    • findById

      public Person findById(int id) throws SQLException
      Finds a person by their ID.
      Specified by:
      findById in interface PersonDAO
      Parameters:
      id - the ID to search for
      Returns:
      the person with the given ID, or null if not found
      Throws:
      SQLException - if a database error occurs
    • findAll

      public List<Person> findAll() throws SQLException
      Finds all persons in the database.
      Specified by:
      findAll in interface PersonDAO
      Returns:
      a list of all persons
      Throws:
      SQLException - if a database error occurs
    • update

      public void update(Person person) throws SQLException
      Updates an existing person in the database.
      Specified by:
      update in interface PersonDAO
      Parameters:
      person - the person to update
      Throws:
      SQLException - if a database error occurs
    • delete

      public void delete(int id) throws SQLException
      Deletes a person from the database by ID.
      Specified by:
      delete in interface PersonDAO
      Parameters:
      id - the ID of the person to delete
      Throws:
      SQLException - if a database error occurs
    • getFatherIdFromResultSet

      Helper method to get father ID from result set. Package-protected to allow FamilyTreeDAO to resolve relationships.
      Parameters:
      resultSet - the result set
      Returns:
      the father ID or Person.UNKNOWN if null
      Throws:
      SQLException - if a database error occurs
    • getMotherIdFromResultSet

      Helper method to get mother ID from result set. Package-protected to allow FamilyTreeDAO to resolve relationships.
      Parameters:
      resultSet - the result set
      Returns:
      the mother ID or Person.UNKNOWN if null
      Throws:
      SQLException - if a database error occurs