@Test public void delete() { int size = agreementDAO.getAll().size(); Agreement agreement = new Agreement(); agreement.setPrice("111"); agreement.setProviderId("provider-id"); agreement.setSlaAgreement("sla-agreement"); agreement.setSlaAgreementId("sla-agreement-id"); boolean saved = agreementDAO.save(agreement); assertTrue(saved); Agreement agreementFromDatabase = agreementDAO.getAll().get(size); int id = agreementFromDatabase.getId(); boolean deleted = agreementDAO.delete(agreementFromDatabase); assertTrue(deleted); deleted = agreementDAO.delete(agreementFromDatabase); assertTrue(!deleted); agreementFromDatabase = agreementDAO.getById(id); assertEquals(null, agreementFromDatabase); }
@Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) public boolean delete(Agreement agreement) { try { agreement = entityManager.getReference(Agreement.class, agreement.getId()); entityManager.remove(agreement); entityManager.flush(); return true; } catch(EntityNotFoundException e) { logger.debug(e); return false; } }
AgreementDAOJpa implements AgreementDAO { @Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) public boolean delete(Agreement agreement) { try { agreement = entityManager.getReference(Agreement.class, agreement.getId()); entityManager.remove(agreement); entityManager.flush(); return true; } catch(EntityNotFoundException e) { logger.debug(e); return false; } } }
AgreementDAOJpa implements AgreementDAO { @Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) public boolean delete(Agreement agreement) { try { agreement = entityManager.getReference(Agreement.class, agreement.getId()); entityManager.remove(agreement); entityManager.flush(); return true; } catch(EntityNotFoundException e) { logger.debug(e); return false; } }  }
AgreementDAOJpa implements AgreementDAO { @Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) public boolean delete(Agreement agreement) { try { agreement = entityManager.getReference(Agreement.class, agreement.getId()); entityManager.remove(agreement); entityManager.flush(); return true; } catch(EntityNotFoundException e) { logger.debug(e); return false; } }  @PersistenceContext (unitName = "applicationManagerDB") void setEntityManager(EntityManager entityManager); EntityManager getEntityManager(); @Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) Agreement getById(int id); @Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) List<Agreement> getAll(); @Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) boolean save(Agreement agreement); @Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) boolean update(Agreement agreement); @Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) boolean delete(Agreement agreement); @Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) @SuppressWarnings("unchecked") Agreement getAcceptedAgreement(Deployment deployment); }
AgreementDAOJpa implements AgreementDAO { @Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) public boolean delete(Agreement agreement) { try { agreement = entityManager.getReference(Agreement.class, agreement.getId()); entityManager.remove(agreement); entityManager.flush(); return true; } catch(EntityNotFoundException e) { logger.debug(e); return false; } }  @PersistenceContext (unitName = "applicationManagerDB") void setEntityManager(EntityManager entityManager); EntityManager getEntityManager(); @Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) Agreement getById(int id); @Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) List<Agreement> getAll(); @Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) boolean save(Agreement agreement); @Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) boolean update(Agreement agreement); @Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) boolean delete(Agreement agreement); @Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) @SuppressWarnings("unchecked") Agreement getAcceptedAgreement(Deployment deployment);  }