]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/dao/TransactionDAO.java
fully employ room for loading transactions off DB
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / dao / TransactionDAO.java
index 8f238183549bbc33b392540728ca4632d736cf89..2c0995e1226cef8480babebff7ac8f3623008721 100644 (file)
@@ -106,6 +106,10 @@ public abstract class TransactionDAO extends BaseDAO<Transaction> {
     @Query("SELECT * FROM transactions WHERE profile_id = :profileId")
     public abstract List<TransactionWithAccounts> getAllWithAccountsSync(long profileId);
 
+    @androidx.room.Transaction
+    @Query("SELECT * FROM transactions WHERE profile_id = :profileId")
+    public abstract LiveData<List<TransactionWithAccounts>> getAllWithAccounts(long profileId);
+
     @androidx.room.Transaction
     @Query("SELECT distinct(tr.id), tr.ledger_id, tr.profile_id, tr.data_hash, tr.year, tr.month," +
            " tr.day, tr.description, tr.comment, tr.generation FROM transactions tr JOIN " +
@@ -115,6 +119,15 @@ public abstract class TransactionDAO extends BaseDAO<Transaction> {
     public abstract List<TransactionWithAccounts> getAllWithAccountsFilteredSync(long profileId,
                                                                                  String accountName);
 
+    @androidx.room.Transaction
+    @Query("SELECT distinct(tr.id), tr.ledger_id, tr.profile_id, tr.data_hash, tr.year, tr.month," +
+           " tr.day, tr.description, tr.comment, tr.generation FROM transactions tr JOIN " +
+           "transaction_accounts ta ON ta.transaction_id=tr.id WHERE ta.account_name LIKE " +
+           ":accountName||'%' AND ta.amount <> 0 AND tr.profile_id = :profileId ORDER BY tr.year " +
+           "desc, tr.month desc, tr.day desc, tr.ledger_id desc")
+    public abstract LiveData<List<TransactionWithAccounts>> getAllWithAccountsFiltered(
+            long profileId, String accountName);
+
     @Query("DELETE FROM transactions WHERE profile_id = :profileId AND generation <> " +
            ":currentGeneration")
     public abstract int purgeOldTransactionsSync(long profileId, long currentGeneration);