Spring Book – Chapter 21 – Spring Batch

Batch Meta-Data

Spring Batch saves information related to batch operations in your application in two different ways:

  • Relational Database
  • Volatile (in-memory map)

Storing these details allows Spring Batch to track statuses of job executions. Also the various readers and writers are stateful in nature; this necessitates persisting these meta-data in some form so that they can be used by Spring Batch to do the appropriate operations as required.

The Spring Batch Meta-Data tables very closely match the Domain objects that represent them in Java. The one-to-one relationship between the domain object and the table is as shown in Table 23-3 below.

Table 23-3. Domain object name and database table mapping in Spring Batch

Domain Object Database Table
JobInstance BATCH_JOB_INSTANCE
JobExecution BATCH_JOB_EXECUTION
JobParameters BATCH_JOB_PARAMS
Job’s ExecutionContext BATCH_JOB_EXECUTION_CONTEXT
StepExecution BATCH_STEP_EXECUTION
Step’s ExecutionContext BATCH_STEP_EXECUTION_CONTEXT

The JobRepository is responsible for saving and storing each Java object into its correct database table. JobRepository is purely an internal interface which the users need not know at all. But this has to be defined in the Spring configuration file as show in Listing 23-29 below.

Listing 23-29. JobRepository declaration in Spring configuration file using Spring Batch namespace

Figure 23-17 below shows how the various Spring Batch meta-data is filled in so that the database tables are filled with details required.

 

 Figure 23-17. Spring Batch meta-data details getting filled in by Spring Batch

Figure 23-17. Spring Batch meta-data details getting filled in by Spring Batch

Figure 23-18 below shows the relationship between various database tables in Spring Batch which will be used by the various components to become stateful in nature.

Figure 23-18. Spring Batch meta-data database table schema details (Spring Batch Documentation)

Figure 23-18. Spring Batch meta-data database table schema details (Spring Batch Documentation)

Page Visitors: 25939

The following two tabs change content below.
Tomcy John

Tomcy John

Blogger & Author at javacodebook
He is an Enterprise Java Specialist holding a degree in Engineering (B-Tech) with over 10 years of experience in several industries. He's currently working as Principal Architect at Emirates Group IT since 2005. Prior to this he has worked with Oracle Corporation and Ernst & Young. His main specialization is on various web technologies and acts as chief mentor and Architect to facilitate incorporating Spring as Corporate Standard in the organization.
Tomcy John

Latest posts by Tomcy John (see all)

2 thoughts on “Spring Book – Chapter 21 – Spring Batch

  1. Thanks for sharing the information but what’s the difference between CursorItemReader’s setFetchSize() and PagingItemReader’s setPageSize()? isn’t it the same?

  2. Please provide an example for StoredProcedureItem Reader – which returns cursor and how to process cursor in processor – I am new to Spring Batch as part of my work I need to invoke Oracle Stored proc which takes one param as input and returns result set which I need to process in Spring Batch Processor.

    Thanks
    Laxmi

Leave a Reply

Your email address will not be published. Required fields are marked *