Skip to content

Instantly share code, notes, and snippets.

@tanapoln
Created September 1, 2017 11:51
Show Gist options
  • Save tanapoln/3e08d417cb4937fcf0ae9374ef474130 to your computer and use it in GitHub Desktop.
Save tanapoln/3e08d417cb4937fcf0ae9374ef474130 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.getFriends().addAll(friends);
user.setLastUpdateTime(new Date());
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment