-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[maro/#33] feat :: SongDao, SongDatabase 추가
- Loading branch information
1 parent
bb3935b
commit 31d11f9
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
UMC_6th/app/src/main/java/com/example/umc_6th/SongDatabase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} |