Created
May 18, 2018 08:35
-
-
Save vprabhu/30bff3975bc240a4ed5ddfe96f5327ef 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
@Database(entities = arrayOf(TodoTask::class), version = 1, exportSchema = false) | |
@TypeConverters(DataConverter::class) | |
abstract class AppDatabase : RoomDatabase() { | |
abstract fun todoTaskDao(): TodoTaskDao | |
companion object { | |
private val LOCK = Any() | |
private val DATABASE_NAME = "todotaskList" | |
private var sAppDatabaseSingletonInstance: AppDatabase? = null | |
fun getInstance(context: Context): AppDatabase? { | |
if (sAppDatabaseSingletonInstance == null) { | |
synchronized(LOCK) { | |
sAppDatabaseSingletonInstance = Room.databaseBuilder( | |
context.applicationContext, | |
AppDatabase::class.java, | |
AppDatabase.DATABASE_NAME | |
).build() | |
} | |
} | |
return sAppDatabaseSingletonInstance; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment