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 - Android Tutorial
From the course: Building an Android App with Jetpack Libraries
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
-
-
-
-
-
-
Turn a data class into a Room entity3m 3s
-
(Locked)
Implement database operations in a DAO4m 7s
-
(Locked)
Create a custom type converter2m 14s
-
(Locked)
Define an SQLite database with Room4m 31s
-
(Locked)
Create a unit test for database logic5m 11s
-
(Locked)
Challenge: Add another unit test for database logic1m 27s
-
(Locked)
Solution: Add another unit test for database logic3m 3s
-
-
-
-