@Test public void delete() { int size = providerDAO.getAll().size(); Provider provider = new Provider(); provider.setName("name"); provider.setVmmUrl("http: provider.setSlamUrl("http2..."); boolean saved = providerDAO.save(provider); assertTrue(saved); Provider providerFromDatabase = providerDAO.getAll().get(size); int id = providerFromDatabase.getId(); boolean deleted = providerDAO.delete(providerFromDatabase); assertTrue(deleted); deleted = providerDAO.delete(providerFromDatabase); assertTrue(!deleted); providerFromDatabase = providerDAO.getById(id); assertEquals(null, providerFromDatabase); }
@Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) public boolean delete(Provider provider) { try { provider = entityManager.getReference(Provider.class, provider.getId()); entityManager.remove(provider); entityManager.flush(); return true; } catch(EntityNotFoundException e) { logger.debug(e); return false; } }
ProviderDAOJpa implements ProviderDAO { @Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) public boolean delete(Provider provider) { try { provider = entityManager.getReference(Provider.class, provider.getId()); entityManager.remove(provider); entityManager.flush(); return true; } catch(EntityNotFoundException e) { logger.debug(e); return false; } } }
ProviderDAOJpa implements ProviderDAO { @Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) public boolean delete(Provider provider) { try { provider = entityManager.getReference(Provider.class, provider.getId()); entityManager.remove(provider); entityManager.flush(); return true; } catch(EntityNotFoundException e) { logger.debug(e); return false; } }  }
ProviderDAOJpa implements ProviderDAO { @Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) public boolean delete(Provider provider) { try { provider = entityManager.getReference(Provider.class, provider.getId()); entityManager.remove(provider); entityManager.flush(); return true; } catch(EntityNotFoundException e) { logger.debug(e); return false; } }  @PersistenceContext (unitName = "providerRegistryDB") void setEntityManager(EntityManager entityManager); EntityManager getEntityManager(); @Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) Provider getById(int id); @Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) List<Provider> getAll(); @Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) boolean save(Provider rpovider); @Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) boolean update(Provider provider); @Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) boolean delete(Provider provider); }
ProviderDAOJpa implements ProviderDAO { @Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) public boolean delete(Provider provider) { try { provider = entityManager.getReference(Provider.class, provider.getId()); entityManager.remove(provider); entityManager.flush(); return true; } catch(EntityNotFoundException e) { logger.debug(e); return false; } }  @PersistenceContext (unitName = "providerRegistryDB") void setEntityManager(EntityManager entityManager); EntityManager getEntityManager(); @Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) Provider getById(int id); @Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) List<Provider> getAll(); @Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) boolean save(Provider rpovider); @Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) boolean update(Provider provider); @Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) boolean delete(Provider provider);  }