2019-05-26 18:40:02 +02:00
|
|
|
package com.denizd.substitutionplan
|
|
|
|
|
|
|
|
|
|
import android.content.Context
|
|
|
|
|
import androidx.room.Database
|
|
|
|
|
import androidx.room.Room
|
|
|
|
|
import androidx.room.RoomDatabase
|
|
|
|
|
|
2019-08-18 17:53:22 +02:00
|
|
|
@Database(entities = [Subst::class, Food::class], version = 5, exportSchema = false)
|
2019-05-26 18:40:02 +02:00
|
|
|
public abstract class SubstDatabase : RoomDatabase() {
|
|
|
|
|
|
|
|
|
|
abstract fun substDao(): SubstDao
|
|
|
|
|
|
|
|
|
|
companion object {
|
|
|
|
|
|
|
|
|
|
private var instance: SubstDatabase? = null
|
|
|
|
|
|
|
|
|
|
fun getInstance(context: Context): SubstDatabase? {
|
|
|
|
|
if (instance == null) {
|
|
|
|
|
synchronized (SubstDatabase::class) {
|
|
|
|
|
instance = Room.databaseBuilder(context.applicationContext,
|
|
|
|
|
SubstDatabase::class.java,
|
|
|
|
|
"subst_database")
|
|
|
|
|
.fallbackToDestructiveMigration()
|
|
|
|
|
.build()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return instance
|
|
|
|
|
}
|
2019-07-06 14:18:59 +02:00
|
|
|
|
2019-08-21 10:26:54 +02:00
|
|
|
private var foodInstance: SubstDatabase? = null
|
|
|
|
|
|
2019-07-06 14:18:59 +02:00
|
|
|
fun getFoodInstance(context: Context): SubstDatabase? {
|
2019-08-21 10:26:54 +02:00
|
|
|
if (foodInstance == null) {
|
2019-07-06 14:18:59 +02:00
|
|
|
synchronized (SubstDatabase::class) {
|
2019-08-21 10:26:54 +02:00
|
|
|
foodInstance = Room.databaseBuilder(context.applicationContext,
|
2019-07-06 14:18:59 +02:00
|
|
|
SubstDatabase::class.java,
|
|
|
|
|
"food_database")
|
|
|
|
|
.fallbackToDestructiveMigration()
|
|
|
|
|
.build()
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-08-21 10:26:54 +02:00
|
|
|
return foodInstance
|
2019-07-06 14:18:59 +02:00
|
|
|
}
|
2019-05-26 18:40:02 +02:00
|
|
|
}
|
|
|
|
|
}
|