+ @Query("SELECT generation FROM transactions WHERE profile_id = :profileId LIMIT 1")
+ protected abstract TransactionGenerationContainer getGenerationPOJOSync(long profileId);
+
+ @androidx.room.Transaction
+ @Query("SELECT * FROM transactions WHERE profile_id = :profileId")
+ public abstract List<TransactionWithAccounts> getAllWithAccountsSync(long profileId);
+
+ @androidx.room.Transaction
+ @Query("SELECT distinct(tr.id), tr.ledger_id, tr.profile_id, tr.data_hash, tr.year, tr.month," +
+ " tr.day, tr.description, tr.comment, tr.generation FROM transactions tr JOIN " +
+ "transaction_accounts ta ON ta.transaction_id=tr.id WHERE ta.account_name LIKE " +
+ ":accountName||'%' AND ta.amount <> 0 AND tr.profile_id = :profileId ORDER BY tr.year " +
+ "desc, tr.month desc, tr.day desc, tr.ledger_id desc")
+ public abstract List<TransactionWithAccounts> getAllWithAccountsFilteredSync(long profileId,
+ String accountName);
+
+ public long getGenerationSync(long profileId) {
+ TransactionGenerationContainer result = getGenerationPOJOSync(profileId);
+
+ if (result == null)
+ return 0;
+ return result.generation;
+ }
+ @Query("DELETE FROM transactions WHERE profile_id = :profileId AND generation <> " +
+ ":currentGeneration")
+ public abstract void purgeOldTransactionsSync(long profileId, long currentGeneration);
+ static class TransactionGenerationContainer {
+ @ColumnInfo
+ long generation;
+ public TransactionGenerationContainer(long generation) {
+ this.generation = generation;
+ }
+ }
+