]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/dao/AccountDAO.java
methods for deleting all DB tables
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / dao / AccountDAO.java
index f37b940b1df9e9377325374e277f5ba96107c3cf..0c581787a30a2fac55c605674904eebdd7441995 100644 (file)
@@ -75,11 +75,14 @@ public abstract class AccountDAO extends BaseDAO<Account> {
     @Delete
     public abstract void deleteSync(List<Account> items);
 
-    @Query("SELECT * FROM accounts WHERE profile_id=:profileId")
+    @Query("DELETE FROM accounts")
+    public abstract void deleteAllSync();
+
+    @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")
@@ -106,9 +109,9 @@ public abstract class AccountDAO extends BaseDAO<Account> {
            "               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 " +
@@ -116,22 +119,32 @@ public abstract class AccountDAO extends BaseDAO<Account> {
            "               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);
+
+    @Transaction
+    @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);