From b6a432c50fcfaf4210abf5c14fbc20ee8afb3087 Mon Sep 17 00:00:00 2001 From: CappielloAntonio Date: Mon, 19 Apr 2021 14:53:43 +0200 Subject: [PATCH] Removed unused methods from artist repository --- .../play/database/dao/ArtistDao.java | 9 - .../play/repository/AlbumRepository.java | 19 ++ .../play/repository/ArtistRepository.java | 170 +++++------------- 3 files changed, 64 insertions(+), 134 deletions(-) diff --git a/app/src/main/java/com/cappielloantonio/play/database/dao/ArtistDao.java b/app/src/main/java/com/cappielloantonio/play/database/dao/ArtistDao.java index 6592728c..738e59f4 100644 --- a/app/src/main/java/com/cappielloantonio/play/database/dao/ArtistDao.java +++ b/app/src/main/java/com/cappielloantonio/play/database/dao/ArtistDao.java @@ -22,18 +22,9 @@ public interface ArtistDao { @Query("SELECT * FROM artist WHERE name LIKE '%' || :name || '%'") LiveData> searchArtist(String name); - @Query("SELECT EXISTS(SELECT * FROM artist WHERE id = :id)") - boolean exist(String id); - - @Insert(onConflict = OnConflictStrategy.REPLACE) - void insert(Artist artist); - @Insert(onConflict = OnConflictStrategy.REPLACE) void insertAll(List artists); - @Delete - void delete(Artist artist); - @Query("SELECT name FROM artist WHERE name LIKE :query || '%' OR name like '% ' || :query || '%' GROUP BY name LIMIT :number") List searchSuggestions(String query, int number); diff --git a/app/src/main/java/com/cappielloantonio/play/repository/AlbumRepository.java b/app/src/main/java/com/cappielloantonio/play/repository/AlbumRepository.java index 8f558056..66830a74 100644 --- a/app/src/main/java/com/cappielloantonio/play/repository/AlbumRepository.java +++ b/app/src/main/java/com/cappielloantonio/play/repository/AlbumRepository.java @@ -91,6 +91,25 @@ public class AlbumRepository { thread.start(); } + public void deleteAll() { + DeleteAllThreadSafe delete = new DeleteAllThreadSafe(albumDao); + Thread thread = new Thread(delete); + thread.start(); + } + + private static class DeleteAllThreadSafe implements Runnable { + private AlbumDao albumDao; + + public DeleteAllThreadSafe(AlbumDao albumDao) { + this.albumDao = albumDao; + } + + @Override + public void run() { + albumDao.deleteAll(); + } + } + public Album getAlbumByID(String id) { Album album = null; diff --git a/app/src/main/java/com/cappielloantonio/play/repository/ArtistRepository.java b/app/src/main/java/com/cappielloantonio/play/repository/ArtistRepository.java index 88294109..00c2d538 100644 --- a/app/src/main/java/com/cappielloantonio/play/repository/ArtistRepository.java +++ b/app/src/main/java/com/cappielloantonio/play/repository/ArtistRepository.java @@ -55,131 +55,6 @@ public class ArtistRepository { return suggestions; } - public boolean exist(Artist artist) { - boolean exist = false; - - ExistThreadSafe existThread = new ExistThreadSafe(artistDao, artist); - Thread thread = new Thread(existThread); - thread.start(); - - try { - thread.join(); - exist = existThread.exist(); - } - catch (InterruptedException e) { - e.printStackTrace(); - } - - return exist; - } - - public void insert(Artist artist) { - InsertThreadSafe insert = new InsertThreadSafe(artistDao, artist); - Thread thread = new Thread(insert); - thread.start(); - } - - public void insertAll(ArrayList artists) { - InsertAllThreadSafe insertAll = new InsertAllThreadSafe(artistDao, artists); - Thread thread = new Thread(insertAll); - thread.start(); - } - - public void delete(Artist artist) { - DeleteThreadSafe delete = new DeleteThreadSafe(artistDao, artist); - Thread thread = new Thread(delete); - thread.start(); - } - - public void deleteAll() { - DeleteAllThreadSafe delete = new DeleteAllThreadSafe(artistDao); - Thread thread = new Thread(delete); - thread.start(); - } - - public Artist getArtistByID(String id) { - Artist artist = null; - - GetArtistByIDThreadSafe getArtist = new GetArtistByIDThreadSafe(artistDao, id); - Thread thread = new Thread(getArtist); - thread.start(); - - try { - thread.join(); - artist = getArtist.getArtist(); - } catch (InterruptedException e) { - e.printStackTrace(); - } - - return artist; - } - - private static class ExistThreadSafe implements Runnable { - private ArtistDao artistDao; - private Artist artist; - private boolean exist = false; - - public ExistThreadSafe(ArtistDao artistDao, Artist artist) { - this.artistDao = artistDao; - this.artist = artist; - } - - @Override - public void run() { - exist = artistDao.exist(artist.getId()); - } - - public boolean exist() { - return exist; - } - } - - private static class InsertThreadSafe implements Runnable { - private ArtistDao artistDao; - private Artist artist; - - public InsertThreadSafe(ArtistDao artistDao, Artist artist) { - this.artistDao = artistDao; - this.artist = artist; - } - - @Override - public void run() { - artistDao.insert(artist); - } - } - - private static class InsertAllThreadSafe implements Runnable { - private ArtistDao artistDao; - private ArrayList artists; - - public InsertAllThreadSafe(ArtistDao artistDao, ArrayList artists) { - this.artistDao = artistDao; - this.artists = artists; - } - - @Override - public void run() { - artistDao.deleteAll(); - artistDao.insertAll(artists); - } - } - - private static class DeleteThreadSafe implements Runnable { - private ArtistDao artistDao; - private Artist artist; - - public DeleteThreadSafe(ArtistDao artistDao, Artist artist) { - this.artistDao = artistDao; - this.artist = artist; - } - - @Override - public void run() { - artistDao.delete(artist); - } - } - private static class SearchSuggestionsThreadSafe implements Runnable { private ArtistDao artistDao; private String query; @@ -202,6 +77,34 @@ public class ArtistRepository { } } + public void insertAll(ArrayList artists) { + InsertAllThreadSafe insertAll = new InsertAllThreadSafe(artistDao, artists); + Thread thread = new Thread(insertAll); + thread.start(); + } + + private static class InsertAllThreadSafe implements Runnable { + private ArtistDao artistDao; + private ArrayList artists; + + public InsertAllThreadSafe(ArtistDao artistDao, ArrayList artists) { + this.artistDao = artistDao; + this.artists = artists; + } + + @Override + public void run() { + artistDao.deleteAll(); + artistDao.insertAll(artists); + } + } + + public void deleteAll() { + DeleteAllThreadSafe delete = new DeleteAllThreadSafe(artistDao); + Thread thread = new Thread(delete); + thread.start(); + } + private static class DeleteAllThreadSafe implements Runnable { private ArtistDao artistDao; @@ -215,6 +118,23 @@ public class ArtistRepository { } } + public Artist getArtistByID(String id) { + Artist artist = null; + + GetArtistByIDThreadSafe getArtist = new GetArtistByIDThreadSafe(artistDao, id); + Thread thread = new Thread(getArtist); + thread.start(); + + try { + thread.join(); + artist = getArtist.getArtist(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + return artist; + } + private static class GetArtistByIDThreadSafe implements Runnable { private Artist artist; private ArtistDao artistDao;