Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. @Database(entities = [InputMsg::class], version = 1)
  2. abstract class AppDatabase : RoomDatabase() {
  3. abstract fun inputMsgDao(): InputMsgDao
  4.  
  5.  
  6. companion object {
  7. val DB_NAME = "livedata-db"
  8.  
  9. private var instance: AppDatabase? = null
  10.  
  11. fun getInstance(context: Context): AppDatabase {
  12. return instance ?: synchronized(this) {
  13. instance ?: buildDatabase(context).also { instance = it }
  14. }
  15. }
  16.  
  17. private fun buildDatabase(context: Context): AppDatabase {
  18. return Room.databaseBuilder(context.applicationContext, AppDatabase::class.java, DB_NAME)
  19. .fallbackToDestructiveMigration()
  20. .addCallback(object : RoomDatabase.Callback() {
  21. override fun onCreate(db: SupportSQLiteDatabase) {
  22. super.onCreate(db)
  23. }
  24. }).build()
  25. }
  26.  
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement