In this tutorial, we will learn step by step using Android Room's persistent SQLite ORM mapper. As we have practiced in my last tutorial with GreenDAO which is a fast SQLite wrapper for ORM.
Google I / O 2017 has introduced the new database persistence library called Room as ORM like GreenDAO and ORMLite. There are 3 major components in Room.
- Database
- Entity
- DAO
Database: A database is a component that creates a database holder. Annotations define a list of entities, and the class content defines a list of data access objects (DAO) in the database. This is also the main access point for the underlying connection.
Entity: This component represents the class that stores the database row. For each entity, a database table is created to store items.
DAO: This component represents a class or interface as a Data Access Object (DAO). DAO is the main component of Room and is responsible for determining methods that access the database.
Ok, Let's integrate the Space library in one of the project examples with Kotlin reactively by RxJava2. The first thing to add relevant dependencies in the build.gradle file.
In project level of build.gradle file we need to add maven google path to download the dependency.
Now all setup is ready, let’s create the database entity.
Now let’s create a DAO class.
Now create an instance of a database.
Now let’s create the instance of the database to observing with Live data.
Let’s create an interface for what are the operations required in the project and implement those locally.
Ok, Let’s implement those.
Please add database creator into MainApplication.
Ok all done, We can call the insert operation to insert data into the table and get details from the database table.
Wrapping Up: This is the good implementation of Android Room with Kotlin. Room introduced in new Android Architecture component. But this is still in alpha, So it might change implementation.
You can get the full source code from Github.
Also Read :
- Full Source Code Android GAme Snow Skating With Admob Leaderboard - Free Download
- Universal v4.0 – Full Multi-Purpose Android App Source code Download Free
- Full Source Code Apps Mosque Finder Android to Admob reskinner Codecanyon
- Source Code Game Android Full Reskinner To ADMOB "Toby’s Adventures Beach "