BATCH-676: Added sample jobs for non sequential execution and decisions
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
package org.springframework.batch.sample.domain.nonSequential.internal;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.batch.core.ExitStatus;
|
||||
import org.springframework.batch.core.StepContribution;
|
||||
import org.springframework.batch.core.step.tasklet.Tasklet;
|
||||
import org.springframework.core.AttributeAccessor;
|
||||
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
|
||||
|
||||
public class ErrorLogWriter implements Tasklet {
|
||||
|
||||
protected final Log logger = LogFactory.getLog(getClass());
|
||||
private SimpleJdbcTemplate simpleJdbcTemplate;
|
||||
|
||||
public ExitStatus execute(StepContribution contribution, AttributeAccessor attributes) throws Exception {
|
||||
this.simpleJdbcTemplate.update("insert into ERROR_LOG values ('Some records were skipped!')");
|
||||
return ExitStatus.FINISHED;
|
||||
}
|
||||
|
||||
public void setDataSource(DataSource dataSource) {
|
||||
this.simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package org.springframework.batch.sample.domain.nonSequential.internal;
|
||||
|
||||
import org.springframework.batch.core.ExitStatus;
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
import org.springframework.batch.core.StepExecution;
|
||||
import org.springframework.batch.core.job.flow.support.state.JobExecutionDecider;
|
||||
|
||||
public class SkipCheckingDecider implements JobExecutionDecider {
|
||||
|
||||
public String decide(JobExecution jobExecution, StepExecution stepExecution) {
|
||||
if (!stepExecution.getExitStatus().getExitCode().equals(ExitStatus.FAILED.getExitCode())
|
||||
&& stepExecution.getSkipCount() > 0) {
|
||||
return "COMPLETED WITH SKIPS";
|
||||
} else {
|
||||
return ExitStatus.FINISHED.getExitCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package org.springframework.batch.sample.domain.nonSequential.internal;
|
||||
|
||||
import org.springframework.batch.core.ExitStatus;
|
||||
import org.springframework.batch.core.StepExecution;
|
||||
import org.springframework.batch.core.StepExecutionListener;
|
||||
|
||||
public class SkipCheckingListener implements StepExecutionListener {
|
||||
|
||||
public ExitStatus afterStep(StepExecution stepExecution) {
|
||||
if (!stepExecution.getExitStatus().getExitCode().equals(ExitStatus.FAILED.getExitCode())
|
||||
&& stepExecution.getSkipCount() > 0) {
|
||||
return new ExitStatus(false, "COMPLETED WITH SKIPS");
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void beforeStep(StepExecution stepExecution) {
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user