mirror of
https://github.com/antebudimir/tempus.git
synced 2025-12-31 17:43:32 +00:00
Fix condition race in deleting element and insert new one
This commit is contained in:
parent
3addc3b561
commit
fc430e5811
3 changed files with 24 additions and 10 deletions
|
|
@ -11,6 +11,7 @@ import com.cappielloantonio.play.database.dao.SongArtistCrossDao;
|
||||||
import com.cappielloantonio.play.model.AlbumArtistCross;
|
import com.cappielloantonio.play.model.AlbumArtistCross;
|
||||||
import com.cappielloantonio.play.model.Queue;
|
import com.cappielloantonio.play.model.Queue;
|
||||||
import com.cappielloantonio.play.model.Song;
|
import com.cappielloantonio.play.model.Song;
|
||||||
|
import com.cappielloantonio.play.model.SongArtistCross;
|
||||||
import com.cappielloantonio.play.util.QueueUtil;
|
import com.cappielloantonio.play.util.QueueUtil;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
@ -27,9 +28,17 @@ public class AlbumArtistRepository {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void insertAll(List<AlbumArtistCross> crosses) {
|
public void insertAll(List<AlbumArtistCross> crosses) {
|
||||||
InsertAllThreadSafe insertAll = new InsertAllThreadSafe(albumArtistCrossDao, crosses);
|
try {
|
||||||
Thread thread = new Thread(insertAll);
|
final Thread delete = new Thread(new DeleteAllAlbumArtistCrossThreadSafe(albumArtistCrossDao));
|
||||||
thread.start();
|
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 {
|
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.SongArtistCrossDao;
|
||||||
import com.cappielloantonio.play.database.dao.SongGenreCrossDao;
|
import com.cappielloantonio.play.database.dao.SongGenreCrossDao;
|
||||||
import com.cappielloantonio.play.model.AlbumArtistCross;
|
import com.cappielloantonio.play.model.AlbumArtistCross;
|
||||||
|
import com.cappielloantonio.play.model.Song;
|
||||||
import com.cappielloantonio.play.model.SongArtistCross;
|
import com.cappielloantonio.play.model.SongArtistCross;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -22,9 +23,17 @@ public class SongArtistRepository {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void insertAll(List<SongArtistCross> crosses) {
|
public void insertAll(List<SongArtistCross> crosses) {
|
||||||
InsertAllThreadSafe insertAll = new InsertAllThreadSafe(songArtistCrossDao, crosses);
|
try {
|
||||||
Thread thread = new Thread(insertAll);
|
final Thread delete = new Thread(new DeleteAllSongArtistCrossThreadSafe(songArtistCrossDao));
|
||||||
thread.start();
|
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 {
|
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
|
* Sincronizzazzione dell'album con gli artisti che hanno collaborato per la sua produzione | isProduced = false
|
||||||
*/
|
*/
|
||||||
private void syncAlbumArtistCross(ArrayList<Album> albums) {
|
private void syncAlbumArtistCross(ArrayList<Album> albums) {
|
||||||
albumArtistRepository.deleteAll();
|
|
||||||
|
|
||||||
List<AlbumArtistCross> crosses = new ArrayList<>();
|
List<AlbumArtistCross> crosses = new ArrayList<>();
|
||||||
|
|
||||||
for(Album album: albums) {
|
for(Album album: albums) {
|
||||||
|
|
@ -298,8 +296,6 @@ public class SyncFragment extends Fragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void syncSongArtistCross(ArrayList<Song> songs) {
|
private void syncSongArtistCross(ArrayList<Song> songs) {
|
||||||
songArtistRepository.deleteAll();
|
|
||||||
|
|
||||||
List<SongArtistCross> crosses = new ArrayList<>();
|
List<SongArtistCross> crosses = new ArrayList<>();
|
||||||
|
|
||||||
for(Song song: songs) {
|
for(Song song: songs) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue