public FriendDTO updateFriend(FriendDTO friendDTO) {
PersistenceManager pm = PMF.getTxnPm();
if (friendDTO.getId() == null) { // create new Friend
Friend newFriend = addFriend(friendDTO);
return newFriend.toDTO();
}
// otherwise, do an update of an existing Friend.
// do this operation under transactional control
Friend friend = null;
try {
for (int i = 0; i < NUM_RETRIES; i++) {
pm.currentTransaction().begin();
friend = pm.getObjectById(Friend.class, friendDTO.getId());
Set<String> origurls = new HashSet<String>(friend.getUrls());
logger.info("original Friend urls are: " + origurls);
// delete feed information from the feedids cache
// only need to do this if the URLs set has changed
if (!origurls.equals(friendDTO.getUrls())) {
CacheSupport.cacheDelete(feedids_nmspce, friendDTO.getId());
}
friend.updateFromDTO(friendDTO);
if (!(origurls.isEmpty() && friendDTO.getUrls().isEmpty())) {
// build task payload:
Map<String, Object> hm = new HashMap<String, Object>();
hm.put("newurls", friendDTO.getUrls());