]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/model/MobileLedgerProfile.java
more debug (disabled)
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / model / MobileLedgerProfile.java
index 59ae1958dd89c5e23e4cc1342fc19a2a4b914727..ec204d9a47272042ba3b15b5815fb0e9aba7eeaa 100644 (file)
@@ -25,6 +25,7 @@ import net.ktnx.mobileledger.utils.Globals;
 import net.ktnx.mobileledger.utils.MLDB;
 
 import java.util.ArrayList;
+import java.util.Date;
 import java.util.List;
 import java.util.UUID;
 
@@ -181,27 +182,24 @@ 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 = ?",
                 new Object[]{acc.getLevel(), uuid, acc.getName()});
-        db.execSQL("insert into accounts(profile, name, name_upper, parent_name, level) " +
-                   "select ?,?,?,?,? where (select changes() = 0)",
+        db.execSQL("insert into accounts(profile, name, name_upper, parent_name, level, keep) " +
+                   "select ?,?,?,?,?,1 where (select changes() = 0)",
                 new Object[]{uuid, acc.getName(), acc.getName().toUpperCase(), acc.getParentName(),
                              acc.getLevel()
                 });
+//        Log.d("accounts", String.format("Stored account '%s' in DB [%s]", acc.getName(), uuid));
     }
-    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()});
@@ -340,4 +338,10 @@ public final class MobileLedgerProfile {
     public void deleteNotPresentTransactions(SQLiteDatabase db) {
         db.execSQL("DELETE FROM transactions WHERE profile=? AND keep = 0", new String[]{uuid});
     }
+    public void setLastUpdateStamp() {
+        Log.d("db", "Updating transaction value stamp");
+        Date now = new Date();
+        setLongOption(MLDB.OPT_LAST_SCRAPE, now.getTime());
+        Data.lastUpdateDate.set(now);
+    }
 }