コード例 #1
0
 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);
   }
 }
コード例 #2
0
 public static void deleteContacts(Long contactsId[]) throws ServiceException {
   log.debug("deleteContacts: ");
   try {
     DaoFactory daoFactory = DaoFactory.getDaoFactory();
     ContactModificationDao modificationDao = daoFactory.getContactModificationDao();
     PersistenceManager.startTransaction();
     modificationDao.deleteContacts(contactsId);
     PersistenceManager.finishTransaction();
   } catch (SQLException | NamingException e) {
     log.error(e);
     throw new ServiceException("Can not delete contacts.", e);
   } catch (DaoException e) {
     try {
       PersistenceManager.rollbackTransaction();
     } catch (SQLException e1) {
       log.error(e1);
     }
     log.error(e);
     throw new ServiceException("Can not delete contacts.", e);
   }
 }
コード例 #3
0
 public static void updateContactAttachments(Contact contact) throws ServiceException {
   log.debug("updateContactAttachments: " + contact.getIdContact());
   try {
     DaoFactory daoFactory = DaoFactory.getDaoFactory();
     ContactModificationDao modificationDao = daoFactory.getContactModificationDao();
     PersistenceManager.startTransaction();
     modificationDao.updateContactAttachments(contact);
     PersistenceManager.finishTransaction();
   } catch (SQLException | NamingException e) {
     log.error(e);
     throw new ServiceException("Can't update contact attachments.", e);
   } catch (DaoException e) {
     try {
       PersistenceManager.rollbackTransaction();
     } catch (SQLException e1) {
       log.error(e1);
     }
     log.error(e);
     throw new ServiceException("Can't update contact attachments.", e);
   }
 }
コード例 #4
0
 public static void saveContactPhones(List<ContactPhone> phones) throws ServiceException {
   log.debug("saveContactPhones: " + phones);
   try {
     DaoFactory daoFactory = DaoFactory.getDaoFactory();
     ContactModificationDao modificationDao = daoFactory.getContactModificationDao();
     PersistenceManager.startTransaction();
     modificationDao.saveContactPhones(phones);
     PersistenceManager.finishTransaction();
   } catch (SQLException | NamingException e) {
     log.error(e);
     throw new ServiceException("Can't save contact phones.", e);
   } catch (DaoException e) {
     try {
       PersistenceManager.rollbackTransaction();
     } catch (SQLException e1) {
       log.error(e1);
     }
     log.error(e);
     throw new ServiceException("Can't save contact phones.", e);
   }
 }
コード例 #5
0
 public static Contact addNewContact(Contact contact) throws ServiceException {
   log.debug("addNewContact: " + contact.getSurname() + " " + contact.getEmail());
   Contact savedContact = null;
   try {
     DaoFactory daoFactory = DaoFactory.getDaoFactory();
     ContactModificationDao modificationDao = daoFactory.getContactModificationDao();
     PersistenceManager.startTransaction();
     savedContact = modificationDao.addNewContact(contact);
     PersistenceManager.finishTransaction();
   } catch (SQLException | NamingException e) {
     log.error(e);
     throw new ServiceException("Can not add new contact.", e);
   } catch (DaoException e) {
     try {
       PersistenceManager.rollbackTransaction();
     } catch (SQLException e1) {
       log.error(e1);
     }
     log.error(e);
     throw new ServiceException("Can not add new contact.", e);
   }
   return savedContact;
 }
コード例 #6
0
 public static List<ContactAttachment> saveContactAttachments(List<ContactAttachment> attachments)
     throws ServiceException {
   log.debug("saveContactAttachments: " + attachments);
   List<ContactAttachment> savedAttachments = new ArrayList<>();
   try {
     DaoFactory daoFactory = DaoFactory.getDaoFactory();
     ContactModificationDao modificationDao = daoFactory.getContactModificationDao();
     PersistenceManager.startTransaction();
     savedAttachments = modificationDao.saveContactAttachments(attachments);
     PersistenceManager.finishTransaction();
   } catch (SQLException | NamingException e) {
     log.error(e);
     throw new ServiceException("Can't save contact attachments.", e);
   } catch (DaoException e) {
     try {
       PersistenceManager.rollbackTransaction();
     } catch (SQLException e1) {
       log.error(e1);
     }
     log.error(e);
     throw new ServiceException("Can't save contact attachments.", e);
   }
   return savedAttachments;
 }