]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/dao/TransactionDAO.java
fix ordering of transactions when loaded from database
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / dao / TransactionDAO.java
index 2c0995e1226cef8480babebff7ac8f3623008721..e347207cda9ed053b36cb1481d9c62ca2527884c 100644 (file)
@@ -103,11 +103,13 @@ public abstract class TransactionDAO extends BaseDAO<Transaction> {
     protected abstract TransactionGenerationContainer getGenerationPOJOSync(long profileId);
 
     @androidx.room.Transaction
-    @Query("SELECT * FROM transactions WHERE profile_id = :profileId")
+    @Query("SELECT * FROM transactions WHERE profile_id = :profileId ORDER BY year " +
+           " desc, month desc, day desc, ledger_id desc")
     public abstract List<TransactionWithAccounts> getAllWithAccountsSync(long profileId);
 
     @androidx.room.Transaction
-    @Query("SELECT * FROM transactions WHERE profile_id = :profileId")
+    @Query("SELECT * FROM transactions WHERE profile_id = :profileId ORDER BY year " +
+           " desc, month desc, day desc, ledger_id desc")
     public abstract LiveData<List<TransactionWithAccounts>> getAllWithAccounts(long profileId);
 
     @androidx.room.Transaction
@@ -161,6 +163,7 @@ public abstract class TransactionDAO extends BaseDAO<Transaction> {
             return 0;
         return result.generation;
     }
+    @androidx.room.Transaction
     public void storeTransactionsSync(List<TransactionWithAccounts> list, long profileId) {
         long generation = getGenerationSync(profileId) + 1;
 
@@ -179,7 +182,8 @@ public abstract class TransactionDAO extends BaseDAO<Transaction> {
         Logger.debug("Transaction",
                 String.format(Locale.ROOT, "Purged %d transaction accounts", removed));
     }
-    private void storeSync(TransactionWithAccounts rec) {
+    @androidx.room.Transaction
+    void storeSync(TransactionWithAccounts rec) {
         TransactionAccountDAO trAccDao = DB.get()
                                            .getTransactionAccountDAO();