In this seminar, you will be working with the database layer inside the Employee Records project. You will be adding and fixing the functionality for the storage related code for the employee records.

Task 0: Update your repository

For this seminar, you will work with the same forked repository as previously. We assume you already have the upstream remote set from Seminar 03 (if not, please follow task 0a from that seminar).

Task 0.1: Update your main branch

First, you need to fetch new changes from the upstream repository and update your local main branch:

git switch main
git pull upstream main

Then you need to update the main branch in your forked repository:

git push origin main

Task 0.2: Create a new branch for this seminar

Again, each pair creates a new branch on a single computer as they are working together as one person during the seminar.

Pair 1 creates a new branch seminar08-pair1:

git switch -c seminar08-pair1

Pair 2 creates a new branch seminar08-pair2:

git switch -c seminar08-pair2

Task 1: Discover the added code structure

Please navigate yourself through the Idea context menu as shown in the picture below. For the first attempt select just business and storage packages. Play a little bit with the controls above the diagram. Especially, we suggest to enable the Show Dependencies button.

Show Diagram

Try to understand the code that has been added. Think about the relations between the classes in the diagram.

We have added:

  • In memory repository object: cz.muni.fi.pv168.employees.storage.memory
  • Sql repository objects: cz.muni.fi.pv168.employees.storage.sql
  • DAO objects: cz.muni.fi.pv168.employees.storage.sql.dao
  • Connection/Transaction handlers: cz.muni.fi.pv168.employees.storage.sql.db
  • Entities that represent the database objects: cz.muni.fi.pv168.employees.storage.sql.entity
  • Mappers: cz.muni.fi.pv168.employees.storage.sql.entity.mapper
  • Dependency providers: cz.muni.fi.pv168.employees.wiring
  • Nuclear Quit action: cz.muni.fi.pv168.employees.ui.action.NuclearQuitAction

Diagram

Diagram

Important notes:

  • You should focus on the DAO and Repository objects, discuss why they are needed and what they do
  • Another thing you should discuss is why we need Entity objects (package entity)
    • With this try to understand why we need mappers
  • Transaction connection related functionality will be used in the next seminar

Task 2: Create a new employee

You should be able to create a new employee, are you? If you were not able to create a new employee, try to figure out why. What is missing? Discuss that with your partner.

Task 3: Add departments to the Employee Records

When you start the emploee records application, you will notice it is empty (without any employees). Adding a new employee will fail because of multiple problems that you will be fixing in this task.

There is already an SQL file that contains the SQL Query with “testing” departments. The file can be found in the resources, it is called: data_dev.sql. You can use either SqlFileExecutor or run this file manually.

Important note: THIS SQL FILE IS NOT IDEMPOTENT.

Important note: THE LOCATION OF DATABASE HAS CHANGED.

Task 4: Add Gender to the employee records

As you might probably know right now, the gender for the employee is currently not stored in the database. Fix that!

Do not forget to run all tests – all of them shall pass. Hint: look for TODO in the code.

Task 5: Fix the update for departments

First of all the go to the test cz.muni.fi.pv168.employees.storage.sql.DepartmentRepositoryTest and uncomment the updateDepartment() method. Try to run it and observe the behaviour. Investigate why the test failed.

After you have investigated why the test has failed, implement the fix.

Task 6: Implement update for the employees

The update for employees is also missing. Cover the operation by unit tests.

Task 7: Discuss data initialization at the application start

Let’s remind ourselves of Task 3, where we needed to run the migration add departments at the application start.

Discuss without implementing it, how you would initialize the application with testing data (we do not want to run the migration via console every time).

Bonus Task 1: Implement tests for EmployeeDao

We are currently missing tests for EmployeeDao, implement them.