Removed unused methods from queue repository

This commit is contained in:
CappielloAntonio 2021-04-19 15:00:21 +02:00
parent c1496d01a2
commit fc57befd73
2 changed files with 120 additions and 170 deletions

View file

@ -20,15 +20,9 @@ public interface QueueDao {
@Query("SELECT * FROM song JOIN queue ON song.id = queue.id") @Query("SELECT * FROM song JOIN queue ON song.id = queue.id")
List<Song> getAllSimple(); List<Song> getAllSimple();
@Insert(onConflict = OnConflictStrategy.REPLACE)
void insert(Queue songQueueObject);
@Insert(onConflict = OnConflictStrategy.REPLACE) @Insert(onConflict = OnConflictStrategy.REPLACE)
void insertAll(List<Queue> songQueueObject); void insertAll(List<Queue> songQueueObject);
@Delete
void delete(Queue songQueueObject);
@Query("DELETE FROM queue WHERE queue.track_order = :position") @Query("DELETE FROM queue WHERE queue.track_order = :position")
void deleteByPosition(int position); void deleteByPosition(int position);

View file

@ -50,10 +50,22 @@ public class QueueRepository {
return songs; return songs;
} }
public void insert(Song song, int position) { private static class GetSongsThreadSafe implements Runnable {
InsertThreadSafe insert = new InsertThreadSafe(queueDao, song, position); private QueueDao queueDao;
Thread thread = new Thread(insert); private List<Song> songs;
thread.start();
public GetSongsThreadSafe(QueueDao queueDao) {
this.queueDao = queueDao;
}
@Override
public void run() {
songs = queueDao.getAllSimple();
}
public List<Song> getSongs() {
return songs;
}
} }
public void insertAll(List<Song> songs) { public void insertAll(List<Song> songs) {
@ -82,166 +94,6 @@ public class QueueRepository {
return mix; return mix;
} }
public void insertAllAndStartNew(List<Song> songs) {
try {
final Thread delete = new Thread(new DeleteAllThreadSafe(queueDao));
final Thread insertAll = new Thread(new InsertAllThreadSafe(queueDao, songs));
delete.start();
delete.join();
insertAll.start();
insertAll.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
public void delete(Queue queueElement) {
DeleteThreadSafe delete = new DeleteThreadSafe(queueDao, queueElement);
Thread thread = new Thread(delete);
thread.start();
}
public void deleteByPosition(int position) {
DeleteByPositionThreadSafe delete = new DeleteByPositionThreadSafe(queueDao, position);
Thread thread = new Thread(delete);
thread.start();
}
public void deleteAll() {
DeleteAllThreadSafe delete = new DeleteAllThreadSafe(queueDao);
Thread thread = new Thread(delete);
thread.start();
}
public int count() {
int count = 0;
CountThreadSafe countThread = new CountThreadSafe(queueDao);
Thread thread = new Thread(countThread);
thread.start();
try {
thread.join();
count = countThread.getCount();
} catch (InterruptedException e) {
e.printStackTrace();
}
return count;
}
private static class InsertThreadSafe implements Runnable {
private QueueDao queueDao;
private Song song;
private int position;
public InsertThreadSafe(QueueDao queueDao, Song song, int position) {
this.queueDao = queueDao;
this.song = song;
this.position = position;
}
@Override
public void run() {
queueDao.insert(QueueUtil.getQueueElementFromSong(song, position));
}
}
private static class InsertAllThreadSafe implements Runnable {
private QueueDao queueDao;
private List<Song> songs;
public InsertAllThreadSafe(QueueDao queueDao, List<Song> songs) {
this.queueDao = queueDao;
this.songs = songs;
}
@Override
public void run() {
queueDao.insertAll(QueueUtil.getQueueElementsFromSongs(songs));
}
}
private static class DeleteThreadSafe implements Runnable {
private QueueDao queueDao;
private Queue queueElement;
public DeleteThreadSafe(QueueDao queueDao, Queue queueElement) {
this.queueDao = queueDao;
this.queueElement = queueElement;
}
@Override
public void run() {
queueDao.delete(queueElement);
}
}
private static class DeleteAllThreadSafe implements Runnable {
private QueueDao queueDao;
public DeleteAllThreadSafe(QueueDao queueDao) {
this.queueDao = queueDao;
}
@Override
public void run() {
queueDao.deleteAll();
}
}
private static class DeleteByPositionThreadSafe implements Runnable {
private QueueDao queueDao;
private int position;
public DeleteByPositionThreadSafe(QueueDao queueDao,int position) {
this.queueDao = queueDao;
this.position = position;
}
@Override
public void run() {
queueDao.deleteByPosition(position);
}
}
private static class CountThreadSafe implements Runnable {
private QueueDao queueDao;
private int count = 0;
public CountThreadSafe(QueueDao queueDao) {
this.queueDao = queueDao;
}
@Override
public void run() {
count = queueDao.count();
}
public int getCount() {
return count;
}
}
private static class GetSongsThreadSafe implements Runnable {
private QueueDao queueDao;
private List<Song> songs;
public GetSongsThreadSafe(QueueDao queueDao) {
this.queueDao = queueDao;
}
@Override
public void run() {
songs = queueDao.getAllSimple();
}
public List<Song> getSongs() {
return songs;
}
}
private static class GetSongsByIDThreadSafe implements Runnable { private static class GetSongsByIDThreadSafe implements Runnable {
private SongDao songDao; private SongDao songDao;
private List<String> IDs; private List<String> IDs;
@ -261,4 +113,108 @@ public class QueueRepository {
return songs; return songs;
} }
} }
public void insertAllAndStartNew(List<Song> songs) {
try {
final Thread delete = new Thread(new DeleteAllThreadSafe(queueDao));
final Thread insertAll = new Thread(new InsertAllThreadSafe(queueDao, songs));
delete.start();
delete.join();
insertAll.start();
insertAll.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
private static class InsertAllThreadSafe implements Runnable {
private QueueDao queueDao;
private List<Song> songs;
public InsertAllThreadSafe(QueueDao queueDao, List<Song> songs) {
this.queueDao = queueDao;
this.songs = songs;
}
@Override
public void run() {
queueDao.insertAll(QueueUtil.getQueueElementsFromSongs(songs));
}
}
public void deleteByPosition(int position) {
DeleteByPositionThreadSafe delete = new DeleteByPositionThreadSafe(queueDao, position);
Thread thread = new Thread(delete);
thread.start();
}
private static class DeleteByPositionThreadSafe implements Runnable {
private QueueDao queueDao;
private int position;
public DeleteByPositionThreadSafe(QueueDao queueDao,int position) {
this.queueDao = queueDao;
this.position = position;
}
@Override
public void run() {
queueDao.deleteByPosition(position);
}
}
public void deleteAll() {
DeleteAllThreadSafe delete = new DeleteAllThreadSafe(queueDao);
Thread thread = new Thread(delete);
thread.start();
}
private static class DeleteAllThreadSafe implements Runnable {
private QueueDao queueDao;
public DeleteAllThreadSafe(QueueDao queueDao) {
this.queueDao = queueDao;
}
@Override
public void run() {
queueDao.deleteAll();
}
}
public int count() {
int count = 0;
CountThreadSafe countThread = new CountThreadSafe(queueDao);
Thread thread = new Thread(countThread);
thread.start();
try {
thread.join();
count = countThread.getCount();
} catch (InterruptedException e) {
e.printStackTrace();
}
return count;
}
private static class CountThreadSafe implements Runnable {
private QueueDao queueDao;
private int count = 0;
public CountThreadSafe(QueueDao queueDao) {
this.queueDao = queueDao;
}
@Override
public void run() {
count = queueDao.count();
}
public int getCount() {
return count;
}
}
} }