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());
@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")
" ELSE 9 END AS ordering " + "FROM accounts " +
"WHERE profile_id=:profileId AND name_upper LIKE '%%'||:term||'%%' " +
"ORDER BY ordering, name_upper, rowid ")
- public abstract LiveData<List<AccountNameContainer>> lookupInProfileByName(long profileId,
- @NonNull
- String term);
+ public abstract LiveData<List<AccountNameContainer>> lookupNamesInProfileByName(long profileId,
+ @NonNull
+ String term);
@Query("SELECT name, CASE WHEN name_upper LIKE :term||'%%' THEN 1 " +
" WHEN name_upper LIKE '%%:'||:term||'%%' THEN 2 " +
" ELSE 9 END AS ordering " + "FROM accounts " +
"WHERE profile_id=:profileId AND name_upper LIKE '%%'||:term||'%%' " +
"ORDER BY ordering, name_upper, rowid ")
- public abstract List<AccountNameContainer> lookupInProfileByNameSync(long profileId,
- @NonNull String term);
+ public abstract List<AccountNameContainer> lookupNamesInProfileByNameSync(long profileId,
+ @NonNull String term);
+
+ @Query("SELECT * FROM accounts " +
+ "WHERE profile_id=:profileId AND name_upper LIKE '%%'||:term||'%%' " +
+ "ORDER BY CASE WHEN name_upper LIKE :term||'%%' THEN 1 " +
+ " WHEN name_upper LIKE '%%:'||:term||'%%' THEN 2 " +
+ " WHEN name_upper LIKE '%% '||:term||'%%' THEN 3 " +
+ " ELSE 9 END, name_upper, rowid ")
+ public abstract List<AccountWithAmounts> lookupWithAmountsInProfileByNameSync(long profileId,
+ @NonNull
+ String term);
@Query("SELECT DISTINCT name, CASE WHEN name_upper LIKE :term||'%%' THEN 1 " +
" WHEN name_upper LIKE '%%:'||:term||'%%' THEN 2 " +
" WHEN name_upper LIKE '%% '||:term||'%%' THEN 3 " +
" ELSE 9 END AS ordering " + "FROM accounts " +
"WHERE name_upper LIKE '%%'||:term||'%%' " + "ORDER BY ordering, name_upper, rowid ")
- public abstract LiveData<List<AccountNameContainer>> lookupByName(@NonNull String term);
+ public abstract LiveData<List<AccountNameContainer>> lookupNamesByName(@NonNull String term);
@Query("SELECT DISTINCT name, CASE WHEN name_upper LIKE :term||'%%' THEN 1 " +
" WHEN name_upper LIKE '%%:'||:term||'%%' THEN 2 " +
" WHEN name_upper LIKE '%% '||:term||'%%' THEN 3 " +
" ELSE 9 END AS ordering " + "FROM accounts " +
"WHERE name_upper LIKE '%%'||:term||'%%' " + "ORDER BY ordering, name_upper, rowid ")
- public abstract List<AccountNameContainer> lookupByNameSync(@NonNull String term);
+ public abstract List<AccountNameContainer> lookupNamesByNameSync(@NonNull String term);
@Query("SELECT * FROM accounts WHERE profile_id = :profileId")
public abstract List<Account> allForProfileSync(long profileId);