-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProfileRoomDatabase.java
More file actions
47 lines (38 loc) · 1.59 KB
/
Copy pathProfileRoomDatabase.java
File metadata and controls
47 lines (38 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package com.example.wagbaapplication;
import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import androidx.annotation.NonNull;
import androidx.room.Database;
import androidx.room.Room;
import androidx.room.RoomDatabase;
import androidx.sqlite.db.SupportSQLiteDatabase;
@Database(entities = {Profile.class}, version = 2, exportSchema = false)
public abstract class ProfileRoomDatabase extends RoomDatabase {
public abstract ProfileDao profileDao();
private static ProfileRoomDatabase INSTANCE;
static ProfileRoomDatabase getDatabase(final Context context) {
if (INSTANCE == null) {
synchronized (ProfileRoomDatabase.class) {
if (INSTANCE == null) {
INSTANCE = Room.databaseBuilder(context.getApplicationContext(),
ProfileRoomDatabase.class, "profile_database")
// Wipes and rebuilds instead of migrating
// if no Migration object.
// Migration is not part of this practical.
.fallbackToDestructiveMigration()
.addCallback(sRoomDatabaseCallback)
.build();
}
}
}
return INSTANCE;
}
private static RoomDatabase.Callback sRoomDatabaseCallback =
new RoomDatabase.Callback(){
@Override
public void onOpen (@NonNull SupportSQLiteDatabase db){
super.onOpen(db);
}
};
}