+ 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;
+
+ try (Cursor cTr = db.rawQuery(
+ "SELECT year, month, day, description, comment from transactions WHERE profile=? " +
+ "AND id=?", new String[]{profile, String.valueOf(id)}))
+ {
+ if (cTr.moveToFirst()) {
+ date = new SimpleDate(cTr.getInt(0), cTr.getInt(1), cTr.getInt(2));
+ description = cTr.getString(3);
+ comment = cTr.getString(4);