Package edu.pdx.cs.joy.family
Class PersonDAOImpl
java.lang.Object
edu.pdx.cs.joy.family.PersonDAOImpl
- All Implemented Interfaces:
PersonDAO
Data Access Object implementation for managing Person entities in the database.
-
Constructor Summary
ConstructorsConstructorDescriptionPersonDAOImpl(Connection connection) Creates a new PersonDAOImpl with the specified database connection. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcreateTable(Connection connection) Creates the persons table in the database.voiddelete(int id) Deletes a person from the database by ID.static voiddropTable(Connection connection) Drops the persons table from the database if it exists.findAll()Finds all persons in the database.findById(int id) Finds a person by their ID.(package private) intgetFatherIdFromResultSet(ResultSet resultSet) Helper method to get father ID from result set.(package private) intgetMotherIdFromResultSet(ResultSet resultSet) Helper method to get mother ID from result set.voidSaves a person to the database.voidUpdates an existing person in the database.
-
Constructor Details
-
PersonDAOImpl
Creates a new PersonDAOImpl with the specified database connection.- Parameters:
connection- the database connection to use
-
-
Method Details
-
dropTable
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
Creates the persons table in the database.- Parameters:
connection- the database connection to use- Throws:
SQLException- if a database error occurs
-
save
Saves a person to the database.- Specified by:
savein interfacePersonDAO- Parameters:
person- the person to save- Throws:
SQLException- if a database error occurs
-
findById
Finds a person by their ID.- Specified by:
findByIdin interfacePersonDAO- 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
Finds all persons in the database.- Specified by:
findAllin interfacePersonDAO- Returns:
- a list of all persons
- Throws:
SQLException- if a database error occurs
-
update
Updates an existing person in the database.- Specified by:
updatein interfacePersonDAO- Parameters:
person- the person to update- Throws:
SQLException- if a database error occurs
-
delete
Deletes a person from the database by ID.- Specified by:
deletein interfacePersonDAO- 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
-