if the dataHash field of the transaction that needs storage matches one
from the database (retrieved by profile id and ledger id), then simply
update the generation of the transaction in the database (and its
accounts)
since this is the common case (refreshing transaction list -- most of
the transactions are expected to be unchanged) this saves big time
import net.ktnx.mobileledger.db.TransactionAccount;
import net.ktnx.mobileledger.db.TransactionWithAccounts;
import net.ktnx.mobileledger.utils.Logger;
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;
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("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);
public long getGenerationSync(long profileId) {
TransactionGenerationContainer result = getGenerationPOJOSync(profileId);
Transaction transaction = rec.transaction;
Transaction existing = getByLedgerId(transaction.getProfileId(), transaction.getLedgerId());
if (existing != null) {
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);
existing.copyDataFrom(transaction);
updateSync(existing);
transaction = existing;
}
else
transaction = existing;
}
else