]> git.ktnx.net Git - mobile-ledger.git/commitdiff
methods for deleting all DB tables
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Sun, 12 Sep 2021 11:30:09 +0000 (14:30 +0300)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Sun, 12 Sep 2021 11:30:09 +0000 (14:30 +0300)
app/src/main/java/net/ktnx/mobileledger/dao/AccountDAO.java
app/src/main/java/net/ktnx/mobileledger/dao/AccountValueDAO.java
app/src/main/java/net/ktnx/mobileledger/dao/CurrencyDAO.java
app/src/main/java/net/ktnx/mobileledger/dao/OptionDAO.java
app/src/main/java/net/ktnx/mobileledger/dao/ProfileDAO.java
app/src/main/java/net/ktnx/mobileledger/dao/TemplateAccountDAO.java
app/src/main/java/net/ktnx/mobileledger/dao/TemplateHeaderDAO.java
app/src/main/java/net/ktnx/mobileledger/dao/TransactionAccountDAO.java
app/src/main/java/net/ktnx/mobileledger/dao/TransactionDAO.java
app/src/main/java/net/ktnx/mobileledger/db/DB.java

index 677fa81e0080631e9dcb730b32add5ca0056b7ab..0c581787a30a2fac55c605674904eebdd7441995 100644 (file)
@@ -75,6 +75,9 @@ public abstract class AccountDAO extends BaseDAO<Account> {
     @Delete
     public abstract void deleteSync(List<Account> items);
 
+    @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);
 
index 54a42c12ded9943dc5764344efbe6a1f26bec45c..8a7e5fb7970420ff3f3867fac3332c31bba3ab09 100644 (file)
@@ -41,6 +41,9 @@ public abstract class AccountValueDAO extends BaseDAO<AccountValue> {
     @Delete
     public abstract void deleteSync(AccountValue item);
 
+    @Query("DELETE FROM account_values")
+    public abstract void deleteAllSync();
+
     @Query("SELECT * FROM account_values WHERE account_id=:accountId")
     public abstract LiveData<List<AccountValue>> getAll(long accountId);
 
index 46e86358d7ffc2d2d5ab718e7b1cd209b026ca7e..1505a8fe4e6c6026d167a5f6b33ef5b524d16a81 100644 (file)
@@ -40,6 +40,9 @@ public abstract class CurrencyDAO extends BaseDAO<Currency> {
     @Delete
     public abstract void deleteSync(Currency item);
 
+    @Query("DELETE FROM currencies")
+    public abstract void deleteAllSync();
+
     @Query("SELECT * FROM currencies")
     public abstract LiveData<List<Currency>> getAll();
 
index 5540b233c27ea2110ab53c285e26b3590f04ef3f..41d6464b4936c85e96d6fc3a8a875510825a29c8 100644 (file)
@@ -43,6 +43,9 @@ public abstract class OptionDAO extends BaseDAO<Option> {
     @Delete
     public abstract void deleteSync(List<Option> items);
 
+    @Query("DELETE from options")
+    public abstract void deleteAllSync();
+
     @Query("SELECT * FROM options WHERE profile_id = :profileId AND name = :name")
     public abstract LiveData<Option> load(long profileId, String name);
 
index 3c8fb4c373516c060c43fab91436c216676bd926..c7a2e5d77a930ca4b8191d302d67d1a3c3d23eba 100644 (file)
@@ -55,6 +55,9 @@ public abstract class ProfileDAO extends BaseDAO<Profile> {
     @Delete
     public abstract void deleteSync(Profile item);
 
+    @Query("DELETE FROM profiles")
+    public abstract void deleteAllSync();
+
     @Query("select * from profiles where id = :profileId")
     public abstract Profile getByIdSync(long profileId);
 
index 44b1b201ede77c94aa1bc5dd71cd53e458a8151e..c2be8c7ff23ce097a937351671572e77b9e650d4 100644 (file)
@@ -40,6 +40,9 @@ public interface TemplateAccountDAO {
     @Delete
     void deleteSync(TemplateAccount item);
 
+    @Query("DELETE FROM template_accounts")
+    void deleteAllSync();
+
     @Query("SELECT * FROM template_accounts WHERE template_id=:template_id")
     LiveData<List<TemplateAccount>> getTemplateAccounts(Long template_id);
 
index ed2473b2ec65ac01af50ade9af357d7bb420d551..24e751c8149400fd26d3f933a36db90f93f3f73f 100644 (file)
@@ -62,6 +62,9 @@ public abstract class TemplateHeaderDAO {
         });
     }
 
+    @Query("DELETE FROM templates")
+    public abstract void deleteAllSync();
+
     @Query("SELECT * FROM templates ORDER BY is_fallback, UPPER(name)")
     public abstract LiveData<List<TemplateHeader>> getTemplates();
 
index c63ed223c1cf051c2800cd146661ce373e9866c2..1b6f27d9be8bb83e051be57c635cd4343e3b5fc3 100644 (file)
@@ -43,6 +43,9 @@ public abstract class TransactionAccountDAO extends BaseDAO<TransactionAccount>
     @Delete
     public abstract void deleteSync(List<TransactionAccount> items);
 
+    @Query("DELETE FROM transaction_accounts")
+    public abstract void deleteAllSync();
+
     @Query("SELECT * FROM transaction_accounts WHERE id = :id")
     public abstract LiveData<TransactionAccount> getById(long id);
 
index fca54eda13e0211e2f753160e861603f4136b1b3..001976d3b1ee08393c2ac48d6fbc5d634566a403 100644 (file)
@@ -66,6 +66,9 @@ public abstract class TransactionDAO extends BaseDAO<Transaction> {
     @Delete
     public abstract void deleteSync(List<Transaction> items);
 
+    @Query("DELETE FROM transactions")
+    public abstract void deleteAllSync();
+
     @Query("SELECT * FROM transactions WHERE id = :id")
     public abstract LiveData<Transaction> getById(long id);
 
index 97c16dbbad3917d1d8630ca704777ac33aceac98..482628888b1b021c9b78d53eb159ab974c479d2e 100644 (file)
@@ -244,4 +244,17 @@ abstract public class DB extends RoomDatabase {
     public abstract OptionDAO getOptionDAO();
 
     public abstract ProfileDAO getProfileDAO();
+
+    @androidx.room.Transaction
+    public void deleteAllSync() {
+        getTransactionAccountDAO().deleteAllSync();
+        getTransactionDAO().deleteAllSync();
+        getAccountValueDAO().deleteAllSync();
+        getAccountDAO().deleteAllSync();
+        getTemplateAccountDAO().deleteAllSync();
+        getTemplateDAO().deleteAllSync();
+        getCurrencyDAO().deleteAllSync();
+        getOptionDAO().deleteAllSync();
+        getProfileDAO().deleteAllSync();
+    }
 }