@Test public void write() { JudgmentWithCorrectionList<Judgment> jwc1 = new JudgmentWithCorrectionList<>(createScJudgment(), createImportCorrectionList()); JudgmentWithCorrectionList<Judgment> jwc2 = new JudgmentWithCorrectionList<>(createScJudgment(), createImportCorrectionList()); JudgmentWithCorrectionList<Judgment> jwc3 = new JudgmentWithCorrectionList<>(createScJudgment(), createImportCorrectionList()); @SuppressWarnings("unchecked") List<JudgmentWithCorrectionList<Judgment>> judgmentsWithCorrectionList = Lists.newArrayList(jwc1, jwc2, jwc3); List<JudgmentCorrection> j1Corrections = createJudgmentCorrections(jwc1.getJudgment(), 1); when(importCorrectionConverter.convertToJudgmentCorrections(jwc1.getJudgment(), jwc1.getCorrectionList().getImportCorrections())).thenReturn(j1Corrections); List<JudgmentCorrection> j2Corrections = createJudgmentCorrections(jwc2.getJudgment(), 2); when(importCorrectionConverter.convertToJudgmentCorrections(jwc2.getJudgment(), jwc2.getCorrectionList().getImportCorrections())).thenReturn(j2Corrections); List<JudgmentCorrection> j3Corrections = createJudgmentCorrections(jwc3.getJudgment(), 3); when(importCorrectionConverter.convertToJudgmentCorrections(jwc3.getJudgment(), jwc3.getCorrectionList().getImportCorrections())).thenReturn(j3Corrections); judgmentImportProcessWriter.write(judgmentsWithCorrectionList); verify(judgmentRepository).save(argJudgments.capture()); assertThat(argJudgments.getValue(), Matchers.containsInAnyOrder(jwc1.getJudgment(), jwc2.getJudgment(), jwc3.getJudgment())); verify(judgmentRepository).flush(); verify(judgmentCorrectionRepository).deleteByJudgmentIds(argJudgmentIds.capture()); assertThat(argJudgmentIds.getValue(), Matchers.containsInAnyOrder(jwc1.getJudgment().getId(), jwc2.getJudgment().getId(), jwc3.getJudgment().getId())); verify(judgmentCorrectionRepository, times(judgmentsWithCorrectionList.size())).save(argJudgmentCorrections.capture()); Matcher<Iterable<? extends Object>> containsInAnyOrder = Matchers.containsInAnyOrder(j1Corrections, j2Corrections, j3Corrections); assertThat(argJudgmentCorrections.getAllValues(), containsInAnyOrder); verify(judgmentCorrectionRepository, times(2)).flush(); verify(entityManager).clear(); }
@Override public void write(List<? extends JudgmentWithCorrectionList<T>> judgmentsWithCorrectionList) { List<Judgment> judgments = judgmentsWithCorrectionList.stream().map(j->j.getJudgment()).collect(Collectors.toList()); judgmentRepository.save(judgments); judgmentRepository.flush(); judgmentCorrectionRepository.deleteByJudgmentIds(judgments.stream().map(j->j.getId()).collect(Collectors.toList())); judgmentCorrectionRepository.flush(); for (JudgmentWithCorrectionList<T> jwc : judgmentsWithCorrectionList) { List<JudgmentCorrection> judgmentCorrections = importCorrectionConverter.convertToJudgmentCorrections(jwc.getJudgment(), jwc.getCorrectionList().getImportCorrections()); judgmentCorrectionRepository.save(judgmentCorrections); } judgmentCorrectionRepository.flush(); entityManager.clear(); }
JudgmentImportProcessWriter implements ItemWriter<JudgmentWithCorrectionList<T>> { @Override public void write(List<? extends JudgmentWithCorrectionList<T>> judgmentsWithCorrectionList) { List<Judgment> judgments = judgmentsWithCorrectionList.stream().map(j->j.getJudgment()).collect(Collectors.toList()); judgmentRepository.save(judgments); judgmentRepository.flush(); judgmentCorrectionRepository.deleteByJudgmentIds(judgments.stream().map(j->j.getId()).collect(Collectors.toList())); judgmentCorrectionRepository.flush(); for (JudgmentWithCorrectionList<T> jwc : judgmentsWithCorrectionList) { List<JudgmentCorrection> judgmentCorrections = importCorrectionConverter.convertToJudgmentCorrections(jwc.getJudgment(), jwc.getCorrectionList().getImportCorrections()); judgmentCorrectionRepository.save(judgmentCorrections); } judgmentCorrectionRepository.flush(); entityManager.clear(); } }
JudgmentImportProcessWriter implements ItemWriter<JudgmentWithCorrectionList<T>> { @Override public void write(List<? extends JudgmentWithCorrectionList<T>> judgmentsWithCorrectionList) { List<Judgment> judgments = judgmentsWithCorrectionList.stream().map(j->j.getJudgment()).collect(Collectors.toList()); judgmentRepository.save(judgments); judgmentRepository.flush(); judgmentCorrectionRepository.deleteByJudgmentIds(judgments.stream().map(j->j.getId()).collect(Collectors.toList())); judgmentCorrectionRepository.flush(); for (JudgmentWithCorrectionList<T> jwc : judgmentsWithCorrectionList) { List<JudgmentCorrection> judgmentCorrections = importCorrectionConverter.convertToJudgmentCorrections(jwc.getJudgment(), jwc.getCorrectionList().getImportCorrections()); judgmentCorrectionRepository.save(judgmentCorrections); } judgmentCorrectionRepository.flush(); entityManager.clear(); }  }
JudgmentImportProcessWriter implements ItemWriter<JudgmentWithCorrectionList<T>> { @Override public void write(List<? extends JudgmentWithCorrectionList<T>> judgmentsWithCorrectionList) { List<Judgment> judgments = judgmentsWithCorrectionList.stream().map(j->j.getJudgment()).collect(Collectors.toList()); judgmentRepository.save(judgments); judgmentRepository.flush(); judgmentCorrectionRepository.deleteByJudgmentIds(judgments.stream().map(j->j.getId()).collect(Collectors.toList())); judgmentCorrectionRepository.flush(); for (JudgmentWithCorrectionList<T> jwc : judgmentsWithCorrectionList) { List<JudgmentCorrection> judgmentCorrections = importCorrectionConverter.convertToJudgmentCorrections(jwc.getJudgment(), jwc.getCorrectionList().getImportCorrections()); judgmentCorrectionRepository.save(judgmentCorrections); } judgmentCorrectionRepository.flush(); entityManager.clear(); }  @Override void write(List<? extends JudgmentWithCorrectionList<T>> judgmentsWithCorrectionList); @Autowired void setJudgmentRepository(JudgmentRepository judgmentRepository); @Autowired void setImportCorrectionConverter(ImportCorrectionConverter importCorrectionConverter); @Autowired void setJudgmentCorrectionRepository(JudgmentCorrectionRepository judgmentCorrectionRepository); @Autowired void setEntityManager(EntityManager entityManager); }
JudgmentImportProcessWriter implements ItemWriter<JudgmentWithCorrectionList<T>> { @Override public void write(List<? extends JudgmentWithCorrectionList<T>> judgmentsWithCorrectionList) { List<Judgment> judgments = judgmentsWithCorrectionList.stream().map(j->j.getJudgment()).collect(Collectors.toList()); judgmentRepository.save(judgments); judgmentRepository.flush(); judgmentCorrectionRepository.deleteByJudgmentIds(judgments.stream().map(j->j.getId()).collect(Collectors.toList())); judgmentCorrectionRepository.flush(); for (JudgmentWithCorrectionList<T> jwc : judgmentsWithCorrectionList) { List<JudgmentCorrection> judgmentCorrections = importCorrectionConverter.convertToJudgmentCorrections(jwc.getJudgment(), jwc.getCorrectionList().getImportCorrections()); judgmentCorrectionRepository.save(judgmentCorrections); } judgmentCorrectionRepository.flush(); entityManager.clear(); }  @Override void write(List<? extends JudgmentWithCorrectionList<T>> judgmentsWithCorrectionList); @Autowired void setJudgmentRepository(JudgmentRepository judgmentRepository); @Autowired void setImportCorrectionConverter(ImportCorrectionConverter importCorrectionConverter); @Autowired void setJudgmentCorrectionRepository(JudgmentCorrectionRepository judgmentCorrectionRepository); @Autowired void setEntityManager(EntityManager entityManager);  }