Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Room warnings #578

Merged
merged 1 commit into from Mar 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions data/src/main/java/app/tivi/data/daos/EpisodesDao.kt
Expand Up @@ -18,6 +18,8 @@ package app.tivi.data.daos

import androidx.room.Dao
import androidx.room.Query
import androidx.room.RoomWarnings
import androidx.room.Transaction
import app.tivi.data.entities.Episode
import app.tivi.data.entities.Season
import app.tivi.data.resultentities.EpisodeWithSeason
Expand Down Expand Up @@ -46,6 +48,7 @@ abstract class EpisodesDao : EntityDao<Episode>() {
@Query("SELECT id from episodes WHERE trakt_id = :traktId")
abstract suspend fun episodeIdWithTraktId(traktId: Int): Long?

@Transaction
@Query("SELECT * from episodes WHERE id = :id")
abstract fun episodeWithIdObservable(id: Long): Flow<EpisodeWithSeason>

Expand All @@ -55,16 +58,22 @@ abstract class EpisodesDao : EntityDao<Episode>() {
" WHERE eps.id = :episodeId")
abstract suspend fun showIdForEpisodeId(episodeId: Long): Long

@Transaction
@Suppress(RoomWarnings.CURSOR_MISMATCH)
@Query(latestWatchedEpisodeForShowId)
abstract fun observeLatestWatchedEpisodeForShowId(showId: Long): Flow<EpisodeWithSeason?>

@Transaction
@Suppress(RoomWarnings.CURSOR_MISMATCH)
@Query(nextEpisodeForShowIdAfter)
abstract fun observeNextEpisodeForShowAfter(
showId: Long,
seasonNumber: Int,
episodeNumber: Int
): Flow<EpisodeWithSeason?>

@Transaction
@Suppress(RoomWarnings.CURSOR_MISMATCH)
@Query(nextAiredEpisodeForShowIdAfter)
abstract fun observeNextAiredEpisodeForShowAfter(
showId: Long,
Expand Down
2 changes: 2 additions & 0 deletions data/src/main/java/app/tivi/data/daos/FollowedShowsDao.kt
Expand Up @@ -64,6 +64,7 @@ abstract class FollowedShowsDao : EntryDao<FollowedShowEntry, FollowedShowEntryW
@Query(ENTRY_QUERY_ORDER_ADDED_FILTER)
internal abstract fun pagedListAddedFilter(filter: String): DataSource.Factory<Int, FollowedShowEntryWithShow>

@Transaction
@Query("""
SELECT myshows_entries.* FROM myshows_entries
INNER JOIN seasons AS s ON s.show_id = myshows_entries.show_id
Expand Down Expand Up @@ -92,6 +93,7 @@ abstract class FollowedShowsDao : EntryDao<FollowedShowEntry, FollowedShowEntryW
@Query("SELECT COUNT(*) FROM myshows_entries WHERE show_id = :showId")
abstract suspend fun entryCountWithShowId(showId: Long): Int

@Transaction
@Query("""
SELECT stats.* FROM FollowedShowsWatchStats as stats
INNER JOIN myshows_entries ON stats.id = myshows_entries.id
Expand Down
1 change: 1 addition & 0 deletions data/src/main/java/app/tivi/data/daos/RecommendedDao.kt
Expand Up @@ -26,6 +26,7 @@ import kotlinx.coroutines.flow.Flow

@Dao
abstract class RecommendedDao : PaginatedEntryDao<RecommendedShowEntry, RecommendedEntryWithShow>() {
@Transaction
@Query("SELECT * FROM recommended_entries WHERE page = :page ORDER BY id ASC")
abstract fun entriesForPage(page: Int): Flow<List<RecommendedShowEntry>>

Expand Down
2 changes: 2 additions & 0 deletions data/src/main/java/app/tivi/data/daos/ShowFtsDao.kt
Expand Up @@ -18,10 +18,12 @@ package app.tivi.data.daos

import androidx.room.Dao
import androidx.room.Query
import androidx.room.Transaction
import app.tivi.data.resultentities.ShowDetailed

@Dao
abstract class ShowFtsDao {
@Transaction
@Query("""
SELECT s.* FROM shows as s
INNER JOIN shows_fts AS fts ON s.id = fts.docid
Expand Down
3 changes: 3 additions & 0 deletions data/src/main/java/app/tivi/data/daos/TiviShowDao.kt
Expand Up @@ -18,6 +18,7 @@ package app.tivi.data.daos

import androidx.room.Dao
import androidx.room.Query
import androidx.room.Transaction
import app.tivi.data.entities.TiviShow
import app.tivi.data.repositories.shows.mergeShows
import app.tivi.data.resultentities.ShowDetailed
Expand All @@ -37,9 +38,11 @@ abstract class TiviShowDao : EntityDao<TiviShow>() {
@Query("SELECT * FROM shows WHERE id = :id")
abstract fun getShowWithIdFlow(id: Long): Flow<TiviShow>

@Transaction
@Query("SELECT * FROM shows WHERE id = :id")
abstract suspend fun getShowWithIdDetailed(id: Long): ShowDetailed?

@Transaction
@Query("SELECT * FROM shows WHERE id = :id")
abstract fun getShowDetailedWithIdFlow(id: Long): Flow<ShowDetailed>

Expand Down
4 changes: 4 additions & 0 deletions data/src/main/java/app/tivi/data/daos/TrendingDao.kt
Expand Up @@ -19,18 +19,22 @@ package app.tivi.data.daos
import androidx.paging.DataSource
import androidx.room.Dao
import androidx.room.Query
import androidx.room.Transaction
import app.tivi.data.entities.TrendingShowEntry
import app.tivi.data.resultentities.TrendingEntryWithShow
import kotlinx.coroutines.flow.Flow

@Dao
abstract class TrendingDao : PaginatedEntryDao<TrendingShowEntry, TrendingEntryWithShow>() {
@Transaction
@Query("SELECT * FROM trending_shows WHERE page = :page ORDER BY watchers DESC, id ASC")
abstract fun entriesObservable(page: Int): Flow<List<TrendingShowEntry>>

@Transaction
@Query("SELECT * FROM trending_shows ORDER BY page ASC, watchers DESC, id ASC LIMIT :count OFFSET :offset")
abstract fun entriesObservable(count: Int, offset: Int): Flow<List<TrendingEntryWithShow>>

@Transaction
@Query("SELECT * FROM trending_shows ORDER BY page ASC, watchers DESC, id ASC")
abstract fun entriesDataSource(): DataSource.Factory<Int, TrendingEntryWithShow>

Expand Down