From the course: Building an Android App with Jetpack Libraries

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Implement database operations in a DAO

Implement database operations in a DAO - Android Tutorial

From the course: Building an Android App with Jetpack Libraries

Start my 1-month free trial

Implement database operations in a DAO

- A DAO, or Data Access Object class in room, defines all of the operations you want to execute with a particular data set. It's common to have one DAO class for each entity class, and that's what I'll do. A DAO is an interface. I'll place my new DAO from my notes table in my data package, and I'll name it NoteDao. And again, it's an interface. I'll mark the interface with the annotation Dao, and that's from androidx.room. Now, for each database operation, you'll want to create a function, and mark that function with a room annotation. The first function will be insertNote, and it'll accept a single argument, which is a note entity object. This isn't interface, and not a class, so I don't need to implement the function, that's going to be done by the room library. But I need to mark this function to tell room what this is supposed to do, and I'll use the insert annotation. I'll also pass in an optional property…

Contents