Convert the abstract class DAOs to interfaces.
This commit is contained in:
parent
9a65f02d5b
commit
a3c4a10721
|
@ -14,26 +14,26 @@ import static org.schabi.newpipe.database.playlist.model.PlaylistEntity.PLAYLIST
|
||||||
import static org.schabi.newpipe.database.playlist.model.PlaylistEntity.PLAYLIST_TABLE;
|
import static org.schabi.newpipe.database.playlist.model.PlaylistEntity.PLAYLIST_TABLE;
|
||||||
|
|
||||||
@Dao
|
@Dao
|
||||||
public abstract class PlaylistDAO implements BasicDAO<PlaylistEntity> {
|
public interface PlaylistDAO extends BasicDAO<PlaylistEntity> {
|
||||||
@Override
|
@Override
|
||||||
@Query("SELECT * FROM " + PLAYLIST_TABLE)
|
@Query("SELECT * FROM " + PLAYLIST_TABLE)
|
||||||
public abstract Flowable<List<PlaylistEntity>> getAll();
|
Flowable<List<PlaylistEntity>> getAll();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Query("DELETE FROM " + PLAYLIST_TABLE)
|
@Query("DELETE FROM " + PLAYLIST_TABLE)
|
||||||
public abstract int deleteAll();
|
int deleteAll();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Flowable<List<PlaylistEntity>> listByService(final int serviceId) {
|
default Flowable<List<PlaylistEntity>> listByService(final int serviceId) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Query("SELECT * FROM " + PLAYLIST_TABLE + " WHERE " + PLAYLIST_ID + " = :playlistId")
|
@Query("SELECT * FROM " + PLAYLIST_TABLE + " WHERE " + PLAYLIST_ID + " = :playlistId")
|
||||||
public abstract Flowable<List<PlaylistEntity>> getPlaylist(long playlistId);
|
Flowable<List<PlaylistEntity>> getPlaylist(long playlistId);
|
||||||
|
|
||||||
@Query("DELETE FROM " + PLAYLIST_TABLE + " WHERE " + PLAYLIST_ID + " = :playlistId")
|
@Query("DELETE FROM " + PLAYLIST_TABLE + " WHERE " + PLAYLIST_ID + " = :playlistId")
|
||||||
public abstract int deletePlaylist(long playlistId);
|
int deletePlaylist(long playlistId);
|
||||||
|
|
||||||
@Query("SELECT COUNT(*) FROM " + PLAYLIST_TABLE)
|
@Query("SELECT COUNT(*) FROM " + PLAYLIST_TABLE)
|
||||||
public abstract Flowable<Long> getCount();
|
Flowable<Long> getCount();
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,31 +17,31 @@ import static org.schabi.newpipe.database.playlist.model.PlaylistRemoteEntity.RE
|
||||||
import static org.schabi.newpipe.database.playlist.model.PlaylistRemoteEntity.REMOTE_PLAYLIST_URL;
|
import static org.schabi.newpipe.database.playlist.model.PlaylistRemoteEntity.REMOTE_PLAYLIST_URL;
|
||||||
|
|
||||||
@Dao
|
@Dao
|
||||||
public abstract class PlaylistRemoteDAO implements BasicDAO<PlaylistRemoteEntity> {
|
public interface PlaylistRemoteDAO extends BasicDAO<PlaylistRemoteEntity> {
|
||||||
@Override
|
@Override
|
||||||
@Query("SELECT * FROM " + REMOTE_PLAYLIST_TABLE)
|
@Query("SELECT * FROM " + REMOTE_PLAYLIST_TABLE)
|
||||||
public abstract Flowable<List<PlaylistRemoteEntity>> getAll();
|
Flowable<List<PlaylistRemoteEntity>> getAll();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Query("DELETE FROM " + REMOTE_PLAYLIST_TABLE)
|
@Query("DELETE FROM " + REMOTE_PLAYLIST_TABLE)
|
||||||
public abstract int deleteAll();
|
int deleteAll();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Query("SELECT * FROM " + REMOTE_PLAYLIST_TABLE
|
@Query("SELECT * FROM " + REMOTE_PLAYLIST_TABLE
|
||||||
+ " WHERE " + REMOTE_PLAYLIST_SERVICE_ID + " = :serviceId")
|
+ " WHERE " + REMOTE_PLAYLIST_SERVICE_ID + " = :serviceId")
|
||||||
public abstract Flowable<List<PlaylistRemoteEntity>> listByService(int serviceId);
|
Flowable<List<PlaylistRemoteEntity>> listByService(int serviceId);
|
||||||
|
|
||||||
@Query("SELECT * FROM " + REMOTE_PLAYLIST_TABLE + " WHERE "
|
@Query("SELECT * FROM " + REMOTE_PLAYLIST_TABLE + " WHERE "
|
||||||
+ REMOTE_PLAYLIST_URL + " = :url AND " + REMOTE_PLAYLIST_SERVICE_ID + " = :serviceId")
|
+ REMOTE_PLAYLIST_URL + " = :url AND " + REMOTE_PLAYLIST_SERVICE_ID + " = :serviceId")
|
||||||
public abstract Flowable<List<PlaylistRemoteEntity>> getPlaylist(long serviceId, String url);
|
Flowable<List<PlaylistRemoteEntity>> getPlaylist(long serviceId, String url);
|
||||||
|
|
||||||
@Query("SELECT " + REMOTE_PLAYLIST_ID + " FROM " + REMOTE_PLAYLIST_TABLE
|
@Query("SELECT " + REMOTE_PLAYLIST_ID + " FROM " + REMOTE_PLAYLIST_TABLE
|
||||||
+ " WHERE " + REMOTE_PLAYLIST_URL + " = :url "
|
+ " WHERE " + REMOTE_PLAYLIST_URL + " = :url "
|
||||||
+ "AND " + REMOTE_PLAYLIST_SERVICE_ID + " = :serviceId")
|
+ "AND " + REMOTE_PLAYLIST_SERVICE_ID + " = :serviceId")
|
||||||
abstract Long getPlaylistIdInternal(long serviceId, String url);
|
Long getPlaylistIdInternal(long serviceId, String url);
|
||||||
|
|
||||||
@Transaction
|
@Transaction
|
||||||
public long upsert(final PlaylistRemoteEntity playlist) {
|
default long upsert(final PlaylistRemoteEntity playlist) {
|
||||||
final Long playlistId = getPlaylistIdInternal(playlist.getServiceId(), playlist.getUrl());
|
final Long playlistId = getPlaylistIdInternal(playlist.getServiceId(), playlist.getUrl());
|
||||||
|
|
||||||
if (playlistId == null) {
|
if (playlistId == null) {
|
||||||
|
@ -55,5 +55,5 @@ public abstract class PlaylistRemoteDAO implements BasicDAO<PlaylistRemoteEntity
|
||||||
|
|
||||||
@Query("DELETE FROM " + REMOTE_PLAYLIST_TABLE
|
@Query("DELETE FROM " + REMOTE_PLAYLIST_TABLE
|
||||||
+ " WHERE " + REMOTE_PLAYLIST_ID + " = :playlistId")
|
+ " WHERE " + REMOTE_PLAYLIST_ID + " = :playlistId")
|
||||||
public abstract int deletePlaylist(long playlistId);
|
int deletePlaylist(long playlistId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,28 +29,28 @@ import static org.schabi.newpipe.database.stream.model.StreamStateEntity.STREAM_
|
||||||
import static org.schabi.newpipe.database.stream.model.StreamStateEntity.STREAM_STATE_TABLE;
|
import static org.schabi.newpipe.database.stream.model.StreamStateEntity.STREAM_STATE_TABLE;
|
||||||
|
|
||||||
@Dao
|
@Dao
|
||||||
public abstract class PlaylistStreamDAO implements BasicDAO<PlaylistStreamEntity> {
|
public interface PlaylistStreamDAO extends BasicDAO<PlaylistStreamEntity> {
|
||||||
@Override
|
@Override
|
||||||
@Query("SELECT * FROM " + PLAYLIST_STREAM_JOIN_TABLE)
|
@Query("SELECT * FROM " + PLAYLIST_STREAM_JOIN_TABLE)
|
||||||
public abstract Flowable<List<PlaylistStreamEntity>> getAll();
|
Flowable<List<PlaylistStreamEntity>> getAll();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Query("DELETE FROM " + PLAYLIST_STREAM_JOIN_TABLE)
|
@Query("DELETE FROM " + PLAYLIST_STREAM_JOIN_TABLE)
|
||||||
public abstract int deleteAll();
|
int deleteAll();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Flowable<List<PlaylistStreamEntity>> listByService(final int serviceId) {
|
default Flowable<List<PlaylistStreamEntity>> listByService(final int serviceId) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Query("DELETE FROM " + PLAYLIST_STREAM_JOIN_TABLE
|
@Query("DELETE FROM " + PLAYLIST_STREAM_JOIN_TABLE
|
||||||
+ " WHERE " + JOIN_PLAYLIST_ID + " = :playlistId")
|
+ " WHERE " + JOIN_PLAYLIST_ID + " = :playlistId")
|
||||||
public abstract void deleteBatch(long playlistId);
|
void deleteBatch(long playlistId);
|
||||||
|
|
||||||
@Query("SELECT COALESCE(MAX(" + JOIN_INDEX + "), -1)"
|
@Query("SELECT COALESCE(MAX(" + JOIN_INDEX + "), -1)"
|
||||||
+ " FROM " + PLAYLIST_STREAM_JOIN_TABLE
|
+ " FROM " + PLAYLIST_STREAM_JOIN_TABLE
|
||||||
+ " WHERE " + JOIN_PLAYLIST_ID + " = :playlistId")
|
+ " WHERE " + JOIN_PLAYLIST_ID + " = :playlistId")
|
||||||
public abstract Flowable<Integer> getMaximumIndexOf(long playlistId);
|
Flowable<Integer> getMaximumIndexOf(long playlistId);
|
||||||
|
|
||||||
@Transaction
|
@Transaction
|
||||||
@Query("SELECT * FROM " + STREAM_TABLE + " INNER JOIN "
|
@Query("SELECT * FROM " + STREAM_TABLE + " INNER JOIN "
|
||||||
|
@ -69,7 +69,7 @@ public abstract class PlaylistStreamDAO implements BasicDAO<PlaylistStreamEntity
|
||||||
+ " ON " + STREAM_ID + " = " + JOIN_STREAM_ID_ALIAS
|
+ " ON " + STREAM_ID + " = " + JOIN_STREAM_ID_ALIAS
|
||||||
|
|
||||||
+ " ORDER BY " + JOIN_INDEX + " ASC")
|
+ " ORDER BY " + JOIN_INDEX + " ASC")
|
||||||
public abstract Flowable<List<PlaylistStreamEntry>> getOrderedStreamsOf(long playlistId);
|
Flowable<List<PlaylistStreamEntry>> getOrderedStreamsOf(long playlistId);
|
||||||
|
|
||||||
@Transaction
|
@Transaction
|
||||||
@Query("SELECT " + PLAYLIST_ID + ", " + PLAYLIST_NAME + ", " + PLAYLIST_THUMBNAIL_URL + ", "
|
@Query("SELECT " + PLAYLIST_ID + ", " + PLAYLIST_NAME + ", " + PLAYLIST_THUMBNAIL_URL + ", "
|
||||||
|
@ -80,5 +80,5 @@ public abstract class PlaylistStreamDAO implements BasicDAO<PlaylistStreamEntity
|
||||||
+ " ON " + PLAYLIST_ID + " = " + JOIN_PLAYLIST_ID
|
+ " ON " + PLAYLIST_ID + " = " + JOIN_PLAYLIST_ID
|
||||||
+ " GROUP BY " + JOIN_PLAYLIST_ID
|
+ " GROUP BY " + JOIN_PLAYLIST_ID
|
||||||
+ " ORDER BY " + PLAYLIST_NAME + " COLLATE NOCASE ASC")
|
+ " ORDER BY " + PLAYLIST_NAME + " COLLATE NOCASE ASC")
|
||||||
public abstract Flowable<List<PlaylistMetadataEntry>> getPlaylistMetadata();
|
Flowable<List<PlaylistMetadataEntry>> getPlaylistMetadata();
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,31 +17,31 @@ import static org.schabi.newpipe.database.stream.model.StreamStateEntity.JOIN_ST
|
||||||
import static org.schabi.newpipe.database.stream.model.StreamStateEntity.STREAM_STATE_TABLE;
|
import static org.schabi.newpipe.database.stream.model.StreamStateEntity.STREAM_STATE_TABLE;
|
||||||
|
|
||||||
@Dao
|
@Dao
|
||||||
public abstract class StreamStateDAO implements BasicDAO<StreamStateEntity> {
|
public interface StreamStateDAO extends BasicDAO<StreamStateEntity> {
|
||||||
@Override
|
@Override
|
||||||
@Query("SELECT * FROM " + STREAM_STATE_TABLE)
|
@Query("SELECT * FROM " + STREAM_STATE_TABLE)
|
||||||
public abstract Flowable<List<StreamStateEntity>> getAll();
|
Flowable<List<StreamStateEntity>> getAll();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Query("DELETE FROM " + STREAM_STATE_TABLE)
|
@Query("DELETE FROM " + STREAM_STATE_TABLE)
|
||||||
public abstract int deleteAll();
|
int deleteAll();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Flowable<List<StreamStateEntity>> listByService(final int serviceId) {
|
default Flowable<List<StreamStateEntity>> listByService(final int serviceId) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Query("SELECT * FROM " + STREAM_STATE_TABLE + " WHERE " + JOIN_STREAM_ID + " = :streamId")
|
@Query("SELECT * FROM " + STREAM_STATE_TABLE + " WHERE " + JOIN_STREAM_ID + " = :streamId")
|
||||||
public abstract Flowable<List<StreamStateEntity>> getState(long streamId);
|
Flowable<List<StreamStateEntity>> getState(long streamId);
|
||||||
|
|
||||||
@Query("DELETE FROM " + STREAM_STATE_TABLE + " WHERE " + JOIN_STREAM_ID + " = :streamId")
|
@Query("DELETE FROM " + STREAM_STATE_TABLE + " WHERE " + JOIN_STREAM_ID + " = :streamId")
|
||||||
public abstract int deleteState(long streamId);
|
int deleteState(long streamId);
|
||||||
|
|
||||||
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
||||||
abstract void silentInsertInternal(StreamStateEntity streamState);
|
void silentInsertInternal(StreamStateEntity streamState);
|
||||||
|
|
||||||
@Transaction
|
@Transaction
|
||||||
public long upsert(final StreamStateEntity stream) {
|
default long upsert(final StreamStateEntity stream) {
|
||||||
silentInsertInternal(stream);
|
silentInsertInternal(stream);
|
||||||
return update(stream);
|
return update(stream);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue