X-Git-Url: https://git.ktnx.net/?p=mobile-ledger.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fasync%2FRetrieveTransactionsTask.java;h=69b43fa6169cccd12826d483496959d79cf7bf24;hp=de459ece7a4e6ef9bf615ba064a4bfb4c22fba4d;hb=131b3a80243191d4cebd2df70e8836d7dbebaaa8;hpb=f8ccb6a9def9403cf24ae1d7f90c80d2ed759da9
diff --git a/app/src/main/java/net/ktnx/mobileledger/async/RetrieveTransactionsTask.java b/app/src/main/java/net/ktnx/mobileledger/async/RetrieveTransactionsTask.java
index de459ece..69b43fa6 100644
--- a/app/src/main/java/net/ktnx/mobileledger/async/RetrieveTransactionsTask.java
+++ b/app/src/main/java/net/ktnx/mobileledger/async/RetrieveTransactionsTask.java
@@ -124,7 +124,7 @@ public class RetrieveTransactionsTask
default:
throw new HTTPException(http.getResponseCode(), http.getResponseMessage());
}
- try (SQLiteDatabase db = MLDB.getWritableDatabase()) {
+ try (SQLiteDatabase db = MLDB.getDatabase()) {
try (InputStream resp = http.getInputStream()) {
if (http.getResponseCode() != 200)
throw new IOException(String.format("HTTP error %d", http.getResponseCode()));
@@ -159,7 +159,13 @@ public class RetrieveTransactionsTask
if (line.equals("
General Journal
")) {
state = ParserState.EXPECTING_TRANSACTION;
L("â expecting transaction");
+ // commit the current transaction and start a new one
+ // the account list in the UI should reflect the (committed)
+ // state of the database
+ db.setTransactionSuccessful();
+ db.endTransaction();
Data.accounts.set(accountList);
+ db.beginTransaction();
continue;
}
m = reAccountName.matcher(line);
@@ -383,54 +389,53 @@ public class RetrieveTransactionsTask
throw new HTTPException(http.getResponseCode(), http.getResponseMessage());
}
publishProgress(progress);
- try (SQLiteDatabase db = MLDB.getWritableDatabase()) {
- try (InputStream resp = http.getInputStream()) {
- if (http.getResponseCode() != 200)
- throw new IOException(String.format("HTTP error %d", http.getResponseCode()));
+ SQLiteDatabase db = MLDB.getDatabase();
+ try (InputStream resp = http.getInputStream()) {
+ if (http.getResponseCode() != 200)
+ throw new IOException(String.format("HTTP error %d", http.getResponseCode()));
- db.beginTransaction();
- try {
- profile.markAccountsAsNotPresent(db);
+ db.beginTransaction();
+ try {
+ profile.markAccountsAsNotPresent(db);
- AccountListParser parser = new AccountListParser(resp);
- ArrayList accountList = new ArrayList<>();
+ AccountListParser parser = new AccountListParser(resp);
+ ArrayList accountList = new ArrayList<>();
- LedgerAccount prevAccount = null;
+ LedgerAccount prevAccount = null;
- while (true) {
- throwIfCancelled();
- ParsedLedgerAccount parsedAccount = parser.nextAccount();
- if (parsedAccount == null) break;
+ while (true) {
+ throwIfCancelled();
+ ParsedLedgerAccount parsedAccount = parser.nextAccount();
+ if (parsedAccount == null) break;
- LedgerAccount acc = profile.tryLoadAccount(db, parsedAccount.getAname());
- if (acc == null) acc = new LedgerAccount(parsedAccount.getAname());
- else acc.removeAmounts();
+ LedgerAccount acc = profile.tryLoadAccount(db, parsedAccount.getAname());
+ if (acc == null) acc = new LedgerAccount(parsedAccount.getAname());
+ else acc.removeAmounts();
- profile.storeAccount(db, acc);
- for (ParsedBalance b : parsedAccount.getAebalance()) {
- profile.storeAccountValue(db, acc.getName(), b.getAcommodity(),
- b.getAquantity().asFloat());
- }
-
- if (acc.isVisible(accountList)) accountList.add(acc);
+ profile.storeAccount(db, acc);
+ for (ParsedBalance b : parsedAccount.getAebalance()) {
+ profile.storeAccountValue(db, acc.getName(), b.getAcommodity(),
+ b.getAquantity().asFloat());
+ }
- if (prevAccount != null) {
- prevAccount.setHasSubAccounts(
- acc.getName().startsWith(prevAccount.getName() + ":"));
- }
+ if (acc.isVisible(accountList)) accountList.add(acc);
- prevAccount = acc;
+ if (prevAccount != null) {
+ prevAccount.setHasSubAccounts(
+ acc.getName().startsWith(prevAccount.getName() + ":"));
}
- throwIfCancelled();
- profile.deleteNotPresentAccounts(db);
- throwIfCancelled();
- db.setTransactionSuccessful();
- Data.accounts.set(accountList);
- }
- finally {
- db.endTransaction();
+ prevAccount = acc;
}
+ throwIfCancelled();
+
+ profile.deleteNotPresentAccounts(db);
+ throwIfCancelled();
+ db.setTransactionSuccessful();
+ Data.accounts.set(accountList);
+ }
+ finally {
+ db.endTransaction();
}
}
@@ -452,7 +457,7 @@ public class RetrieveTransactionsTask
default:
throw new HTTPException(http.getResponseCode(), http.getResponseMessage());
}
- try (SQLiteDatabase db = MLDB.getWritableDatabase()) {
+ try (SQLiteDatabase db = MLDB.getDatabase()) {
try (InputStream resp = http.getInputStream()) {
if (http.getResponseCode() != 200)
throw new IOException(String.format("HTTP error %d", http.getResponseCode()));