Defining a Data Access Object

A database table does not do much good if you cannot edit or access its contents. The first step to interacting with your database tables is to create a data access object, or DAO. A DAO is an interface that contains functions for each database operation you want to perform. In this chapter, CriminalIntent’s DAO needs two query functions: one to return a list of all crimes in the database and another to return a single crime matching a given UUID.

Add a file named CrimeDao.kt to the database package. In it, define an empty interface named CrimeDao annotated with Room’s @Dao annotation.

Listing 11.6  Creating an empty DAO (database/CrimeDao.kt)

@Dao
interface CrimeDao {
}

The @Dao annotation ...

Get Android Programming: The Big Nerd Ranch Guide, 4th Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.