/** * Surrounds the actual write call with listener callbacks. * * @param items list of items to be written. * @throws Exception thrown if error occurs. */ protected final void doWrite(List<O> items) throws Exception { if (itemWriter == null) { return; } try { listener.beforeWrite(items); writeItems(items); doAfterWrite(items); } catch (Exception e) { doOnWriteError(e, items); throw e; } }
/** * Test method for * {@link org.springframework.batch.core.listener.MulticasterBatchListener#beforeWrite(List)} * . */ @Test public void testBeforeWrite() { multicast.beforeWrite(null); assertEquals(1, count); }
/** * Implements writing and all related listener calls * * @param contribution a {@link StepContribution} * @param chunk a {@link Chunk} * @throws Exception thrown if error occurs during the writing portion of the chunking loop. */ protected final void doPersist(final StepContribution contribution, final Chunk<O> chunk) throws Exception { try { List<O> items = chunk.getItems(); listener.beforeWrite(items); itemWriter.write(items); listener.afterWrite(items); } catch (Exception e) { listener.onWriteError(e, chunk.getItems()); throw e; } } }
/** * Test method for * {@link org.springframework.batch.core.listener.MulticasterBatchListener#beforeWrite(List)} * . */ @Test public void testBeforeWriteFails() { error = true; try { multicast.beforeWrite(null); fail("Expected StepListenerFailedException"); } catch (StepListenerFailedException e) { // expected String message = e.getCause().getMessage(); assertEquals("Wrong message: " + message, "listener error", message); } assertEquals(1, count); }
@Test public void testBeforeWriteFails_withAnnotatedListener() { StepListener listener = StepListenerFactoryBean.getListener(new AnnotationBasedStepListener()); multicast.register(listener); try { multicast.beforeWrite(null); fail("Expected StepListenerFailedException"); } catch (StepListenerFailedException e) { // expected Throwable cause = e.getCause(); String message = cause.getMessage(); assertTrue(cause instanceof IllegalStateException); assertEquals("Wrong message: " + message, "listener error", message); } }
/** * Surrounds the actual write call with listener callbacks. * * @param items list of items to be written. * @throws Exception thrown if error occurs. */ protected final void doWrite(List<O> items) throws Exception { if (itemWriter == null) { return; } try { listener.beforeWrite(items); writeItems(items); doAfterWrite(items); } catch (Exception e) { doOnWriteError(e, items); throw e; } }
/** * Surrounds the actual write call with listener callbacks. * * @param items list of items to be written. * @throws Exception thrown if error occurs. */ protected final void doWrite(List<O> items) throws Exception { if (itemWriter == null) { return; } try { listener.beforeWrite(items); writeItems(items); doAfterWrite(items); } catch (Exception e) { doOnWriteError(e, items); throw e; } }
/** * Surrounds the actual write call with listener callbacks. * * @param items * @throws Exception */ protected final void doWrite(List<O> items) throws Exception { if (itemWriter==null) { return; } try { listener.beforeWrite(items); writeItems(items); doAfterWrite(items); } catch (Exception e) { listener.onWriteError(e, items); throw e; } }
/** * Surrounds the actual write call with listener callbacks. * * @param items * @throws Exception */ protected final void doWrite(List<O> items) throws Exception { if (itemWriter == null) { return; } try { listener.beforeWrite(items); writeItems(items); doAfterWrite(items); } catch (Exception e) { doOnWriteError(e, items); throw e; } }
/** * Implements writing and all related listener calls * * @param contribution a {@link StepContribution} * @param chunk a {@link Chunk} * @throws Exception */ protected final void doPersist(final StepContribution contribution, final Chunk<O> chunk) throws Exception { try { List<O> items = chunk.getItems(); listener.beforeWrite(items); itemWriter.write(items); listener.afterWrite(items); } catch (Exception e) { listener.onWriteError(e, chunk.getItems()); throw e; } } }
/** * Implements writing and all related listener calls * * @param contribution a {@link StepContribution} * @param chunk a {@link Chunk} * @throws Exception thrown if error occurs during the writing portion of the chunking loop. */ protected final void doPersist(final StepContribution contribution, final Chunk<O> chunk) throws Exception { try { List<O> items = chunk.getItems(); listener.beforeWrite(items); itemWriter.write(items); listener.afterWrite(items); } catch (Exception e) { listener.onWriteError(e, chunk.getItems()); throw e; } } }
/** * Implements writing and all related listener calls * * @param contribution a {@link StepContribution} * @param chunk a {@link Chunk} * @throws Exception thrown if error occurs during the writing portion of the chunking loop. */ protected final void doPersist(final StepContribution contribution, final Chunk<O> chunk) throws Exception { try { List<O> items = chunk.getItems(); listener.beforeWrite(items); itemWriter.write(items); listener.afterWrite(items); } catch (Exception e) { listener.onWriteError(e, chunk.getItems()); throw e; } } }