Spring Applications

Exercise: Data Repositories

The objective of this exercise is to implement repositories with persistence operations and queries methods of bookstore entities.
  1. Create a Spring Boot application BookstoreApplication using the starter spring-boot-starter-data-jpa and the PostgreSQL and H2 database dependencies.
  2. Define the interfaces BookRepository, CustomerRepository and OrderRepository that extend the Spring JpaRepository interface and additionally provide
    • a method to find all books that contain a specific keyword in the title, authors, or publisher field
    • a method that checks if a customer with a specific email address exists
    • a method that returns CustomerInfo objects of all customers whose first or last name matches a specified name
    • a method that returns OrderInfo objects of all orders of a customer in a specified date range
  3. Use the configuration file application.properties to define the data source connected to the PostgreSQL database bookstore.
  4. Put the SQL script schema.sql in the classpath and data.sql in the testing classpath to initialize the database.
  5. Run the integration tests BookQueriesIT, CustomerQueriesIT and OrderQueriesIT that use the in-memory database H2.