Skip to content

Instantly share code, notes, and snippets.

@tanapoln
Last active September 1, 2017 11:50
Show Gist options
  • Save tanapoln/4a9858f3f84eb86f6b366560a00b0821 to your computer and use it in GitHub Desktop.
Save tanapoln/4a9858f3f84eb86f6b366560a00b0821 to your computer and use it in GitHub Desktop.
@Transactional
public void updateAllFriends() {
Batch<Collection<User>> usersBatch = loadAllUsersBatch();
for (Collection<User> users : usersBatch) {
for (User user : users) {
Collection<User> friends = fetchFriends(user);
TransactionUtils.requiresNewTransaction(() -> {
User newUser = repo.findOne(user.getId())
newUser.getFriends().addAll(friends);
newUser.setLastUpdateTime(new Date());
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment