mirror of
https://github.com/antebudimir/tempus.git
synced 2026-01-01 01:53:31 +00:00
Removed unused methods from artist repository
This commit is contained in:
parent
0e9ec60195
commit
b6a432c50f
3 changed files with 64 additions and 134 deletions
|
|
@ -22,18 +22,9 @@ public interface ArtistDao {
|
||||||
@Query("SELECT * FROM artist WHERE name LIKE '%' || :name || '%'")
|
@Query("SELECT * FROM artist WHERE name LIKE '%' || :name || '%'")
|
||||||
LiveData<List<Artist>> searchArtist(String name);
|
LiveData<List<Artist>> 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)
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
void insertAll(List<Artist> artists);
|
void insertAll(List<Artist> artists);
|
||||||
|
|
||||||
@Delete
|
|
||||||
void delete(Artist artist);
|
|
||||||
|
|
||||||
@Query("SELECT name FROM artist WHERE name LIKE :query || '%' OR name like '% ' || :query || '%' GROUP BY name LIMIT :number")
|
@Query("SELECT name FROM artist WHERE name LIKE :query || '%' OR name like '% ' || :query || '%' GROUP BY name LIMIT :number")
|
||||||
List<String> searchSuggestions(String query, int number);
|
List<String> searchSuggestions(String query, int number);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -91,6 +91,25 @@ public class AlbumRepository {
|
||||||
thread.start();
|
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) {
|
public Album getAlbumByID(String id) {
|
||||||
Album album = null;
|
Album album = null;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -55,131 +55,6 @@ public class ArtistRepository {
|
||||||
return suggestions;
|
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<Artist> 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<Artist> artists;
|
|
||||||
|
|
||||||
public InsertAllThreadSafe(ArtistDao artistDao, ArrayList<Artist> 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 static class SearchSuggestionsThreadSafe implements Runnable {
|
||||||
private ArtistDao artistDao;
|
private ArtistDao artistDao;
|
||||||
private String query;
|
private String query;
|
||||||
|
|
@ -202,6 +77,34 @@ public class ArtistRepository {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void insertAll(ArrayList<Artist> 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<Artist> artists;
|
||||||
|
|
||||||
|
public InsertAllThreadSafe(ArtistDao artistDao, ArrayList<Artist> 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 static class DeleteAllThreadSafe implements Runnable {
|
||||||
private ArtistDao artistDao;
|
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 static class GetArtistByIDThreadSafe implements Runnable {
|
||||||
private Artist artist;
|
private Artist artist;
|
||||||
private ArtistDao artistDao;
|
private ArtistDao artistDao;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue