From 8eab87f02f9a00ec1c7e261f59a2d4ba120b2877 Mon Sep 17 00:00:00 2001 From: Gouri Panda Date: Sun, 4 Dec 2022 18:36:44 +0530 Subject: [PATCH] kiwixRoomDatabase created --- .../core/data/local/KiwixRoomDatabase.kt | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 core/src/main/java/org/kiwix/kiwixmobile/core/data/local/KiwixRoomDatabase.kt diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/data/local/KiwixRoomDatabase.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/data/local/KiwixRoomDatabase.kt new file mode 100644 index 000000000..168cd9c02 --- /dev/null +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/data/local/KiwixRoomDatabase.kt @@ -0,0 +1,43 @@ +/* + * Kiwix Android + * Copyright (c) 2022 Kiwix + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package org.kiwix.kiwixmobile.core.data.local + +import android.content.Context +import androidx.room.Room +import androidx.room.RoomDatabase + +abstract class KiwixRoomDatabase : RoomDatabase() { + + companion object { + private var db: KiwixRoomDatabase? = null + fun getInstance(context: Context): KiwixRoomDatabase { + return db ?: synchronized(KiwixRoomDatabase::class) { + return@getInstance db + ?: Room.databaseBuilder(context, KiwixRoomDatabase::class.java, "KiwixRoom.db") + // We have already database name called kiwix.db in order to avoid complexity we named as + // kiwixRoom.db + .build() + } + } + + fun destroyInstance() { + db = null + } + } +}