Skip to content

Commit

Permalink
[maro/#33] feat :: SongDao, SongDatabase 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
leesumin0526 committed May 27, 2024
1 parent bb3935b commit 31d11f9
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions UMC_6th/app/src/main/java/com/example/umc_6th/SongDatabase.kt
Original file line number Diff line number Diff line change
@@ -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
}
}
}

0 comments on commit 31d11f9

Please sign in to comment.