Search⌘ K
AI Features

Building WordRepository and GameRepository Adapters

Explore how to implement WordRepository and GameRepository adapters using Jdbi in Java. Learn to design database tables, set up SQL queries, and write integration code that passes tests for accessing words and game data, supporting test-driven development.

In this lesson, we’ll use the popular database library Jdbi to implement the fetchWordByNumber() method of interface WordRepository and make our failing integration test pass.

An external system, like a database, is accessed through a port in the domain model. The code that is specific to that external system is contained in an adapter. Our failing test enables us to write the database access code to fetch a word to guess.

Database design

A little bit of database design thinking needs to be done before we begin writing code. For the task at hand, it’s enough to note that we’ll store all available words to guess in a database table named word. This table ...