@Test public void deleteMeansOfAppealWithoutJudgments() { Judgment scJudgment = rawJudgmentTestFactory.createCtJudgment(false); Judgment ctJudgment = rawJudgmentTestFactory.createCtJudgment(false); MeansOfAppeal scMeansOfAppeal1 = createMeansOfAppeal(CourtType.SUPREME, "scMeansOfAppeal1"); createMeansOfAppeal(CourtType.SUPREME, "scMeansOfAppeal2"); MeansOfAppeal ctMeansOfAppeal1 = createMeansOfAppeal(CourtType.CONSTITUTIONAL_TRIBUNAL, "ctMeansOfAppeal1"); MeansOfAppeal ctMeansOfAppeal2 = createMeansOfAppeal(CourtType.CONSTITUTIONAL_TRIBUNAL, "ctMeansOfAppeal2"); scJudgment.setMeansOfAppeal(scMeansOfAppeal1); ctJudgment.setMeansOfAppeal(ctMeansOfAppeal1); judgmentRepository.save(Lists.newArrayList(scJudgment, ctJudgment)); judgmentObjectDeleter.deleteMeansOfAppealWithoutJudgments(CourtType.SUPREME); List<MeansOfAppeal> dbMeansOfAppeal = meansOfAppealRepository.findAll(); assertThat(dbMeansOfAppeal, containsInAnyOrder(scMeansOfAppeal1, ctMeansOfAppeal1, ctMeansOfAppeal2)); }
@Transactional public void deleteMeansOfAppealWithoutJudgments(CourtType courtType) { log.debug("Deleting meansOfAppeal (with type {}) without referring judgments ", courtType.name()); String q = "select meansOfAppeal.id from " + MeansOfAppeal.class.getName() + " meansOfAppeal " + " where meansOfAppeal.courtType = :courtType " + " and not exists (select judgment from "+ Judgment.class.getName() + " judgment " + " where judgment.meansOfAppeal.id = meansOfAppeal.id)"; @SuppressWarnings("unchecked") List<Long> meansOfAppealIds = entityManager.createQuery(q) .setParameter("courtType", courtType) .getResultList(); meansOfAppealIds.stream().forEach(meansOfAppealRepository::delete); meansOfAppealRepository.flush(); }
JudgmentObjectDeleter { @Transactional public void deleteMeansOfAppealWithoutJudgments(CourtType courtType) { log.debug("Deleting meansOfAppeal (with type {}) without referring judgments ", courtType.name()); String q = "select meansOfAppeal.id from " + MeansOfAppeal.class.getName() + " meansOfAppeal " + " where meansOfAppeal.courtType = :courtType " + " and not exists (select judgment from "+ Judgment.class.getName() + " judgment " + " where judgment.meansOfAppeal.id = meansOfAppeal.id)"; @SuppressWarnings("unchecked") List<Long> meansOfAppealIds = entityManager.createQuery(q) .setParameter("courtType", courtType) .getResultList(); meansOfAppealIds.stream().forEach(meansOfAppealRepository::delete); meansOfAppealRepository.flush(); } }
JudgmentObjectDeleter { @Transactional public void deleteMeansOfAppealWithoutJudgments(CourtType courtType) { log.debug("Deleting meansOfAppeal (with type {}) without referring judgments ", courtType.name()); String q = "select meansOfAppeal.id from " + MeansOfAppeal.class.getName() + " meansOfAppeal " + " where meansOfAppeal.courtType = :courtType " + " and not exists (select judgment from "+ Judgment.class.getName() + " judgment " + " where judgment.meansOfAppeal.id = meansOfAppeal.id)"; @SuppressWarnings("unchecked") List<Long> meansOfAppealIds = entityManager.createQuery(q) .setParameter("courtType", courtType) .getResultList(); meansOfAppealIds.stream().forEach(meansOfAppealRepository::delete); meansOfAppealRepository.flush(); }  }
JudgmentObjectDeleter { @Transactional public void deleteMeansOfAppealWithoutJudgments(CourtType courtType) { log.debug("Deleting meansOfAppeal (with type {}) without referring judgments ", courtType.name()); String q = "select meansOfAppeal.id from " + MeansOfAppeal.class.getName() + " meansOfAppeal " + " where meansOfAppeal.courtType = :courtType " + " and not exists (select judgment from "+ Judgment.class.getName() + " judgment " + " where judgment.meansOfAppeal.id = meansOfAppeal.id)"; @SuppressWarnings("unchecked") List<Long> meansOfAppealIds = entityManager.createQuery(q) .setParameter("courtType", courtType) .getResultList(); meansOfAppealIds.stream().forEach(meansOfAppealRepository::delete); meansOfAppealRepository.flush(); }  @Transactional void deleteJudgmentsWithoutRawSourceJudgment(Class<? extends Judgment> judgmentClass, Class<? extends RawSourceJudgment> rawJudgmentClass); @Transactional void deleteMeansOfAppealWithoutJudgments(CourtType courtType); @Transactional void deleteJudgmentResultsWithoutJudgments(CourtType courtType); }
JudgmentObjectDeleter { @Transactional public void deleteMeansOfAppealWithoutJudgments(CourtType courtType) { log.debug("Deleting meansOfAppeal (with type {}) without referring judgments ", courtType.name()); String q = "select meansOfAppeal.id from " + MeansOfAppeal.class.getName() + " meansOfAppeal " + " where meansOfAppeal.courtType = :courtType " + " and not exists (select judgment from "+ Judgment.class.getName() + " judgment " + " where judgment.meansOfAppeal.id = meansOfAppeal.id)"; @SuppressWarnings("unchecked") List<Long> meansOfAppealIds = entityManager.createQuery(q) .setParameter("courtType", courtType) .getResultList(); meansOfAppealIds.stream().forEach(meansOfAppealRepository::delete); meansOfAppealRepository.flush(); }  @Transactional void deleteJudgmentsWithoutRawSourceJudgment(Class<? extends Judgment> judgmentClass, Class<? extends RawSourceJudgment> rawJudgmentClass); @Transactional void deleteMeansOfAppealWithoutJudgments(CourtType courtType); @Transactional void deleteJudgmentResultsWithoutJudgments(CourtType courtType);  }