Created
June 21, 2020 17:47
-
-
Save zijianjoy/e65d60df2be628adfd00f1f9ecfe7368 to your computer and use it in GitHub Desktop.
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
// Define database class which takes {@code Article} as table schema. | |
@Database(entities = Article.class, version = 1, exportSchema = false) | |
abstract class ArticleRoomDatabase extends RoomDatabase { | |
// APIs for accessing table data. | |
public abstract ArticleDao articleDao(); | |
private static volatile ArticleRoomDatabase SINGLETON; | |
private static final int NUMBER_OF_THREADS = 4; | |
static final ExecutorService databaseWriteExecutor = | |
Executors.newFixedThreadPool(NUMBER_OF_THREADS); | |
// Create database instance for Repository to access. | |
static ArticleRoomDatabase getDatabase(final Context context) { | |
if (SINGLETON == null){ | |
synchronized (ArticleRoomDatabase.class){ | |
if (SINGLETON != null) { | |
return SINGLETON; | |
} | |
SINGLETON = Room.databaseBuilder(context.getApplicationContext(), | |
ArticleRoomDatabase.class, | |
"articles").build(); | |
} | |
} | |
return SINGLETON; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment