Java · Advanced level

Advanced level · Module 6: Java Capstone Project · Lesson 2 of 5

Building the Data Layer

Implement the schema, entities and repositories for patients and appointments, with tested queries.

In this lesson you will

  • Implement the schema and repositories for the capstone
  • Test queries and constraints with integration tests

Key concepts

schema scriptsample datarepository queriesconstraint testing

The lesson

Start from the schema: tables for patients and appointments with keys, NOT NULL and a uniqueness rule that prevents two appointments for the same doctor at the same time. Let the database enforce what it can.

Implement repositories with the queries the stories need, such as appointments by date or by patient. Load sample data that covers normal and edge cases, using invented names only.

Integration tests prove the queries return the right rows and that constraints reject invalid data. Run them before building any endpoint on top.

Step by step

  1. Write the schema and sample-data scripts.
  2. Implement the repository methods.
  3. Write integration tests for each query.
  4. Test that a double booking is rejected by the database.

Practice activity

Complete milestone 2: the data layer with passing integration tests.

Expected result: All repository tests pass and the double-booking constraint is proven by a test.

Check your understanding

  1. Why enforce rules such as uniqueness in the database too?

    Show answer

    It protects data even if application code has a bug or another program writes to the database.

  2. Why use invented names in sample data?

    Show answer

    To avoid exposing real personal or health information.

Taught live by an instructor — online or in person. Free course lessons are for self-study and do not lead to a certificate — see registration options.