2018-02-06 06:32:23 +01:00
|
|
|
package org.schabi.newpipe.database.playlist.dao;
|
|
|
|
|
2019-10-04 14:59:08 +02:00
|
|
|
import androidx.room.Dao;
|
|
|
|
import androidx.room.Query;
|
|
|
|
import androidx.room.Transaction;
|
2018-02-06 06:32:23 +01:00
|
|
|
|
|
|
|
import org.schabi.newpipe.database.BasicDAO;
|
|
|
|
import org.schabi.newpipe.database.playlist.model.PlaylistRemoteEntity;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
2020-10-31 21:55:45 +01:00
|
|
|
import io.reactivex.rxjava3.core.Flowable;
|
2018-02-06 06:32:23 +01:00
|
|
|
|
|
|
|
import static org.schabi.newpipe.database.playlist.model.PlaylistRemoteEntity.REMOTE_PLAYLIST_ID;
|
|
|
|
import static org.schabi.newpipe.database.playlist.model.PlaylistRemoteEntity.REMOTE_PLAYLIST_SERVICE_ID;
|
|
|
|
import static org.schabi.newpipe.database.playlist.model.PlaylistRemoteEntity.REMOTE_PLAYLIST_TABLE;
|
|
|
|
import static org.schabi.newpipe.database.playlist.model.PlaylistRemoteEntity.REMOTE_PLAYLIST_URL;
|
|
|
|
|
|
|
|
@Dao
|
|
|
|
public abstract class PlaylistRemoteDAO implements BasicDAO<PlaylistRemoteEntity> {
|
|
|
|
@Override
|
|
|
|
@Query("SELECT * FROM " + REMOTE_PLAYLIST_TABLE)
|
|
|
|
public abstract Flowable<List<PlaylistRemoteEntity>> getAll();
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Query("DELETE FROM " + REMOTE_PLAYLIST_TABLE)
|
|
|
|
public abstract int deleteAll();
|
|
|
|
|
|
|
|
@Override
|
2020-03-31 19:20:15 +02:00
|
|
|
@Query("SELECT * FROM " + REMOTE_PLAYLIST_TABLE
|
|
|
|
+ " WHERE " + REMOTE_PLAYLIST_SERVICE_ID + " = :serviceId")
|
2018-02-06 06:32:23 +01:00
|
|
|
public abstract Flowable<List<PlaylistRemoteEntity>> listByService(int serviceId);
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
@Query("SELECT * FROM " + REMOTE_PLAYLIST_TABLE + " WHERE "
|
|
|
|
+ REMOTE_PLAYLIST_URL + " = :url AND " + REMOTE_PLAYLIST_SERVICE_ID + " = :serviceId")
|
2018-02-06 06:32:23 +01:00
|
|
|
public abstract Flowable<List<PlaylistRemoteEntity>> getPlaylist(long serviceId, String url);
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
@Query("SELECT " + REMOTE_PLAYLIST_ID + " FROM " + REMOTE_PLAYLIST_TABLE
|
|
|
|
+ " WHERE " + REMOTE_PLAYLIST_URL + " = :url "
|
|
|
|
+ "AND " + REMOTE_PLAYLIST_SERVICE_ID + " = :serviceId")
|
2018-02-06 06:32:23 +01:00
|
|
|
abstract Long getPlaylistIdInternal(long serviceId, String url);
|
|
|
|
|
|
|
|
@Transaction
|
2020-03-31 19:20:15 +02:00
|
|
|
public long upsert(final PlaylistRemoteEntity playlist) {
|
2018-02-06 06:32:23 +01:00
|
|
|
final Long playlistId = getPlaylistIdInternal(playlist.getServiceId(), playlist.getUrl());
|
|
|
|
|
|
|
|
if (playlistId == null) {
|
|
|
|
return insert(playlist);
|
|
|
|
} else {
|
|
|
|
playlist.setUid(playlistId);
|
|
|
|
update(playlist);
|
|
|
|
return playlistId;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
@Query("DELETE FROM " + REMOTE_PLAYLIST_TABLE
|
|
|
|
+ " WHERE " + REMOTE_PLAYLIST_ID + " = :playlistId")
|
|
|
|
public abstract int deletePlaylist(long playlistId);
|
2018-02-06 06:32:23 +01:00
|
|
|
}
|