Tighten access on some dao methods

pull/1043/head
Alex Baker 4 years ago
parent f6dd3a63e6
commit 205295a59a

@ -40,7 +40,7 @@ abstract class TaskDao(private val database: Database) {
}
@Query("SELECT * FROM tasks WHERE completed = 0 AND deleted = 0 AND (hideUntil > :now OR dueDate > :now)")
abstract suspend fun needsRefresh(now: Long = DateUtilities.now()): List<Task>
internal abstract suspend fun needsRefresh(now: Long = DateUtilities.now()): List<Task>
suspend fun fetchBlocking(id: Long) = runBlocking {
fetch(id)
@ -66,9 +66,6 @@ abstract class TaskDao(private val database: Database) {
@Query("SELECT * FROM tasks WHERE completed = 0 AND deleted = 0")
abstract suspend fun getActiveTasks(): List<Task>
@Query("SELECT * FROM tasks WHERE hideUntil < (strftime('%s','now')*1000)")
abstract suspend fun getVisibleTasks(): List<Task>
@Query("SELECT * FROM tasks WHERE remoteId IN (:remoteIds) "
+ "AND recurrence IS NOT NULL AND LENGTH(recurrence) > 0")
abstract suspend fun getRecurringTasks(remoteIds: List<String>): List<Task>
@ -171,7 +168,7 @@ SELECT EXISTS(SELECT 1 FROM tasks WHERE parent > 0 AND deleted = 0) AS hasSubtas
}
@Query("UPDATE tasks SET modified = :now WHERE _id in (:ids)")
abstract suspend fun touchInternal(ids: List<Long>, now: Long = currentTimeMillis())
internal abstract suspend fun touchInternal(ids: List<Long>, now: Long = currentTimeMillis())
suspend fun setParent(parent: Long, tasks: List<Long>) =
tasks.eachChunk { setParentInternal(parent, it) }
@ -214,7 +211,7 @@ SELECT EXISTS(SELECT 1 FROM tasks WHERE parent > 0 AND deleted = 0) AS hasSubtas
}
@Query("UPDATE tasks SET collapsed = :collapsed WHERE _id IN (:ids)")
abstract suspend fun collapse(ids: List<Long>, collapsed: Boolean)
internal abstract suspend fun collapse(ids: List<Long>, collapsed: Boolean)
// --- save
// TODO: get rid of this super-hack

@ -13,7 +13,6 @@ import kotlinx.coroutines.runBlocking
import org.tasks.data.SubtaskInfo
import org.tasks.data.TaskContainer
import org.tasks.preferences.Preferences
import org.tasks.time.DateTimeUtils.currentTimeMillis
import javax.inject.Inject
@Deprecated("use coroutines")
@ -22,10 +21,6 @@ class TaskDaoBlocking @Inject constructor(private val dao: TaskDao) {
dao.needsRefresh()
}
fun needsRefresh(now: Long): List<Task> = runBlocking {
dao.needsRefresh(now)
}
fun fetchBlocking(id: Long) = runBlocking {
dao.fetchBlocking(id)
}
@ -38,10 +33,6 @@ class TaskDaoBlocking @Inject constructor(private val dao: TaskDao) {
dao.fetch(ids)
}
internal fun fetchInternal(ids: List<Long>): List<Task> = runBlocking {
dao.fetchInternal(ids)
}
fun activeTimers(): Int = runBlocking {
dao.activeTimers()
}
@ -58,10 +49,6 @@ class TaskDaoBlocking @Inject constructor(private val dao: TaskDao) {
dao.getActiveTasks()
}
fun getVisibleTasks(): List<Task> = runBlocking {
dao.getVisibleTasks()
}
fun getRecurringTasks(remoteIds: List<String>): List<Task> = runBlocking {
dao.getRecurringTasks(remoteIds)
}
@ -142,18 +129,10 @@ class TaskDaoBlocking @Inject constructor(private val dao: TaskDao) {
dao.touch(ids)
}
fun touchInternal(ids: List<Long>, now: Long = currentTimeMillis()) = runBlocking {
dao.touchInternal(ids, now)
}
fun setParent(parent: Long, tasks: List<Long>) = runBlocking {
dao.setParent(parent, tasks)
}
internal fun setParentInternal(parent: Long, children: List<Long>) = runBlocking {
dao.setParentInternal(parent, children)
}
fun fetchChildren(id: Long): List<Task> = runBlocking {
dao.fetchChildren(id)
}
@ -174,10 +153,6 @@ class TaskDaoBlocking @Inject constructor(private val dao: TaskDao) {
dao.setCollapsed(preferences, filter, collapsed)
}
fun collapse(ids: List<Long>, collapsed: Boolean) = runBlocking {
dao.collapse(ids, collapsed)
}
fun save(task: Task) = runBlocking {
dao.save(task)
}

