@Test public void deleteScChambersWithoutJudgments() { SupremeCourtChamber scChamber = createScChamber(true); createScChamber(false); createScChamber(false); createScChamber(false); scObjectDeleter.deleteScChambersWithoutJudgments(); List<SupremeCourtChamber> dbScChambers = scChamberRepository.findAll(); assertEquals(1, dbScChambers.size()); assertEquals(scChamber.getId(), dbScChambers.get(0).getId()); }
@Transactional void deleteScChambersWithoutJudgments() { log.debug("Deleting scChambers without referring judgments "); String q = "select scChamber.id from " + SupremeCourtChamber.class.getName() + " scChamber " + " where not exists (select judgment from "+ SupremeCourtJudgment.class.getName() + " judgment " + " join judgment.scChambers_ jscChamber " + " where scChamber.id = jscChamber.id)"; @SuppressWarnings("unchecked") List<Long> scChamberIds = entityManager.createQuery(q).getResultList(); scChamberIds.stream().forEach(scChamberRepository::delete); scChamberRepository.flush(); }
ScObjectDeleter { @Transactional void deleteScChambersWithoutJudgments() { log.debug("Deleting scChambers without referring judgments "); String q = "select scChamber.id from " + SupremeCourtChamber.class.getName() + " scChamber " + " where not exists (select judgment from "+ SupremeCourtJudgment.class.getName() + " judgment " + " join judgment.scChambers_ jscChamber " + " where scChamber.id = jscChamber.id)"; @SuppressWarnings("unchecked") List<Long> scChamberIds = entityManager.createQuery(q).getResultList(); scChamberIds.stream().forEach(scChamberRepository::delete); scChamberRepository.flush(); } }
ScObjectDeleter { @Transactional void deleteScChambersWithoutJudgments() { log.debug("Deleting scChambers without referring judgments "); String q = "select scChamber.id from " + SupremeCourtChamber.class.getName() + " scChamber " + " where not exists (select judgment from "+ SupremeCourtJudgment.class.getName() + " judgment " + " join judgment.scChambers_ jscChamber " + " where scChamber.id = jscChamber.id)"; @SuppressWarnings("unchecked") List<Long> scChamberIds = entityManager.createQuery(q).getResultList(); scChamberIds.stream().forEach(scChamberRepository::delete); scChamberRepository.flush(); }  }
ScObjectDeleter { @Transactional void deleteScChambersWithoutJudgments() { log.debug("Deleting scChambers without referring judgments "); String q = "select scChamber.id from " + SupremeCourtChamber.class.getName() + " scChamber " + " where not exists (select judgment from "+ SupremeCourtJudgment.class.getName() + " judgment " + " join judgment.scChambers_ jscChamber " + " where scChamber.id = jscChamber.id)"; @SuppressWarnings("unchecked") List<Long> scChamberIds = entityManager.createQuery(q).getResultList(); scChamberIds.stream().forEach(scChamberRepository::delete); scChamberRepository.flush(); }  @Autowired void setEntityManager(EntityManager entityManager); @Autowired void setScChamberRepository(ScChamberRepository scChamberRepository); @Autowired void setScJudgmentFormRepository(ScJudgmentFormRepository scJudgmentFormRepository); @Autowired void setScChamberDivisionRepository(ScChamberDivisionRepository scChamberDivisionRepository); }
ScObjectDeleter { @Transactional void deleteScChambersWithoutJudgments() { log.debug("Deleting scChambers without referring judgments "); String q = "select scChamber.id from " + SupremeCourtChamber.class.getName() + " scChamber " + " where not exists (select judgment from "+ SupremeCourtJudgment.class.getName() + " judgment " + " join judgment.scChambers_ jscChamber " + " where scChamber.id = jscChamber.id)"; @SuppressWarnings("unchecked") List<Long> scChamberIds = entityManager.createQuery(q).getResultList(); scChamberIds.stream().forEach(scChamberRepository::delete); scChamberRepository.flush(); }  @Autowired void setEntityManager(EntityManager entityManager); @Autowired void setScChamberRepository(ScChamberRepository scChamberRepository); @Autowired void setScJudgmentFormRepository(ScJudgmentFormRepository scJudgmentFormRepository); @Autowired void setScChamberDivisionRepository(ScChamberDivisionRepository scChamberDivisionRepository);  }