+
+ @androidx.room.Transaction
+ @Query("SELECT * FROM transactions WHERE profile_id = :profileId")
+ public abstract List<TransactionWithAccounts> getAllWithAccountsSync(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 " +
+ "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 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);
+
+ @Query("DELETE FROM transaction_accounts WHERE EXISTS (SELECT 1 FROM transactions tr WHERE tr" +
+ ".id=transaction_accounts.transaction_id AND tr.profile_id=:profileId) AND generation " +
+ "<> :currentGeneration")
+ public abstract int purgeOldTransactionAccountsSync(long profileId, long currentGeneration);
+
+ @Query("DELETE FROM transactions WHERE profile_id = :profileId")
+ public abstract int deleteAllSync(long profileId);
+
+ @Query("SELECT * FROM transactions where profile_id = :profileId AND ledger_id = :ledgerId")
+ public abstract Transaction getByLedgerId(long profileId, long ledgerId);
+
+ @Query("UPDATE transactions SET generation = :newGeneration WHERE id = :transactionId")
+ public abstract int updateGeneration(long transactionId, long newGeneration);
+
+ @Query("UPDATE transaction_accounts SET generation = :newGeneration WHERE transaction_id = " +
+ ":transactionId")
+ public abstract int updateAccountsGeneration(long transactionId, long newGeneration);
+ @androidx.room.Transaction
+ public void updateGenerationWithAccounts(long transactionId, long newGeneration) {
+ updateGeneration(transactionId, newGeneration);
+ updateAccountsGeneration(transactionId, newGeneration);
+ }