]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/dao/AccountDAO.java
restore account ordering by name
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / dao / AccountDAO.java
index 7bca44ced51ec35f0658b08fd0730a08b4eff105..429e1643465f99f9d2164d61a4fd29aef763de76 100644 (file)
@@ -59,16 +59,7 @@ public abstract class AccountDAO extends BaseDAO<Account> {
         final AccountValueDAO valueDAO = DB.get()
                                            .getAccountValueDAO();
         Account account = accountWithAmounts.account;
-        Account existingAccount = getByNameSync(account.getProfileId(), account.getName());
-        if (existingAccount != null) {
-            existingAccount.setGeneration(account.getGeneration());
-            account = existingAccount;
-            updateSync(account);
-        }
-        else {
-            long accountId = insertSync(account);
-            account.setId(accountId);
-        }
+        account.setId(insertSync(account));
         for (AccountValue value : accountWithAmounts.amounts) {
             value.setAccountId(account.getId());
             value.setGeneration(account.getGeneration());
@@ -84,11 +75,11 @@ public abstract class AccountDAO extends BaseDAO<Account> {
     @Delete
     public abstract void deleteSync(List<Account> items);
 
-    @Query("SELECT * FROM accounts WHERE profile_id=:profileId")
+    @Query("SELECT * FROM accounts WHERE profile_id=:profileId ORDER BY name")
     public abstract LiveData<List<Account>> getAll(long profileId);
 
     @Transaction
-    @Query("SELECT * FROM accounts WHERE profile_id = :profileId")
+    @Query("SELECT * FROM accounts WHERE profile_id = :profileId ORDER BY name")
     public abstract LiveData<List<AccountWithAmounts>> getAllWithAmounts(long profileId);
 
     @Query("SELECT * FROM accounts WHERE id=:id")