How it works...

To understand what is happening:

  1. UserReader extends the AbstractItemReader class that has two key methods: open() and readItem(). In our case, the first one opens the META-INF/user.txt and the second one reads each line of the file.
  2. The UserProcessor class extends the ItemProcessor class that has a processItem() method. It gets the item read by readItem() (from UserReader) to generate the User object that we want.
  3. Once all items are processed and available in a list (in memory) we use the UserWriter class; that extends the AbstractItemWriter class and has the writeItems method. We use it, in our case, to persist the data read from the user.txt file.

All set so, we just use UserBean to run the job:

    public void run() {
try {
JobOperator job = BatchRuntime.getJobOperator();
long jobId = job.start("acess-user", new Properties());
System.out.println("Job started: " + jobId);
} catch (JobStartException ex) {
System.out.println(ex.getMessage());
}
}

The job.start() method is referencing the acess-user.xml file, enabling our reader, processor, and writer to work together.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.19.243