In normal sqlite we can achieve Synchronization easily but How to implement it in Room
The Room persistence library provides an abstraction layer over SQLite to allow for more robust database access while harnessing the full power of SQLite. Latest Update.
Room is a persistence library that's part of Android Jetpack. Room is an abstraction layer on top of a SQLite database. SQLite uses a specialized language (SQL) to perform database operations.
An easy way to use a database in an Android app is with a library called Room. Room is what's called an ORM (Object Relational Mapping) library, which as the name implies, maps the tables in a relational database to objects usable in Kotlin code.
Here is the sample which shows how to use Room with Content Provider which then you can link (ContentProvider ) with your SynchronizationAdapter.
Having said that you can modify your Room model as like
@Entity(tableName = Student.TABLE_NAME)
public class Student {
/** The name of the Student table. */
public static final String TABLE_NAME = "student";
/** The name of the ID column. */
public static final String COLUMN_ID = BaseColumns._ID;
/** The name of the name column. */
public static final String COLUMN_NAME = "name";
/** The unique ID of the Student*/
@PrimaryKey(autoGenerate = true)
@ColumnInfo(index = true, name = COLUMN_ID)
public long id;
/** The name of the Student*/
@ColumnInfo(name = COLUMN_NAME)
public String name;
/**
* Create a new {@link Studentfrom the specified {@link ContentValues}.
*
* @param values A {@link ContentValues} that at least contain {@link #COLUMN_NAME}.
* @return A newly created {@link Student} instance.
*/
public static Student fromContentValues(ContentValues values) {
final Student student= new Student();
if (values.containsKey(COLUMN_ID)) {
student.id = values.getAsLong(COLUMN_ID);
}
if (values.containsKey(COLUMN_NAME)) {
student.name = values.getAsString(COLUMN_NAME);
}
return student;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With