@Test public void getByNameWithoutDeployments() { Application application1 = new Application(); application1.setName("name1"); Deployment deployment1 = new Deployment(); deployment1.setStatus("RUNNING"); deployment1.setPrice("expensive"); Deployment deployment2 = new Deployment(); deployment2.setStatus("RUNNING"); deployment2.setPrice("expensive"); application1.addDeployment(deployment1); application1.addDeployment(deployment2); Application application2 = new Application(); application2.setName("name2"); Deployment deployment3 = new Deployment(); deployment3.setStatus("RUNNING"); deployment3.setPrice("expensive"); Deployment deployment4 = new Deployment(); deployment4.setStatus("RUNNING"); deployment4.setPrice("expensive"); application2.addDeployment(deployment4); application2.addDeployment(deployment3); boolean saved = applicationDAO.save(application1); assertTrue(saved); saved = applicationDAO.save(application2); assertTrue(saved); Application applicationFromDatabase = applicationDAO.getByNameWithoutDeployments("name1"); assertEquals("name1", applicationFromDatabase.getName()); assertEquals(null, applicationFromDatabase.getDeployments()); applicationFromDatabase = applicationDAO.getByName("name1"); assertEquals("name1", applicationFromDatabase.getName()); assertEquals(2, applicationFromDatabase.getDeployments().size()); applicationFromDatabase = applicationDAO.getByNameWithoutDeployments("xxx"); assertEquals(null, applicationFromDatabase); }
@Override public Application getByNameWithoutDeployments(String name) { Query query = entityManager.createQuery("SELECT a FROM Application a WHERE a.name = :appName"); query.setParameter("appName", name); query.setMaxResults(1); @SuppressWarnings("unchecked") List<Application> applications = query.getResultList(); if(applications.size() > 0) { return ApplicationConverter.withoutDeployments(applications.get(0)); } else { return null; } }
ApplicationDAOJpa implements ApplicationDAO { @Override public Application getByNameWithoutDeployments(String name) { Query query = entityManager.createQuery("SELECT a FROM Application a WHERE a.name = :appName"); query.setParameter("appName", name); query.setMaxResults(1); @SuppressWarnings("unchecked") List<Application> applications = query.getResultList(); if(applications.size() > 0) { return ApplicationConverter.withoutDeployments(applications.get(0)); } else { return null; } } }
ApplicationDAOJpa implements ApplicationDAO { @Override public Application getByNameWithoutDeployments(String name) { Query query = entityManager.createQuery("SELECT a FROM Application a WHERE a.name = :appName"); query.setParameter("appName", name); query.setMaxResults(1); @SuppressWarnings("unchecked") List<Application> applications = query.getResultList(); if(applications.size() > 0) { return ApplicationConverter.withoutDeployments(applications.get(0)); } else { return null; } }  }
ApplicationDAOJpa implements ApplicationDAO { @Override public Application getByNameWithoutDeployments(String name) { Query query = entityManager.createQuery("SELECT a FROM Application a WHERE a.name = :appName"); query.setParameter("appName", name); query.setMaxResults(1); @SuppressWarnings("unchecked") List<Application> applications = query.getResultList(); if(applications.size() > 0) { return ApplicationConverter.withoutDeployments(applications.get(0)); } else { return null; } }  @PersistenceContext (unitName = "applicationManagerDB") void setEntityManager(EntityManager entityManager); EntityManager getEntityManager(); @Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) Application getById(int id); @Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) Application getByIdWithoutDeployments(int id); @Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) List<Application> getAll(); @Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) List<Application> getAllWithOutDeployments(); @Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) boolean save(Application application); @Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) boolean update(Application application); @Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) boolean delete(Application application); @Override Application getByName(String name); @Override Application getByNameWithoutDeployments(String name); }
ApplicationDAOJpa implements ApplicationDAO { @Override public Application getByNameWithoutDeployments(String name) { Query query = entityManager.createQuery("SELECT a FROM Application a WHERE a.name = :appName"); query.setParameter("appName", name); query.setMaxResults(1); @SuppressWarnings("unchecked") List<Application> applications = query.getResultList(); if(applications.size() > 0) { return ApplicationConverter.withoutDeployments(applications.get(0)); } else { return null; } }  @PersistenceContext (unitName = "applicationManagerDB") void setEntityManager(EntityManager entityManager); EntityManager getEntityManager(); @Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) Application getById(int id); @Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) Application getByIdWithoutDeployments(int id); @Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) List<Application> getAll(); @Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) List<Application> getAllWithOutDeployments(); @Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) boolean save(Application application); @Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) boolean update(Application application); @Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) boolean delete(Application application); @Override Application getByName(String name); @Override Application getByNameWithoutDeployments(String name);  }