2020-11-20 15:38:08 +01:00
|
|
|
package com.cappielloantonio.play.database;
|
|
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
|
|
|
|
|
import androidx.room.Database;
|
|
|
|
|
import androidx.room.Room;
|
|
|
|
|
import androidx.room.RoomDatabase;
|
|
|
|
|
|
|
|
|
|
import com.cappielloantonio.play.database.dao.AlbumDao;
|
|
|
|
|
import com.cappielloantonio.play.database.dao.ArtistDao;
|
|
|
|
|
import com.cappielloantonio.play.database.dao.GenreDao;
|
|
|
|
|
import com.cappielloantonio.play.database.dao.PlaylistDao;
|
2020-11-21 13:54:49 +01:00
|
|
|
import com.cappielloantonio.play.database.dao.RecentSearchDao;
|
2020-11-20 15:38:08 +01:00
|
|
|
import com.cappielloantonio.play.database.dao.SongDao;
|
|
|
|
|
import com.cappielloantonio.play.model.Album;
|
|
|
|
|
import com.cappielloantonio.play.model.Artist;
|
|
|
|
|
import com.cappielloantonio.play.model.Genre;
|
|
|
|
|
import com.cappielloantonio.play.model.Playlist;
|
2020-11-21 13:54:49 +01:00
|
|
|
import com.cappielloantonio.play.model.RecentSearch;
|
2020-11-20 15:38:08 +01:00
|
|
|
import com.cappielloantonio.play.model.Song;
|
|
|
|
|
|
2020-11-21 13:54:49 +01:00
|
|
|
@Database(entities = {Album.class, Artist.class, Genre.class, Playlist.class, Song.class, RecentSearch.class}, version = 3, exportSchema = false)
|
2020-11-20 15:38:08 +01:00
|
|
|
public abstract class AppDatabase extends RoomDatabase {
|
|
|
|
|
private static final String TAG = "AppDatabase";
|
|
|
|
|
|
|
|
|
|
private static AppDatabase instance;
|
|
|
|
|
private final static String DB_NAME = "play_db";
|
|
|
|
|
|
|
|
|
|
public static synchronized AppDatabase getInstance(Context context) {
|
|
|
|
|
|
|
|
|
|
if (instance == null) {
|
|
|
|
|
instance = Room.databaseBuilder(context.getApplicationContext(), AppDatabase.class, DB_NAME)
|
|
|
|
|
.fallbackToDestructiveMigration()
|
|
|
|
|
.build();
|
|
|
|
|
}
|
|
|
|
|
return instance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public abstract AlbumDao albumDao();
|
|
|
|
|
|
|
|
|
|
public abstract ArtistDao artistDao();
|
|
|
|
|
|
|
|
|
|
public abstract GenreDao genreDao();
|
|
|
|
|
|
|
|
|
|
public abstract PlaylistDao playlistDao();
|
|
|
|
|
|
|
|
|
|
public abstract SongDao songDao();
|
2020-11-21 13:54:49 +01:00
|
|
|
|
|
|
|
|
public abstract RecentSearchDao recentSearchDao();
|
2020-11-20 15:38:08 +01:00
|
|
|
}
|