import net.ktnx.mobileledger.db.TransactionAccount;
import net.ktnx.mobileledger.db.TransactionWithAccounts;
import net.ktnx.mobileledger.utils.Logger;
+import net.ktnx.mobileledger.utils.Misc;
import java.util.ArrayList;
import java.util.List;
@Query("SELECT * FROM transactions where profile_id = :profileId AND ledger_id = :ledgerId")
public abstract Transaction getByLedgerId(long profileId, long ledgerId);
+
+ @Query("UPDATE transactions SET generation = :newGeneration WHERE id = :transactionId")
+ public abstract int updateGeneration(long transactionId, long newGeneration);
+
+ @Query("UPDATE transaction_accounts SET generation = :newGeneration WHERE transaction_id = " +
+ ":transactionId")
+ public abstract int updateAccountsGeneration(long transactionId, long newGeneration);
+ @androidx.room.Transaction
+ public void updateGenerationWithAccounts(long transactionId, long newGeneration) {
+ updateGeneration(transactionId, newGeneration);
+ updateAccountsGeneration(transactionId, newGeneration);
+ }
public long getGenerationSync(long profileId) {
TransactionGenerationContainer result = getGenerationPOJOSync(profileId);
Transaction transaction = rec.transaction;
Transaction existing = getByLedgerId(transaction.getProfileId(), transaction.getLedgerId());
if (existing != null) {
+ if (Misc.equalStrings(transaction.getDataHash(), existing.getDataHash())) {
+ updateGenerationWithAccounts(existing.getId(), rec.transaction.getGeneration());
+ return;
+ }
+
existing.copyDataFrom(transaction);
updateSync(existing);
+
transaction = existing;
}
else