package it.niedermann.nextcloud.deck.persistence.sync.adapters.db.dao; import androidx.lifecycle.LiveData; import androidx.room.Dao; import androidx.room.Query; import androidx.room.RawQuery; import androidx.room.Transaction; import androidx.sqlite.db.SupportSQLiteQuery; import java.util.List; import it.niedermann.nextcloud.deck.model.Card; import it.niedermann.nextcloud.deck.model.full.FullCard; import it.niedermann.nextcloud.deck.model.full.FullCardWithProjects; @Dao public interface CardDao extends GenericDao { @Query("SELECT * FROM card WHERE stackId = :localStackId order by `order`, createdAt asc") LiveData> getCardsForStack(final long localStackId); @Query("SELECT * FROM card WHERE accountId = :accountId and id = :remoteId") LiveData getCardByRemoteId(final long accountId, final long remoteId); @Transaction @Query("SELECT * FROM card WHERE accountId = :accountId and id = :remoteId") FullCard getFullCardByRemoteIdDirectly(final long accountId, final long remoteId); @Query("SELECT * FROM card WHERE accountId = :accountId and localId = :localId") Card getCardByLocalIdDirectly(final long accountId, final long localId); @Transaction @Query("SELECT * FROM card WHERE accountId = :accountId and localId = :localId") FullCard getFullCardByLocalIdDirectly(final long accountId, final long localId); @Transaction // v not deleted! @Query("SELECT * FROM card WHERE accountId = :accountId AND archived = 0 AND stackId = :localStackId and status<>3 order by `order`, createdAt asc") LiveData> getFullCardsForStack(final long accountId, final long localStackId); @Transaction @RawQuery(observedEntities = Card.class) LiveData> getFilteredFullCardsForStack(SupportSQLiteQuery query); @Transaction @RawQuery(observedEntities = Card.class) List getFilteredFullCardsForStackDirectly(SupportSQLiteQuery query); @Transaction @Query("SELECT * FROM card WHERE accountId = :accountId AND stackId = :localStackId order by `order`, createdAt asc") List getFullCardsForStackDirectly(final long accountId, final long localStackId); @Transaction @Query("SELECT * FROM card WHERE accountId = :accountId and localId = :localCardId") LiveData getFullCardByLocalId(final long accountId, final long localCardId); @Transaction @Query("SELECT * FROM card WHERE accountId = :accountId and localId = :localCardId") LiveData getFullCardWithProjectsByLocalId(final long accountId, final long localCardId); @Transaction @Query("SELECT * FROM card WHERE accountId = :accountId and id = :remoteId") LiveData getFullCardByRemoteId(final long accountId, final long remoteId); @Query("SELECT * FROM card WHERE accountId = :accountId and id = :remoteId") Card getCardByRemoteIdDirectly(long accountId, long remoteId); @Transaction @Query("SELECT * FROM card WHERE accountId = :accountId and (status<>1 or id is null or lastModified <> lastModifiedLocal)") List getLocallyChangedCardsDirectly(long accountId); @Transaction @Query("SELECT * FROM card WHERE accountId = :accountId and stackId = :localStackId and (status<>1 or id is null or lastModified <> lastModifiedLocal)") List getLocallyChangedCardsByLocalStackIdDirectly(long accountId, long localStackId); @Query("SELECT * FROM card c WHERE accountId = :accountId and exists ( select 1 from DeckComment dc where dc.objectId = c.localId and dc.status<>1)") List getCardsWithLocallyChangedCommentsDirectly(Long accountId); @Query("SELECT * FROM card c WHERE stackId = :localStackId and exists ( select 1 from DeckComment dc where dc.objectId = c.localId and dc.status<>1)") List getCardsWithLocallyChangedCommentsForStackDirectly(Long localStackId); @Query("SELECT count(*) FROM card c WHERE accountId = :accountId and stackId = :localStackId and status <> 3") LiveData countCardsInStack(long accountId, long localStackId); @Query("SELECT coalesce(MAX(`order`), -1) FROM card c WHERE stackId = :localStackId and status <> 3") Integer getHighestOrderInStack(Long localStackId); @Query("SELECT c.stackId FROM card c WHERE localId = :localCardId") Long getLocalStackIdByLocalCardId(Long localCardId); }