From 31d11f9af3fbf3530f32f1899418aa8012c17703 Mon Sep 17 00:00:00 2001 From: leesumin0526 Date: Mon, 27 May 2024 12:11:20 +0900 Subject: [PATCH] =?UTF-8?q?[maro/#33]=20feat=20::=20SongDao,=20SongDatabas?= =?UTF-8?q?e=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/example/umc_6th/SongDatabase.kt | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 UMC_6th/app/src/main/java/com/example/umc_6th/SongDatabase.kt diff --git a/UMC_6th/app/src/main/java/com/example/umc_6th/SongDatabase.kt b/UMC_6th/app/src/main/java/com/example/umc_6th/SongDatabase.kt new file mode 100644 index 0000000..9feaa7c --- /dev/null +++ b/UMC_6th/app/src/main/java/com/example/umc_6th/SongDatabase.kt @@ -0,0 +1,30 @@ +package com.example.umc_6th + +import android.content.Context +import androidx.room.Database +import androidx.room.Room +import androidx.room.RoomDatabase + +@Database(entities = [Song::class], version = 1) +abstract class SongDatabase: RoomDatabase() { + abstract fun songDao(): SongDao + + companion object { + private var instance: SongDatabase? = null + + @Synchronized + fun getInstance(context: Context): SongDatabase? { + if (instance == null) { + synchronized(SongDatabase::class){ + instance = Room.databaseBuilder( + context.applicationContext, + SongDatabase::class.java, + "song-database" // 다른 데이터 베이스랑 이름이 겹치지 않도록 주의 + ).allowMainThreadQueries().build() // 편의상 메인 쓰레드에서 처리하게 한다. + } + } + + return instance + } + } +} \ No newline at end of file