+ protected void fillDataHash() {
+ if (dataHash != null)
+ return;
+ try {
+ Digest sha = new Digest(DIGEST_TYPE);
+ StringBuilder data = new StringBuilder();
+ data.append(profile);
+ data.append(getId());
+ data.append('\0');
+ data.append(getDescription());
+ data.append('\0');
+ data.append(getComment());
+ data.append('\0');
+ data.append(Globals.formatLedgerDate(getDate()));
+ data.append('\0');
+ for (LedgerTransactionAccount item : accounts) {
+ data.append(item.getAccountName());
+ data.append('\0');
+ data.append(item.getCurrency());
+ data.append('\0');
+ data.append(item.getAmount());
+ data.append('\0');
+ data.append(item.getComment());
+ }
+ sha.update(data.toString()
+ .getBytes(StandardCharsets.UTF_8));
+ dataHash = sha.digestToHexString();
+ }
+ catch (NoSuchAlgorithmException e) {
+ throw new RuntimeException(
+ String.format("Unable to get instance of %s digest", DIGEST_TYPE), e);
+ }
+ }
+ public boolean existsInDb(SQLiteDatabase db) {
+ fillDataHash();
+ try (Cursor c = db.rawQuery("SELECT 1 from transactions where data_hash = ?",
+ new String[]{dataHash}))
+ {
+ boolean result = c.moveToFirst();
+// debug("db", String.format("Transaction %d (%s) %s", id, dataHash,
+// result ? "already present" : "not present"));
+ return result;
+ }
+ }
+ public void loadData(SQLiteDatabase db) {
+ if (dataLoaded)
+ return;