+ public abstract List<AccountNameContainer> lookupNamesByNameSync(@NonNull String term);
+
+ @Query("SELECT * FROM accounts WHERE profile_id = :profileId")
+ public abstract List<Account> allForProfileSync(long profileId);
+
+ @Query("SELECT generation FROM accounts WHERE profile_id = :profileId LIMIT 1")
+ protected abstract AccountGenerationContainer getGenerationPOJOSync(long profileId);
+ public long getGenerationSync(long profileId) {
+ AccountGenerationContainer result = getGenerationPOJOSync(profileId);
+
+ if (result == null)
+ return 0;
+ return result.generation;
+ }
+ @Query("DELETE FROM accounts WHERE profile_id = :profileId AND generation <> " +
+ ":currentGeneration")
+ public abstract void purgeOldAccountsSync(long profileId, long currentGeneration);
+
+ @Query("DELETE FROM account_values WHERE EXISTS (SELECT 1 FROM accounts a WHERE a" +
+ ".id=account_values.account_id AND a.profile_id=:profileId) AND generation <> " +
+ ":currentGeneration")
+ public abstract void purgeOldAccountValuesSync(long profileId, long currentGeneration);
+ @Transaction
+ public void storeAccountsSync(List<AccountWithAmounts> accounts, long profileId) {
+ long generation = getGenerationSync(profileId) + 1;
+
+ for (AccountWithAmounts rec : accounts) {
+ rec.account.setGeneration(generation);
+ rec.account.setProfileId(profileId);
+ insertSync(rec);
+ }
+ purgeOldAccountsSync(profileId, generation);
+ purgeOldAccountValuesSync(profileId, generation);
+ }