Skip to content

Instantly share code, notes, and snippets.

@ajaypro
Created November 3, 2018 09:38
Show Gist options
  • Save ajaypro/eafc6b5c320536f4ab279eaad9f62bed to your computer and use it in GitHub Desktop.
Save ajaypro/eafc6b5c320536f4ab279eaad9f62bed to your computer and use it in GitHub Desktop.
Roomdatabase subclass
@Database(entities = {objects.ChecklistItem.class, OfflineData.class}, version = 4, exportSchema = false)
@TypeConverters({DateConverter.class, GeopointsConverter.class})
public abstract class DbChecklist extends RoomDatabase {
private static final Object LOCK = new Object();
private static final String DATABASE_NAME = "****.db";
private static DbChecklist sInstance;
public static DbChecklist getsInstance(Context context) {
//to make sure that Singleton Pattern is followed
//i.e. only one object of the class is created.
if (sInstance == null) {
synchronized (LOCK) {
sInstance = Room.databaseBuilder(context.getApplicationContext(),
DbChecklist.class, DbChecklist.DATABASE_NAME)
.addMigrations(MIGRATION_3_4)
.build();
}
}
return sInstance;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment