BATCH-514:Additional small refactorings on Jdbc readers.
This commit is contained in:
@@ -24,6 +24,7 @@ import org.springframework.batch.core.JobParameters;
|
||||
import org.springframework.batch.core.StepExecution;
|
||||
import org.springframework.batch.core.StepExecutionListener;
|
||||
import org.springframework.batch.core.listener.StepExecutionListenerSupport;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.jdbc.core.PreparedStatementSetter;
|
||||
import org.springframework.jdbc.core.SqlTypeValue;
|
||||
@@ -38,18 +39,23 @@ import org.springframework.util.Assert;
|
||||
* @author Lucas Ward
|
||||
*
|
||||
*/
|
||||
public class JobParametersPreparedStatementSetter extends StepExecutionListenerSupport implements
|
||||
public class StepExecutionPreparedStatementSetter extends StepExecutionListenerSupport implements
|
||||
PreparedStatementSetter, InitializingBean {
|
||||
|
||||
private List parameterKeys;
|
||||
private JobParameters jobParameters;
|
||||
private ExecutionContext executionContext;
|
||||
|
||||
public void setValues(PreparedStatement ps) throws SQLException {
|
||||
Map parameters = jobParameters.getParameters();
|
||||
for(int i = 0; i < parameterKeys.size(); i++){
|
||||
Object arg = parameters.get(parameterKeys.get(i));
|
||||
String parameterKey = parameterKeys.get(i).toString();
|
||||
Object arg = executionContext.get(parameterKey);
|
||||
if(arg == null){
|
||||
throw new IllegalStateException("No job parameter found for with key of: [" + parameterKeys.get(i) + "]");
|
||||
arg = parameters.get(parameterKey);
|
||||
if(arg == null){
|
||||
throw new IllegalStateException("No job parameter found for with key of: [" + parameterKeys.get(i) + "]");
|
||||
}
|
||||
}
|
||||
StatementCreatorUtils.setParameterValue(ps, i + 1, SqlTypeValue.TYPE_UNKNOWN, arg);
|
||||
}
|
||||
@@ -57,6 +63,7 @@ public class JobParametersPreparedStatementSetter extends StepExecutionListenerS
|
||||
|
||||
public void beforeStep(StepExecution stepExecution) {
|
||||
this.jobParameters = stepExecution.getJobParameters();
|
||||
this.executionContext = stepExecution.getExecutionContext();
|
||||
}
|
||||
|
||||
/**
|
||||
Reference in New Issue
Block a user