package com.qimai.log.database

import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
/**
 *
 */
@Database(entities = [PushNotifiInfo::class], version = 1, exportSchema = false)
abstract class PushNotifiDataBase : RoomDatabase() {

    abstract fun pushInfoDao(): PushNotifiInfoDao

    companion object {
        // Singleton prevents multiple instances of database opening at the
        // same time.
        @Volatile
        private var INSTANCE: PushNotifiDataBase? = null

        fun getDatabase(context: Context): PushNotifiDataBase {
            val tempInstance = INSTANCE
            if (tempInstance != null) {
                return tempInstance
            }
            synchronized(this) {
                val instance = Room.databaseBuilder(
                        context.applicationContext,
                        PushNotifiDataBase::class.java,
                        "push_database"
                ).build()
                INSTANCE = instance
                return instance
            }
        }
    }

}