private <T> void doDelete(String theDescriptor, Supplier<Slice<T>> theLoader, Supplier<Integer> theCounter, JpaRepository<T, ?> theDao) { int count; ourLog.info(" * Deleting {}", theDescriptor); int totalCount = theCounter.get(); StopWatch sw = new StopWatch(); count = 0; while (true) { Slice<T> link = theLoader.get(); if (link.hasContent() == false) { break; } TransactionTemplate txTemplate = new TransactionTemplate(myTransactionManager); txTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); txTemplate.execute(t -> { theDao.deleteInBatch(link); return null; }); count += link.getNumberOfElements(); ourLog.info(" * {} {} deleted - {}/sec - ETA: {}", count, theDescriptor, sw.formatThroughput(count, TimeUnit.SECONDS), sw.getEstimatedTimeRemaining(count, totalCount)); } theDao.flush(); }
private <T> void doDelete(String theDescriptor, Supplier<Slice<T>> theLoader, Supplier<Integer> theCounter, JpaRepository<T, ?> theDao) { int count; ourLog.info(" * Deleting {}", theDescriptor); int totalCount = theCounter.get(); StopWatch sw = new StopWatch(); count = 0; while (true) { Slice<T> link = theLoader.get(); if (link.hasContent() == false) { break; } TransactionTemplate txTemplate = new TransactionTemplate(myTransactionManager); txTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); txTemplate.execute(t -> { theDao.deleteInBatch(link); return null; }); count += link.getNumberOfElements(); ourLog.info(" * {} {} deleted - {}/sec - ETA: {}", count, theDescriptor, sw.formatThroughput(count, TimeUnit.SECONDS), sw.getEstimatedTimeRemaining(count, totalCount)); } theDao.flush(); }