]> git.ktnx.net Git - mobile-ledger.git/commitdiff
Profile/storeAccount[Value],storeTransaction: get the db as an argument
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Thu, 7 Mar 2019 04:57:53 +0000 (06:57 +0200)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Thu, 7 Mar 2019 04:57:53 +0000 (06:57 +0200)
the calling code uses transactions, so it would be nice to use them

app/src/main/java/net/ktnx/mobileledger/async/RetrieveTransactionsTask.java
app/src/main/java/net/ktnx/mobileledger/model/MobileLedgerProfile.java

index dcc91b2f27ff2a7cb2aa5433afee4970741522df..acd1475d1e66eddf89cdbf0c34436a7ca2e149dc 100644 (file)
@@ -166,7 +166,7 @@ public class RetrieveTransactionsTask
                                     lastAccount = profile.loadAccount(acct_name);
                                     if (lastAccount == null) {
                                         lastAccount = new LedgerAccount(acct_name);
-                                        profile.storeAccount(lastAccount);
+                                        profile.storeAccount(db, lastAccount);
                                     }
 
                                     // make sure the parent account(s) are present,
@@ -188,7 +188,7 @@ public class RetrieveTransactionsTask
                                                 accountList.add(acc);
                                             L(String.format("gap-filling with %s", aName));
                                             accountNames.put(aName, null);
-                                            profile.storeAccount(acc);
+                                            profile.storeAccount(db, acc);
                                         }
                                     }
 
@@ -213,7 +213,7 @@ public class RetrieveTransactionsTask
                                     if (currency == null) currency = "";
                                     value = value.replace(',', '.');
                                     L("curr=" + currency + ", value=" + value);
-                                    profile.storeAccountValue(lastAccount.getName(), currency,
+                                    profile.storeAccountValue(db, lastAccount.getName(), currency,
                                             Float.valueOf(value));
                                     lastAccount.addAmount(Float.parseFloat(value), currency);
                                 }
@@ -291,7 +291,7 @@ public class RetrieveTransactionsTask
                                         }
                                     }
                                     else {
-                                        profile.storeTransaction(transaction);
+                                        profile.storeTransaction(db, transaction);
                                         matchedTransactionsCount = 0;
                                         progress.setTotal(maxTransactionId);
                                     }
@@ -380,9 +380,9 @@ public class RetrieveTransactionsTask
                         if (parsedAccount == null) break;
 
                         LedgerAccount acc = new LedgerAccount(parsedAccount.getAname());
-                        profile.storeAccount(acc);
+                        profile.storeAccount(db, acc);
                         for (ParsedBalance b : parsedAccount.getAebalance()) {
-                            profile.storeAccountValue(acc.getName(), b.getAcommodity(),
+                            profile.storeAccountValue(db, acc.getName(), b.getAcommodity(),
                                     b.getAquantity().asFloat());
                         }
 
@@ -445,7 +445,7 @@ public class RetrieveTransactionsTask
                             }
                         }
                         else {
-                            profile.storeTransaction(transaction);
+                            profile.storeTransaction(db, transaction);
                             matchedTransactionsCount = 0;
                             progress.setTotal(maxTransactionId);
                         }
index ae877c3384c4ae992efa77f6b2d44b5b12285a2f..168941f87fb4ed39b165d91f96edbd711d7de133 100644 (file)
@@ -182,9 +182,7 @@ public final class MobileLedgerProfile {
             db.endTransaction();
         }
     }
-    public void storeAccount(LedgerAccount acc) {
-        SQLiteDatabase db = MLDB.getWritableDatabase();
-
+    public void storeAccount(SQLiteDatabase db, LedgerAccount acc) {
         // replace into is a bad idea because it would reset hidden to its default value
         // we like the default, but for new accounts only
         db.execSQL("update accounts set level = ?, keep = 1 where profile=? and name = ?",
@@ -195,14 +193,12 @@ public final class MobileLedgerProfile {
                              acc.getLevel()
                 });
     }
-    public void storeAccountValue(String name, String currency, Float amount) {
-        SQLiteDatabase db = MLDB.getWritableDatabase();
+    public void storeAccountValue(SQLiteDatabase db, String name, String currency, Float amount) {
         db.execSQL("replace into account_values(profile, account, " +
                    "currency, value, keep) values(?, ?, ?, ?, 1);",
                 new Object[]{uuid, name, currency, amount});
     }
-    public void storeTransaction(LedgerTransaction tr) {
-        SQLiteDatabase db = MLDB.getWritableDatabase();
+    public void storeTransaction(SQLiteDatabase db, LedgerTransaction tr) {
         tr.fillDataHash();
         db.execSQL("DELETE from transactions WHERE profile=? and id=?",
                 new Object[]{uuid, tr.getId()});