2 * Copyright © 2021 Damyan Ivanov.
3 * This file is part of MoLe.
4 * MoLe is free software: you can distribute it and/or modify it
5 * under the term of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your opinion), any later version.
9 * MoLe is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License terms for details.
14 * You should have received a copy of the GNU General Public License
15 * along with MoLe. If not, see <https://www.gnu.org/licenses/>.
18 package net.ktnx.mobileledger.dao;
20 import androidx.annotation.NonNull;
21 import androidx.lifecycle.LiveData;
22 import androidx.room.Dao;
23 import androidx.room.Delete;
24 import androidx.room.Insert;
25 import androidx.room.Query;
26 import androidx.room.RoomWarnings;
27 import androidx.room.Update;
29 import net.ktnx.mobileledger.db.Account;
31 import java.util.List;
34 public abstract class AccountDAO extends BaseDAO<Account> {
36 public abstract void insertSync(Account item);
39 public abstract void updateSync(Account item);
42 public abstract void deleteSync(Account item);
44 @Query("SELECT * FROM accounts")
45 public abstract LiveData<List<Account>> getAll();
47 @Query("SELECT * FROM accounts WHERE profile = :profileUUID AND name = :accountName")
48 public abstract LiveData<Account> getByName(@NonNull String profileUUID,
49 @NonNull String accountName);
53 // @Query("SELECT * FROM patterns")
54 // List<PatternWithAccounts> getPatternsWithAccounts();
56 @Query("SELECT *, CASE WHEN name_upper LIKE :term||'%%' THEN 1 " +
57 " WHEN name_upper LIKE '%%:'||:term||'%%' THEN 2 " +
58 " WHEN name_upper LIKE '%% '||:term||'%%' THEN 3 " +
59 " ELSE 9 END AS ordering " + "FROM accounts " +
60 "WHERE profile=:profileUUID AND name_upper LIKE '%%'||:term||'%%' " +
61 "ORDER BY ordering, name_upper, rowid ")
62 @SuppressWarnings(RoomWarnings.CURSOR_MISMATCH)
63 public abstract LiveData<List<Account>> lookupInProfileByName(@NonNull String profileUUID,
64 @NonNull String term);
66 @Query("SELECT *, CASE WHEN name_upper LIKE :term||'%%' THEN 1 " +
67 " WHEN name_upper LIKE '%%:'||:term||'%%' THEN 2 " +
68 " WHEN name_upper LIKE '%% '||:term||'%%' THEN 3 " +
69 " ELSE 9 END AS ordering " + "FROM accounts " +
70 "WHERE profile=:profileUUID AND name_upper LIKE '%%'||:term||'%%' " +
71 "ORDER BY ordering, name_upper, rowid ")
72 @SuppressWarnings(RoomWarnings.CURSOR_MISMATCH)
73 public abstract List<Account> lookupInProfileByNameSync(@NonNull String profileUUID,
74 @NonNull String term);
76 @Query("SELECT *, CASE WHEN name_upper LIKE :term||'%%' THEN 1 " +
77 " WHEN name_upper LIKE '%%:'||:term||'%%' THEN 2 " +
78 " WHEN name_upper LIKE '%% '||:term||'%%' THEN 3 " +
79 " ELSE 9 END AS ordering " + "FROM accounts " +
80 "WHERE name_upper LIKE '%%'||:term||'%%' " + "ORDER BY ordering, name_upper, rowid ")
81 @SuppressWarnings(RoomWarnings.CURSOR_MISMATCH)
82 public abstract LiveData<List<Account>> lookupByName(@NonNull String term);
84 @Query("SELECT *, CASE WHEN name_upper LIKE :term||'%%' THEN 1 " +
85 " WHEN name_upper LIKE '%%:'||:term||'%%' THEN 2 " +
86 " WHEN name_upper LIKE '%% '||:term||'%%' THEN 3 " +
87 " ELSE 9 END AS ordering " + "FROM accounts " +
88 "WHERE name_upper LIKE '%%'||:term||'%%' " + "ORDER BY ordering, name_upper, rowid ")
89 @SuppressWarnings(RoomWarnings.CURSOR_MISMATCH)
90 public abstract List<Account> lookupByNameSync(@NonNull String term);