diff options
author | Stefan Niedermann <info@niedermann.it> | 2021-01-03 13:16:18 +0300 |
---|---|---|
committer | Stefan Niedermann <info@niedermann.it> | 2021-01-03 13:16:18 +0300 |
commit | 7b68f925e71662cc4caf26998efadc6df44848e5 (patch) | |
tree | ab5f4be5ef547773a2cc71dfb0d2ae2df006933a /app/src/main/java/it/niedermann/owncloud/notes/persistence/dao/AccountDao.java | |
parent | 02e9b71a4cdbc7f026a4fa984aea2dbfafa14f70 (diff) |
Deduplicate Dao queries for LiveData and Non-LiveData
Diffstat (limited to 'app/src/main/java/it/niedermann/owncloud/notes/persistence/dao/AccountDao.java')
-rw-r--r-- | app/src/main/java/it/niedermann/owncloud/notes/persistence/dao/AccountDao.java | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/dao/AccountDao.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/dao/AccountDao.java index 1734e1a7..0fe6f768 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/dao/AccountDao.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/dao/AccountDao.java @@ -20,29 +20,34 @@ public interface AccountDao { @Delete int deleteAccount(Account localAccount); - @Query("SELECT * FROM Account WHERE ID = :accountId") - Account getAccount(long accountId); + String getAccountById = "SELECT * FROM Account WHERE ID = :accountId"; + String getAccountByName = "SELECT * FROM Account WHERE ACCOUNTNAME = :accountName"; + String getAccounts = "SELECT * FROM Account"; + String countAccounts = "SELECT COUNT(*) FROM Account"; - @Query("SELECT * FROM Account WHERE ID = :accountId") - LiveData<Account> getAccountLiveData(long accountId); + @Query(getAccountById) + LiveData<Account> getAccountById$(long accountId); - @Query("SELECT * FROM Account WHERE ACCOUNTNAME = :accountName") - Account getLocalAccountByAccountName(String accountName); + @Query(getAccountById) + Account getAccountById(long accountId); - @Query("SELECT * FROM Account WHERE ACCOUNTNAME = :accountName") - LiveData<Account> getLocalAccountByAccountNameLiveData(String accountName); + @Query(getAccountByName) + LiveData<Account> getAccountByName$(String accountName); - @Query("SELECT * FROM Account") - List<Account> getAccounts(); + @Query(getAccountByName) + Account getAccountByName(String accountName); + + @Query(getAccounts) + LiveData<List<Account>> getAccounts$(); - @Query("SELECT * FROM Account") - LiveData<List<Account>> getAccountsLiveData(); + @Query(getAccounts) + List<Account> getAccounts(); - @Query("SELECT COUNT(*) FROM Account") - Integer getAccountsCount(); + @Query(countAccounts) + LiveData<Integer> countAccounts$(); - @Query("SELECT COUNT(*) FROM Account") - LiveData<Integer> getAccountsCountLiveData(); + @Query(countAccounts) + Integer countAccounts(); @Query("UPDATE Account SET COLOR = :color, TEXTCOLOR = :textColor WHERE id = :id") void updateBrand(long id, @ColorInt Integer color, @ColorInt Integer textColor); |