Created
June 24, 2020 16:04
-
-
Save codejunk1e/5d2702fe8c1181c4f96a7ae794a8dcd6 to your computer and use it in GitHub Desktop.
RoomDatabase Template for Android
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.robin.theandroidcrew.movies.database; | |
import android.content.Context; | |
import android.util.Log; | |
import androidx.room.Room; | |
import androidx.room.RoomDatabase; | |
@androidx.room.Database(entities = {${MODEL_NAME}.class}, exportSchema = false, version = 1) | |
public abstract class Database extends RoomDatabase { | |
private static final String LOG_TAG = Database.class.getSimpleName(); | |
private static final Object LOCK = new Object(); | |
private static final String DATABASE_NAME = "${MODEL_NAME}Database"; | |
private static Database sInstance; | |
public static Database getInstance(Context context) { | |
if (sInstance == null) { | |
synchronized (LOCK) { | |
sInstance = Room.databaseBuilder(context.getApplicationContext(), | |
Database.class, Database.DATABASE_NAME) | |
.build(); | |
} | |
} | |
return sInstance; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment