// syncing updates void onRemoteUpdateSuccess() throws Exception { Iterable<com.antoshkaplus.words.model.Translation> it = Iterables.concat(updates.localNew, updates.localNotFound, updates.localIntersection); for (com.antoshkaplus.words.model.Translation t : it) { repo.trySyncTranslation(t); } }
public List<Translation> mergeRemote(final List<Translation> remoteList) throws Exception { // merging updates from server and database in one transaction this.updates = repo.executeBatch( new Callable<Updates>() { @Override public Updates call() throws Exception { Updates updates = computeUpdates(repo.getSyncedTranslationList(false), remoteList); for (com.antoshkaplus.words.model.Translation t : updates.localIntersection) { repo.updateTranslation(t); } for (com.antoshkaplus.words.model.Translation t : updates.localNotFound) { TranslationKey key = new TranslationKey(t.foreignWord, t.nativeWord); com.antoshkaplus.words.model.Translation tKey = repo.getTranslation(key); if (tKey == null) { repo.addTranslation(t); } else { t.id = tKey.id; repo.updateTranslation(t); } } // can be done only after successful push to server???? for (com.antoshkaplus.words.model.Translation t : updates.localNew) { repo.updateTranslation(t); } return updates; } }); return updates.remote; }