@Test public void deleteScChamberDivisionsWithoutJudgments() { SupremeCourtChamber scChamber = new SupremeCourtChamber(); scChamber.setName(RandomStringUtils.randomAlphanumeric(12)); scChamberRepository.save(scChamber); SupremeCourtChamberDivision scDivision1 = createScChamberDivision(scChamber, true); createScChamberDivision(scChamber, false); createScChamberDivision(scChamber, false); scObjectDeleter.deleteScChamberDivisionsWithoutJudgments(); assertEquals(1, scChamberDivisionRepository.count()); List<SupremeCourtChamberDivision> dbScChamberDivisions = scChamberDivisionRepository.findAll(); assertEquals(1, dbScChamberDivisions.size()); assertEquals(scDivision1.getId(), dbScChamberDivisions.get(0).getId()); }
@Transactional void deleteScChamberDivisionsWithoutJudgments() { log.debug("Deleting scChamberDivisions without referring judgments "); String q = "select scChamberDivision.id from " + SupremeCourtChamberDivision.class.getName() + " scChamberDivision " + " where not exists (select judgment from "+ SupremeCourtJudgment.class.getName() + " judgment " + " where scChamberDivision.id = judgment.scChamberDivision.id)"; @SuppressWarnings("unchecked") List<Long> scChamberDivisionIds = entityManager.createQuery(q).getResultList(); scChamberDivisionIds.stream().forEach(scChamberDivisionRepository::delete); scChamberDivisionRepository.flush(); }
ScObjectDeleter { @Transactional void deleteScChamberDivisionsWithoutJudgments() { log.debug("Deleting scChamberDivisions without referring judgments "); String q = "select scChamberDivision.id from " + SupremeCourtChamberDivision.class.getName() + " scChamberDivision " + " where not exists (select judgment from "+ SupremeCourtJudgment.class.getName() + " judgment " + " where scChamberDivision.id = judgment.scChamberDivision.id)"; @SuppressWarnings("unchecked") List<Long> scChamberDivisionIds = entityManager.createQuery(q).getResultList(); scChamberDivisionIds.stream().forEach(scChamberDivisionRepository::delete); scChamberDivisionRepository.flush(); } }
ScObjectDeleter { @Transactional void deleteScChamberDivisionsWithoutJudgments() { log.debug("Deleting scChamberDivisions without referring judgments "); String q = "select scChamberDivision.id from " + SupremeCourtChamberDivision.class.getName() + " scChamberDivision " + " where not exists (select judgment from "+ SupremeCourtJudgment.class.getName() + " judgment " + " where scChamberDivision.id = judgment.scChamberDivision.id)"; @SuppressWarnings("unchecked") List<Long> scChamberDivisionIds = entityManager.createQuery(q).getResultList(); scChamberDivisionIds.stream().forEach(scChamberDivisionRepository::delete); scChamberDivisionRepository.flush(); }  }
ScObjectDeleter { @Transactional void deleteScChamberDivisionsWithoutJudgments() { log.debug("Deleting scChamberDivisions without referring judgments "); String q = "select scChamberDivision.id from " + SupremeCourtChamberDivision.class.getName() + " scChamberDivision " + " where not exists (select judgment from "+ SupremeCourtJudgment.class.getName() + " judgment " + " where scChamberDivision.id = judgment.scChamberDivision.id)"; @SuppressWarnings("unchecked") List<Long> scChamberDivisionIds = entityManager.createQuery(q).getResultList(); scChamberDivisionIds.stream().forEach(scChamberDivisionRepository::delete); scChamberDivisionRepository.flush(); }  @Autowired void setEntityManager(EntityManager entityManager); @Autowired void setScChamberRepository(ScChamberRepository scChamberRepository); @Autowired void setScJudgmentFormRepository(ScJudgmentFormRepository scJudgmentFormRepository); @Autowired void setScChamberDivisionRepository(ScChamberDivisionRepository scChamberDivisionRepository); }
ScObjectDeleter { @Transactional void deleteScChamberDivisionsWithoutJudgments() { log.debug("Deleting scChamberDivisions without referring judgments "); String q = "select scChamberDivision.id from " + SupremeCourtChamberDivision.class.getName() + " scChamberDivision " + " where not exists (select judgment from "+ SupremeCourtJudgment.class.getName() + " judgment " + " where scChamberDivision.id = judgment.scChamberDivision.id)"; @SuppressWarnings("unchecked") List<Long> scChamberDivisionIds = entityManager.createQuery(q).getResultList(); scChamberDivisionIds.stream().forEach(scChamberDivisionRepository::delete); scChamberDivisionRepository.flush(); }  @Autowired void setEntityManager(EntityManager entityManager); @Autowired void setScChamberRepository(ScChamberRepository scChamberRepository); @Autowired void setScJudgmentFormRepository(ScJudgmentFormRepository scJudgmentFormRepository); @Autowired void setScChamberDivisionRepository(ScChamberDivisionRepository scChamberDivisionRepository);  }