@ -48,7 +48,7 @@ abstract class CaldavDao {
}
@Insert
abstract suspend fun insertInternal(caldavCalendar: CaldavCalendar): Long
internal abstract suspend fun insertInternal(caldavCalendar: CaldavCalendar): Long
@Update
abstract suspend fun update(caldavCalendar: CaldavCalendar)
@ -153,7 +153,7 @@ abstract class CaldavDao {
objects.chunkedMap { getTasksInternal(calendar, it) }
@Query("SELECT cd_task FROM caldav_tasks WHERE cd_calendar = :calendar AND cd_object IN (:objects)")
abstract suspend fun getTasksInternal(calendar: String, objects: List<String>): List<Long>
internal abstract suspend fun getTasksInternal(calendar: String, objects: List<String>): List<Long>
@Query("SELECT * FROM caldav_lists WHERE cdl_account = :account AND cdl_url NOT IN (:urls)")
abstract suspend fun findDeletedCalendars(account: String, urls: List<String>): List<CaldavCalendar>

@ -2,7 +2,6 @@ package org.tasks.data
import android.content.Context
import androidx.lifecycle.LiveData
import com.todoroo.andlib.utility.DateUtilities.now
import com.todoroo.astrid.data.Task
import kotlinx.coroutines.runBlocking
import org.tasks.filters.CaldavFilters
@ -51,10 +50,6 @@ class CaldavDaoBlocking @Inject constructor(private val dao: CaldavDao) {
dao.insert(caldavCalendar)
}
fun insertInternal(caldavCalendar: CaldavCalendar): Long = runBlocking {
dao.insertInternal(caldavCalendar)
}
fun update(caldavCalendar: CaldavCalendar) = runBlocking {
dao.update(caldavCalendar)
}
@ -163,10 +158,6 @@ class CaldavDaoBlocking @Inject constructor(private val dao: CaldavDao) {
dao.getTasks(calendar, objects)
}
fun getTasksInternal(calendar: String, objects: List<String>): List<Long> = runBlocking {
dao.getTasksInternal(calendar, objects)
}
fun findDeletedCalendars(account: String, urls: List<String>): List<CaldavCalendar> = runBlocking {
dao.findDeletedCalendars(account, urls)
}
@ -207,14 +198,6 @@ class CaldavDaoBlocking @Inject constructor(private val dao: CaldavDao) {
dao.shiftDown(calendar, parent, from, to)
}
internal fun touchInternal(ids: List<Long>, modificationTime: Long = now()) = runBlocking {
dao.touchInternal(ids, modificationTime)
}
internal fun getTasksToShift(calendar: String, parent: Long, from: Long, to: Long?): List<CaldavTaskContainer> = runBlocking {
dao.getTasksToShift(calendar, parent, from, to)
}
fun resetOrders() = runBlocking {
dao.resetOrders()
}

@ -11,22 +11,22 @@ import java.util.*
@Dao
abstract class DeletionDao {
@Query("DELETE FROM caldav_tasks WHERE cd_task IN(:ids)")
abstract suspend fun deleteCaldavTasks(ids: List<Long>)
internal abstract suspend fun deleteCaldavTasks(ids: List<Long>)
@Query("DELETE FROM google_tasks WHERE gt_task IN(:ids)")
abstract suspend fun deleteGoogleTasks(ids: List<Long>)
internal abstract suspend fun deleteGoogleTasks(ids: List<Long>)
@Query("DELETE FROM tags WHERE task IN(:ids)")
abstract suspend fun deleteTags(ids: List<Long>)
@Query("DELETE FROM geofences WHERE task IN(:ids)")
abstract suspend fun deleteGeofences(ids: List<Long>)
internal abstract suspend fun deleteGeofences(ids: List<Long>)
@Query("DELETE FROM alarms WHERE task IN(:ids)")
abstract suspend fun deleteAlarms(ids: List<Long>)
internal abstract suspend fun deleteAlarms(ids: List<Long>)
@Query("DELETE FROM tasks WHERE _id IN(:ids)")
abstract suspend fun deleteTasks(ids: List<Long>)
internal abstract suspend fun deleteTasks(ids: List<Long>)
@Transaction
open suspend fun delete(ids: List<Long>) {
@ -43,17 +43,17 @@ abstract class DeletionDao {
@Query("UPDATE tasks "
+ "SET modified = (strftime('%s','now')*1000), deleted = (strftime('%s','now')*1000)"
+ "WHERE _id IN(:ids)")
abstract suspend fun markDeletedInternal(ids: List<Long>)
internal abstract suspend fun markDeletedInternal(ids: List<Long>)
suspend fun markDeleted(ids: Iterable<Long>) {
ids.eachChunk(this::markDeletedInternal)
}
@Query("SELECT gt_task FROM google_tasks WHERE gt_deleted = 0 AND gt_list_id = :listId")
abstract suspend fun getActiveGoogleTasks(listId: String): List<Long>
internal abstract suspend fun getActiveGoogleTasks(listId: String): List<Long>
@Delete
abstract suspend fun deleteGoogleTaskList(googleTaskList: GoogleTaskList)
internal abstract suspend fun deleteGoogleTaskList(googleTaskList: GoogleTaskList)
@Transaction
open suspend fun delete(googleTaskList: GoogleTaskList): List<Long> {
@ -64,7 +64,7 @@ abstract class DeletionDao {
}
@Delete
abstract suspend fun deleteGoogleTaskAccount(googleTaskAccount: GoogleTaskAccount)
internal abstract suspend fun deleteGoogleTaskAccount(googleTaskAccount: GoogleTaskAccount)
@Query("SELECT * FROM google_task_lists WHERE gtl_account = :account ORDER BY gtl_title ASC")
abstract suspend fun getLists(account: String): List<GoogleTaskList>
@ -80,10 +80,10 @@ abstract class DeletionDao {
}
@Query("SELECT cd_task FROM caldav_tasks WHERE cd_calendar = :calendar AND cd_deleted = 0")
abstract suspend fun getActiveCaldavTasks(calendar: String): List<Long>
internal abstract suspend fun getActiveCaldavTasks(calendar: String): List<Long>
@Delete
abstract suspend fun deleteCaldavCalendar(caldavCalendar: CaldavCalendar)
internal abstract suspend fun deleteCaldavCalendar(caldavCalendar: CaldavCalendar)
@Transaction
open suspend fun delete(caldavCalendar: CaldavCalendar): List<Long> {
@ -97,7 +97,7 @@ abstract class DeletionDao {
abstract suspend fun getCalendars(account: String): List<CaldavCalendar>
@Delete
abstract suspend fun deleteCaldavAccount(caldavAccount: CaldavAccount)
internal abstract suspend fun deleteCaldavAccount(caldavAccount: CaldavAccount)
@Query("DELETE FROM tasks WHERE _id IN (SELECT _id FROM tasks INNER JOIN caldav_tasks ON _id = cd_task INNER JOIN caldav_lists ON cdl_uuid = cd_calendar WHERE cdl_account = '$LOCAL' AND deleted > 0)")
abstract suspend fun purgeDeleted()

@ -5,58 +5,22 @@ import javax.inject.Inject
@Deprecated("use coroutines")
class DeletionDaoBlocking @Inject constructor(private val dao: DeletionDao) {
fun deleteCaldavTasks(ids: List<Long>) = runBlocking {
dao.deleteCaldavTasks(ids)
}
fun deleteGoogleTasks(ids: List<Long>) = runBlocking {
dao.deleteGoogleTasks(ids)
}
fun deleteTags(ids: List<Long>) = runBlocking {
dao.deleteTags(ids)
}
fun deleteGeofences(ids: List<Long>) = runBlocking {
dao.deleteGeofences(ids)
}
fun deleteAlarms(ids: List<Long>) = runBlocking {
dao.deleteAlarms(ids)
}
fun deleteTasks(ids: List<Long>) = runBlocking {
dao.deleteTasks(ids)
}
fun delete(ids: List<Long>) = runBlocking {
dao.delete(ids)
}
fun markDeletedInternal(ids: List<Long>) = runBlocking {
dao.markDeletedInternal(ids)
}
fun markDeleted(ids: Iterable<Long>) = runBlocking {
dao.markDeleted(ids)
}
fun getActiveGoogleTasks(listId: String): List<Long> = runBlocking {
dao.getActiveGoogleTasks(listId)
}
fun deleteGoogleTaskList(googleTaskList: GoogleTaskList) = runBlocking {
dao.deleteGoogleTaskList(googleTaskList)
}
fun delete(googleTaskList: GoogleTaskList): List<Long> = runBlocking {
dao.delete(googleTaskList)
}
fun deleteGoogleTaskAccount(googleTaskAccount: GoogleTaskAccount) = runBlocking {
dao.deleteGoogleTaskAccount(googleTaskAccount)
}
fun getLists(account: String): List<GoogleTaskList> = runBlocking {
dao.getLists(account)
}
@ -65,14 +29,6 @@ class DeletionDaoBlocking @Inject constructor(private val dao: DeletionDao) {
dao.delete(googleTaskAccount)
}
fun getActiveCaldavTasks(calendar: String): List<Long> = runBlocking {
dao.getActiveCaldavTasks(calendar)
}
fun deleteCaldavCalendar(caldavCalendar: CaldavCalendar) = runBlocking {
dao.deleteCaldavCalendar(caldavCalendar)
}
fun delete(caldavCalendar: CaldavCalendar): List<Long> = runBlocking {
dao.delete(caldavCalendar)
}
@ -81,10 +37,6 @@ class DeletionDaoBlocking @Inject constructor(private val dao: DeletionDao) {
dao.getCalendars(account)
}
fun deleteCaldavAccount(caldavAccount: CaldavAccount) = runBlocking {
dao.deleteCaldavAccount(caldavAccount)
}
fun purgeDeleted() = runBlocking {
dao.purgeDeleted()
}

@ -24,16 +24,16 @@ abstract class GoogleTaskDao {
}
@Query("UPDATE google_tasks SET gt_order = gt_order + 1 WHERE gt_list_id = :listId AND gt_parent = :parent AND gt_order >= :position")
abstract suspend fun shiftDown(listId: String, parent: Long, position: Long)
internal abstract suspend fun shiftDown(listId: String, parent: Long, position: Long)
@Query("UPDATE google_tasks SET gt_order = gt_order - 1 WHERE gt_list_id = :listId AND gt_parent = :parent AND gt_order > :from AND gt_order <= :to")
abstract suspend fun shiftUp(listId: String, parent: Long, from: Long, to: Long)
internal abstract suspend fun shiftUp(listId: String, parent: Long, from: Long, to: Long)
@Query("UPDATE google_tasks SET gt_order = gt_order + 1 WHERE gt_list_id = :listId AND gt_parent = :parent AND gt_order < :from AND gt_order >= :to")
abstract suspend fun shiftDown(listId: String, parent: Long, from: Long, to: Long)
internal abstract suspend fun shiftDown(listId: String, parent: Long, from: Long, to: Long)
@Query("UPDATE google_tasks SET gt_order = gt_order - 1 WHERE gt_list_id = :listId AND gt_parent = :parent AND gt_order >= :position")
abstract suspend fun shiftUp(listId: String, parent: Long, position: Long)
internal abstract suspend fun shiftUp(listId: String, parent: Long, position: Long)
@Transaction
open suspend fun move(task: SubsetGoogleTask, newParent: Long, newPosition: Long) {
@ -115,7 +115,7 @@ abstract class GoogleTaskDao {
@SuppressWarnings(RoomWarnings.CURSOR_MISMATCH)
@Query("SELECT google_tasks.*, gt_remote_order AS primary_sort, NULL AS secondary_sort FROM google_tasks JOIN tasks ON tasks._id = gt_task WHERE gt_parent = 0 AND gt_list_id = :listId AND tasks.deleted = 0 UNION SELECT c.*, p.gt_remote_order AS primary_sort, c.gt_remote_order AS secondary_sort FROM google_tasks AS c LEFT JOIN google_tasks AS p ON c.gt_parent = p.gt_task JOIN tasks ON tasks._id = c.gt_task WHERE c.gt_parent > 0 AND c.gt_list_id = :listId AND tasks.deleted = 0 ORDER BY primary_sort ASC, secondary_sort ASC")
abstract suspend fun getByRemoteOrder(listId: String): List<GoogleTask>
internal abstract suspend fun getByRemoteOrder(listId: String): List<GoogleTask>
@Query("UPDATE google_tasks"
+ " SET gt_parent = IFNULL(("

@ -19,22 +19,6 @@ class GoogleTaskDaoBlocking @Inject constructor(private val dao: GoogleTaskDao)
dao.insertAndShift(task, top)
}
fun shiftDown(listId: String, parent: Long, position: Long) = runBlocking {
dao.shiftDown(listId, parent, position)
}
fun shiftUp(listId: String, parent: Long, from: Long, to: Long) = runBlocking {
dao.shiftUp(listId, parent, from, to)
}
fun shiftDown(listId: String, parent: Long, from: Long, to: Long) = runBlocking {
dao.shiftDown(listId, parent, from, to)
}
fun shiftUp(listId: String, parent: Long, position: Long) = runBlocking {
dao.shiftUp(listId, parent, position)
}
fun move(task: SubsetGoogleTask, newParent: Long, newPosition: Long) = runBlocking {
dao.move(task, newParent, newPosition)
}
@ -111,10 +95,6 @@ class GoogleTaskDaoBlocking @Inject constructor(private val dao: GoogleTaskDao)
dao.getByLocalOrder(listId)
}
fun getByRemoteOrder(listId: String): List<GoogleTask> = runBlocking {
dao.getByRemoteOrder(listId)
}
fun updateParents() = runBlocking {
dao.updateParents()
}

@ -51,13 +51,13 @@ abstract class TagDataDao {
abstract suspend fun tagDataOrderedByName(): List<TagData>
@Delete
abstract suspend fun deleteTagData(tagData: TagData)
internal abstract suspend fun deleteTagData(tagData: TagData)
@Query("DELETE FROM tags WHERE tag_uid = :tagUid")
abstract suspend fun deleteTags(tagUid: String)
@Query("SELECT * FROM tags WHERE task IN (:tasks) AND tag_uid NOT IN (:tagsToKeep)")
abstract suspend fun tagsToDelete(tasks: List<Long>, tagsToKeep: List<String>): List<Tag>
internal abstract suspend fun tagsToDelete(tasks: List<Long>, tagsToKeep: List<String>): List<Tag>
suspend fun getTagSelections(tasks: List<Long>): Pair<Set<String>, Set<String>> {
val allTags = getAllTags(tasks)
@ -83,7 +83,7 @@ abstract class TagDataDao {
+ " LEFT JOIN tags ON tags.task = tasks._id"
+ " WHERE tasks._id IN (:tasks)"
+ " GROUP BY tasks._id")
abstract suspend fun getAllTags(tasks: List<Long>): List<String>
internal abstract suspend fun getAllTags(tasks: List<Long>): List<String>
@Transaction
open suspend fun applyTags(

@ -42,26 +42,14 @@ class TagDataDaoBlocking @Inject constructor(private val dao: TagDataDao) {
dao.tagDataOrderedByName()
}
fun deleteTagData(tagData: TagData) = runBlocking {
dao.deleteTagData(tagData)
}
fun deleteTags(tagUid: String) = runBlocking {
dao.deleteTags(tagUid)
}
fun tagsToDelete(tasks: List<Long>, tagsToKeep: List<String>): List<Tag> = runBlocking {
dao.tagsToDelete(tasks, tagsToKeep)
}
fun getTagSelections(tasks: List<Long>): Pair<Set<String>, Set<String>> = runBlocking {
dao.getTagSelections(tasks)
}
fun getAllTags(tasks: List<Long>): List<String> = runBlocking {
dao.getAllTags(tasks)
}
fun applyTags(tasks: List<Task>, partiallySelected: List<TagData>, selected: List<TagData>): List<Long> = runBlocking {
dao.applyTags(tasks, partiallySelected, selected)
}

Loading…
Cancel
Save