mirror of
https://github.com/CappielloAntonio/tempo.git
synced 2026-01-30 06:12:07 +00:00
Fix condition race in deleting element and insert new one
This commit is contained in:
@@ -11,6 +11,7 @@ import com.cappielloantonio.play.database.dao.SongArtistCrossDao;
|
||||
import com.cappielloantonio.play.model.AlbumArtistCross;
|
||||
import com.cappielloantonio.play.model.Queue;
|
||||
import com.cappielloantonio.play.model.Song;
|
||||
import com.cappielloantonio.play.model.SongArtistCross;
|
||||
import com.cappielloantonio.play.util.QueueUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -27,9 +28,17 @@ public class AlbumArtistRepository {
|
||||
}
|
||||
|
||||
public void insertAll(List<AlbumArtistCross> crosses) {
|
||||
InsertAllThreadSafe insertAll = new InsertAllThreadSafe(albumArtistCrossDao, crosses);
|
||||
Thread thread = new Thread(insertAll);
|
||||
thread.start();
|
||||
try {
|
||||
final Thread delete = new Thread(new DeleteAllAlbumArtistCrossThreadSafe(albumArtistCrossDao));
|
||||
final Thread insertAll = new Thread(new InsertAllThreadSafe(albumArtistCrossDao, crosses));
|
||||
|
||||
delete.start();
|
||||
delete.join();
|
||||
insertAll.start();
|
||||
insertAll.join();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static class InsertAllThreadSafe implements Runnable {
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.cappielloantonio.play.database.dao.AlbumArtistCrossDao;
|
||||
import com.cappielloantonio.play.database.dao.SongArtistCrossDao;
|
||||
import com.cappielloantonio.play.database.dao.SongGenreCrossDao;
|
||||
import com.cappielloantonio.play.model.AlbumArtistCross;
|
||||
import com.cappielloantonio.play.model.Song;
|
||||
import com.cappielloantonio.play.model.SongArtistCross;
|
||||
|
||||
import java.util.List;
|
||||
@@ -22,9 +23,17 @@ public class SongArtistRepository {
|
||||
}
|
||||
|
||||
public void insertAll(List<SongArtistCross> crosses) {
|
||||
InsertAllThreadSafe insertAll = new InsertAllThreadSafe(songArtistCrossDao, crosses);
|
||||
Thread thread = new Thread(insertAll);
|
||||
thread.start();
|
||||
try {
|
||||
final Thread delete = new Thread(new DeleteAllSongArtistCrossThreadSafe(songArtistCrossDao));
|
||||
final Thread insertAll = new Thread(new InsertAllThreadSafe(songArtistCrossDao, crosses));
|
||||
|
||||
delete.start();
|
||||
delete.join();
|
||||
insertAll.start();
|
||||
insertAll.join();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static class InsertAllThreadSafe implements Runnable {
|
||||
|
||||
@@ -271,8 +271,6 @@ public class SyncFragment extends Fragment {
|
||||
* Sincronizzazzione dell'album con gli artisti che hanno collaborato per la sua produzione | isProduced = false
|
||||
*/
|
||||
private void syncAlbumArtistCross(ArrayList<Album> albums) {
|
||||
albumArtistRepository.deleteAll();
|
||||
|
||||
List<AlbumArtistCross> crosses = new ArrayList<>();
|
||||
|
||||
for(Album album: albums) {
|
||||
@@ -298,8 +296,6 @@ public class SyncFragment extends Fragment {
|
||||
}
|
||||
|
||||
private void syncSongArtistCross(ArrayList<Song> songs) {
|
||||
songArtistRepository.deleteAll();
|
||||
|
||||
List<SongArtistCross> crosses = new ArrayList<>();
|
||||
|
||||
for(Song song: songs) {
|
||||
|
||||
Reference in New Issue
Block a user