public static void updateContact( Contact contact, Map<String, List<ContactPhone>> phoneGroups, Map<String, List<ContactAttachment>> attachmentGroups) throws ServiceException { log.debug("updateContact: " + contact.getSurname() + " " + contact.getEmail()); try { DaoFactory daoFactory = DaoFactory.getDaoFactory(); ContactModificationDao modificationDao = daoFactory.getContactModificationDao(); PersistenceManager.startTransaction(); contact.setPhoneList(phoneGroups.get("update")); contact.setAttachmentList(attachmentGroups.get("update")); modificationDao.updateContact(contact); modificationDao.deleteContactPhones(phoneGroups.get("delete")); modificationDao.deleteContactAttachments(attachmentGroups.get("delete")); modificationDao.saveContactPhones(phoneGroups.get("new")); modificationDao.saveContactAttachments(attachmentGroups.get("new")); PersistenceManager.finishTransaction(); } catch (SQLException | NamingException e) { log.error(e); throw new ServiceException("Can't update contact.", e); } catch (DaoException e) { try { PersistenceManager.rollbackTransaction(); } catch (SQLException e1) { log.error(e1); } log.error(e); throw new ServiceException("Can't update contact.", e); } }
public static void deleteContactAttachments(List<ContactAttachment> attachments) throws ServiceException { log.debug("deleteContactAttachments: " + attachments); try { DaoFactory daoFactory = DaoFactory.getDaoFactory(); ContactModificationDao modificationDao = daoFactory.getContactModificationDao(); PersistenceManager.startTransaction(); modificationDao.deleteContactAttachments(attachments); PersistenceManager.finishTransaction(); } catch (SQLException | NamingException e) { log.error(e); throw new ServiceException("Can't delete contact attachments.", e); } catch (DaoException e) { try { PersistenceManager.rollbackTransaction(); } catch (SQLException e1) { log.error(e1); } log.error(e); throw new ServiceException("Can't delete contact attachments.", e); } }