From 889b6e44c3cd189d9e7d83fb9b1e9afcb4c2c409 Mon Sep 17 00:00:00 2001 From: Stefan Niedermann Date: Mon, 5 Oct 2020 15:28:58 +0200 Subject: #831 Migrate from SQLiteOpenHelper to Room --- .../owncloud/notes/persistence/dao/NoteDao.java | 37 ++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'app/src/main/java/it/niedermann/owncloud/notes/persistence/dao/NoteDao.java') diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/dao/NoteDao.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/dao/NoteDao.java index 213fe9c7..580eadc1 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/dao/NoteDao.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/dao/NoteDao.java @@ -1,10 +1,22 @@ package it.niedermann.owncloud.notes.persistence.dao; +import android.database.Cursor; +import android.database.sqlite.SQLiteDatabase; + +import androidx.annotation.NonNull; +import androidx.annotation.WorkerThread; import androidx.room.Dao; import androidx.room.Insert; import androidx.room.Query; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + import it.niedermann.owncloud.notes.persistence.entity.NoteEntity; +import it.niedermann.owncloud.notes.shared.model.DBNote; import it.niedermann.owncloud.notes.shared.model.DBStatus; @Dao @@ -16,9 +28,34 @@ public interface NoteDao { @Query("UPDATE noteentity SET scrollY = :scrollY WHERE id = :id") void updateScrollY(long id, int scrollY); + @Query("SELECT * FROM noteentity WHERE id = :id AND accountId = :accountId AND status != :") + NoteEntity getNote(long accountId, long id); + @Insert long addNote(NoteEntity noteEntity); @Query("UPDATE noteentity SET status = :status WHERE id = :id") void updateStatus(long id, DBStatus status); + + /** + * Gets all the remoteIds of all not deleted notes of an account + * + * @param accountId get the remoteIds from all notes of this account + * @return {@link Set} remoteIds from all notes + */ + @Query("SELECT remoteId FROM noteentity WHERE accountId = :accountId AND status != \"LOCAL_DELETED\"") + Set getRemoteIds(long accountId); + + + /** + * Get a single Note by remote Id (aka. nextcloud file id) + * + * @param remoteId int - remote ID of the requested Note + * @return {@link DBNote#getId()} + */ + @Query("SELECT id FROM noteentity WHERE accountId = :accountId AND remoteId = :remoteId AND status != \"LOCAL_DELETED\"") + Long getLocalIdByRemoteId(long accountId, long remoteId); + + @Query("SELECT favorite, COUNT(*) FROM noteentity WHERE status != \"LOCAL_DELETED\" AND accountId = :accountId GROUP BY favorite ORDER BY favorite") + Map getFavoritesCount(long accountId); } -- cgit v1.2.3