Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/stefan-niedermann/nextcloud-notes.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Niedermann <info@niedermann.it>2020-10-05 16:28:58 +0300
committerStefan Niedermann <info@niedermann.it>2020-10-05 16:28:58 +0300
commit889b6e44c3cd189d9e7d83fb9b1e9afcb4c2c409 (patch)
treeffc0d355741d65fe6021f5128813f4904150a474 /app/src/main/java/it/niedermann/owncloud/notes/persistence/dao/NoteDao.java
parentb159118faf1875bcaa02ef73e5289e794b8c8fbe (diff)
#831 Migrate from SQLiteOpenHelper to Room
Diffstat (limited to 'app/src/main/java/it/niedermann/owncloud/notes/persistence/dao/NoteDao.java')
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/persistence/dao/NoteDao.java37
1 files changed, 37 insertions, 0 deletions
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<String>} remoteIds from all notes
+ */
+ @Query("SELECT remoteId FROM noteentity WHERE accountId = :accountId AND status != \"LOCAL_DELETED\"")
+ Set<String> 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<String, Integer> getFavoritesCount(long accountId);
}