Presentation is loading. Please wait.

Presentation is loading. Please wait.

Spring-Batch Tutorial Guide for Application Developers.

Similar presentations


Presentation on theme: "Spring-Batch Tutorial Guide for Application Developers."— Presentation transcript:

1 Spring-Batch Tutorial Guide for Application Developers

2 Agenda  “Hello world!” job  Simple job – programming a Tasklet directly  Common job – weaving standard components  Sample jobs

3 “Hello World!” - tasklet public class HelloWorldTasklet implements Tasklet { public ExitStatus execute() throws Exception { System.out.println("Hello world!"); return ExitStatus.FINISHED; }

4 “Hello World!” - tasklet public class HelloWorldTasklet implements Tasklet { public ExitStatus execute() throws Exception { System.out.println("Hello world!"); return ExitStatus.FINISHED; }

5 “Hello World!” - configuration

6 “Hello World!” - configuration

7 Simple job - tasklet public class SimpleTasklet implements Tasklet { private InputSource inputSource; private OutputSource outputSource; public ExitStatus execute() throws Exception { Object data = inputSource.read(); if (data != null) { outputSource.write(data); return ExitStatus.CONTINUABLE; } return ExitStatus.FINISHED; } public void setInputSource(InputSource inputSource) { this.inputSource = inputSource; } public void setOutputSource(OutputSource outputSource) { this.outputSource = outputSource; }

8 Simple job - tasklet public class SimpleTasklet implements Tasklet { private InputSource inputSource; private OutputSource outputSource; public ExitStatus execute() throws Exception { Object data = inputSource.read(); if (data != null) { outputSource.write(data); return ExitStatus.CONTINUABLE; } return ExitStatus.FINISHED; } public void setInputSource(InputSource inputSource) { this.inputSource = inputSource; } public void setOutputSource(OutputSource outputSource) { this.outputSource = outputSource; }

9 Simple job - tasklet public class SimpleTasklet implements Tasklet { private InputSource inputSource; private OutputSource outputSource; public ExitStatus execute() throws Exception { Object data = inputSource.read(); if (data != null) { outputSource.write(data); return ExitStatus.CONTINUABLE; } return ExitStatus.FINISHED; } public void setInputSource(InputSource inputSource) { this.inputSource = inputSource; } public void setOutputSource(OutputSource outputSource) { this.outputSource = outputSource; }

10 Simple job - configuration

11 Simple job – input source <property name="sql" value="SELECT id, quantity, price, customer from TRADE" />

12 Simple job – input source <property name="sql" value="SELECT id, quantity, price, customer from TRADE" />

13 Simple job – output source <bean id="outputSource" class="...FlatFileOutputSource“ scope="step" >

14 Common job - configuration

15 Common job – tasklet

16 Common job – tasklet

17 Common job – tasklet

18 Samples overview  Samples project contains simple batch jobs illustrating various capabilities of the Spring-Batch framework  See the folder src/main/resources/jobs for job configuration files  See src/test/java, package org.springframework.batch.sample for tests which launch the jobs and check the expected results

19 simpleTaskletJob.xml  Straightforwardly implemented Tasklet, similar to the “Simple Job” example  All-in-one solution to help understand tasklet’s execution logic  Standard solutions are more modular, which makes them more flexible and reusable, but also less straightforward to understand

20 fixedLengthImportJob.xml  Clean separation of reading input and processing data (standard from now on)  Typical scenario of importing data from a fixed-length file to database  Custom DAO used for output

21 multilineOrderJob.xml  Handling of complex file format, both reading input and writing output  Single record spans multiple lines and has nested records  Custom ItemProvider and ItemProcessor implementations handling non-standard file format

22 tradeJob.xml  shows a reasonably complex scenario, that would resemble the real-life usage of the framework  3 steps: trade records are imported from file to database customer account balance is adjusted report about customers is exported to a file

23 compositeProcessorSample.xml  Parallel writing to multiple outputs  Example usage of composite ItemProcessor with an injected list of ItemProcessors

24 restartSample.xml  Simulates restart scenario, where the job crashes on first run and succeeds after being restarted  Uses ‘hacked’ tasklet that throws exception after reading a given number of records


Download ppt "Spring-Batch Tutorial Guide for Application Developers."

Similar presentations


Ads by Google