+ @androidx.room.Transaction
+ @Query("SELECT * from transactions WHERE description = :description ORDER BY year desc, month" +
+ " desc, day desc LIMIT 1")
+ public abstract TransactionWithAccounts getFirstByDescriptionSync(@NonNull String description);
+
+ @androidx.room.Transaction
+ @Query("SELECT * from transactions tr JOIN transaction_accounts t_a ON t_a.transaction_id = " +
+ "tr.id WHERE tr.description = :description AND t_a.account_name LIKE " +
+ "'%'||:accountTerm||'%' ORDER BY year desc, month desc, day desc LIMIT 1")
+ public abstract TransactionWithAccounts getFirstByDescriptionHavingAccountSync(
+ @NonNull String description, @NonNull String accountTerm);
+
+ @Query("SELECT * from transactions WHERE profile_id = :profileId")
+ public abstract List<Transaction> allForProfileSync(long profileId);
+
+ @Query("SELECT generation FROM transactions WHERE profile_id = :profileId LIMIT 1")
+ protected abstract TransactionGenerationContainer getGenerationPOJOSync(long profileId);
+ 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;
+ }
+ }
+