Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Query batch job metadata in Spring batch

I want to fetch the 10 latest records from the BATCH_JOB_EXECUTION-table joined with the BATCH_JOB_INSTANCE-table.

So how can I access these tables?

In this application I have used Spring Data JPA. It's another application which uses Spring Batch and created these tables. In other words, I would just like to run a JOIN-query and map it directly to my custom object with just the necessary fields. As far as it's possible, I would like to avoid making seperate models for the two tables. But I don't know the best approach here.

like image 249
Ole-M Avatar asked Oct 15 '15 08:10

Ole-M


1 Answers

If you want to do it from Spring Batch code you need to use JobExplorer and apply filters on either START_TIME or END_TIME. Alternatively, just send an SQL query with your desired JOIN to the DB using JDBC. The DDLs of the metadata tables can be found here.

EDIT

If you want to try to do it in SpringBatch, I guess you need to iterate through JobExecutions and find the ones that interest you, then do your thing )) someth. like:

List<JobInstance> jobInstances = jobExplorer.getJobInstances(jobName);

for (JobInstance jobInstance : jobInstances) {
    List<JobExecution> jobExecutions = jobExplorer.getJobExecutions(jobInstance);
    for (JobExecution jobExecution : jobExecutions) {
        if (//jobExecution.getWhatever...)) {
        // do your thing...
        }
     }
} 

Good Luck!

like image 97
aviad Avatar answered Sep 29 '22 15:09

aviad