Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 8b3c36f7 authored by Arnau Mora's avatar Arnau Mora Committed by GitHub
Browse files

Use DB StringDefs also in DAOs and methods where they are used (#1252)



* Added annotations to daos

Signed-off-by: default avatarArnau Mora <arnyminerz@proton.me>

* Added missing annotations on methods

Signed-off-by: default avatarArnau Mora <arnyminerz@proton.me>

* Missing annotation

Signed-off-by: default avatarArnau Mora <arnyminerz@proton.me>

---------

Signed-off-by: default avatarArnau Mora <arnyminerz@proton.me>
parent ca2d57cf
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -30,13 +30,13 @@ interface CollectionDao {
    fun getByServiceAndHomeset(serviceId: Long, homeSetId: Long?): List<Collection>

    @Query("SELECT * FROM collection WHERE serviceId=:serviceId AND type=:type ORDER BY displayName COLLATE NOCASE, url COLLATE NOCASE")
    fun getByServiceAndType(serviceId: Long, type: String): List<Collection>
    fun getByServiceAndType(serviceId: Long, @CollectionType type: String): List<Collection>

    @Query("SELECT * FROM collection WHERE pushTopic=:topic AND sync")
    fun getSyncableByPushTopic(topic: String): Collection?

    @Query("SELECT COUNT(*) FROM collection WHERE serviceId=:serviceId AND type=:type")
    suspend fun anyOfType(serviceId: Long, type: String): Boolean
    suspend fun anyOfType(serviceId: Long, @CollectionType type: String): Boolean

    @Query("SELECT COUNT(*) FROM collection WHERE supportsWebPush AND pushTopic IS NOT NULL")
    suspend fun anyPushCapable(): Boolean
@@ -48,13 +48,13 @@ interface CollectionDao {
     */
    @Query("SELECT * FROM collection WHERE serviceId=:serviceId AND type=:type " +
            "AND (supportsVTODO OR supportsVEVENT OR supportsVJOURNAL OR (supportsVEVENT IS NULL AND supportsVTODO IS NULL AND supportsVJOURNAL IS NULL)) ORDER BY displayName COLLATE NOCASE, URL COLLATE NOCASE")
    fun pageByServiceAndType(serviceId: Long, type: String): PagingSource<Int, Collection>
    fun pageByServiceAndType(serviceId: Long, @CollectionType type: String): PagingSource<Int, Collection>

    @Query("SELECT * FROM collection WHERE serviceId=:serviceId AND sync")
    fun getByServiceAndSync(serviceId: Long): List<Collection>

    @Query("SELECT collection.* FROM collection, homeset WHERE collection.serviceId=:serviceId AND type=:type AND homeSetId=homeset.id AND homeset.personal ORDER BY collection.displayName COLLATE NOCASE, collection.url COLLATE NOCASE")
    fun pagePersonalByServiceAndType(serviceId: Long, type: String): PagingSource<Int, Collection>
    fun pagePersonalByServiceAndType(serviceId: Long, @CollectionType type: String): PagingSource<Int, Collection>

    @Query("SELECT * FROM collection WHERE serviceId=:serviceId AND url=:url")
    fun getByServiceAndUrl(serviceId: Long, url: String): Collection?
+1 −1
Original line number Diff line number Diff line
@@ -24,7 +24,7 @@ interface HomeSetDao {
    fun getByService(serviceId: Long): List<HomeSet>

    @Query("SELECT * FROM homeset WHERE serviceId=(SELECT id FROM service WHERE accountName=:accountName AND type=:serviceType) AND privBind ORDER BY displayName, url COLLATE NOCASE")
    fun getBindableByAccountAndServiceTypeFlow(accountName: String, serviceType: String): Flow<List<HomeSet>>
    fun getBindableByAccountAndServiceTypeFlow(accountName: String, @ServiceType serviceType: String): Flow<List<HomeSet>>

    @Query("SELECT * FROM homeset WHERE serviceId=:serviceId AND privBind")
    fun getBindableByServiceFlow(serviceId: Long): Flow<List<HomeSet>>
+2 −2
Original line number Diff line number Diff line
@@ -14,10 +14,10 @@ import kotlinx.coroutines.flow.Flow
interface ServiceDao {

    @Query("SELECT * FROM service WHERE accountName=:accountName AND type=:type")
    fun getByAccountAndType(accountName: String, type: String): Service?
    fun getByAccountAndType(accountName: String, @ServiceType type: String): Service?

    @Query("SELECT * FROM service WHERE accountName=:accountName AND type=:type")
    fun getByAccountAndTypeFlow(accountName: String, type: String): Flow<Service?>
    fun getByAccountAndTypeFlow(accountName: String, @ServiceType type: String): Flow<Service?>

    @Query("SELECT id FROM service WHERE accountName=:accountName")
    suspend fun getIdsByAccountAsync(accountName: String): List<Long>
+2 −1
Original line number Diff line number Diff line
@@ -13,6 +13,7 @@ import at.bitfire.davdroid.R
import at.bitfire.davdroid.db.Credentials
import at.bitfire.davdroid.db.HomeSet
import at.bitfire.davdroid.db.Service
import at.bitfire.davdroid.db.ServiceType
import at.bitfire.davdroid.resource.LocalAddressBookStore
import at.bitfire.davdroid.resource.LocalCalendarStore
import at.bitfire.davdroid.servicedetection.DavResourceFinder
@@ -247,7 +248,7 @@ class AccountRepository @Inject constructor(

    // helpers

    private fun insertService(accountName: String, type: String, info: DavResourceFinder.Configuration.ServiceInfo): Long {
    private fun insertService(accountName: String, @ServiceType type: String, info: DavResourceFinder.Configuration.ServiceInfo): Long {
        // insert service
        val service = Service(0, accountName, type, info.principal)
        val serviceId = serviceRepository.insertOrReplace(service)
+3 −2
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import at.bitfire.dav4jvm.property.webdav.ResourceType
import at.bitfire.davdroid.R
import at.bitfire.davdroid.db.AppDatabase
import at.bitfire.davdroid.db.Collection
import at.bitfire.davdroid.db.CollectionType
import at.bitfire.davdroid.db.HomeSet
import at.bitfire.davdroid.network.HttpClient
import at.bitfire.davdroid.servicedetection.RefreshCollectionsWorker
@@ -248,10 +249,10 @@ class DavCollectionRepository @Inject constructor(
        notifyOnChangeListeners()
    }

    fun pageByServiceAndType(serviceId: Long, type: String) =
    fun pageByServiceAndType(serviceId: Long, @CollectionType type: String) =
        dao.pageByServiceAndType(serviceId, type)

    fun pagePersonalByServiceAndType(serviceId: Long, type: String) =
    fun pagePersonalByServiceAndType(serviceId: Long, @CollectionType type: String) =
        dao.pagePersonalByServiceAndType(serviceId, type)

    /**
Loading