+ sha.update(data.toString().getBytes(Charset.forName("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;
+
+ try (Cursor cTr = db
+ .rawQuery("SELECT date, description from transactions WHERE profile=? AND id=?",
+ new String[]{profile, String.valueOf(id)}))
+ {
+ if (cTr.moveToFirst()) {
+ String dateString = cTr.getString(0);
+ try {
+ date = Globals.parseLedgerDate(dateString);
+ }
+ catch (ParseException e) {
+ e.printStackTrace();
+ throw new RuntimeException(
+ String.format("Error parsing date '%s' from " + "transacion %d",
+ dateString, id));
+ }
+ description = cTr.getString(1);