2

I am doing spring batch application to get the data from database and finally updating some records in the database. The problem is ItemProcessor and ItemWriter are not being called.

here is my config file.

<job id="BpmJob" xmlns="http://www.springframework.org/schema/batch">
  <step id="step1">
    <tasklet transaction-manager="transactionManager">
      <chunk reader="pagingItemReader" processor="testApp" writer="itemWriter" commit-interval="1" />
    </tasklet>
  </step>
</job>

<bean id="pagingItemReader" class="com.tcs.controller.BpmReader" scope="step" />        
<bean id="testApp" class="com.tcs.controller.BpmProcess" scope="step" />
<bean id="itemWriter" class="com.tcs.controller.BpmWriter" scope="step" />

and i customized ItemProcessor and Item writer.

@Component
 public class BpmWriter implements ItemWriter<List<User>> {        

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Override
    public void write(List<? extends List<User>> userList) throws Exception {
        for(int i=0;i<userList.size();i++){
        User user=(User)userList.get(i);
            try{
                String query="update com_tt_bpm_batch set status =:status where seqNo =:seqNo";
                SqlParameterSource namedParameters = new MapSqlParameterSource();  
                  ((MapSqlParameterSource) namedParameters).addValue("status","INACTIVE");  
                  ((MapSqlParameterSource) namedParameters).addValue("seqNo",user.getSeqNo());  
                  jdbcTemplate.update(query, namedParameters); 
                logger.info("updation is successful for seqNo "+user.getSeqNo());
            }catch(Exception e){
                logger.error("exception at updating the status to inactive ..");
                logger.error(e.getStackTrace());
            }
        }       
    }
}

Customzied ItemProcessor

@Component
public class BpmProcess implements ItemProcessor<User,User>{

    List<User>userList=new ArrayList<User>();
    private User userDetails;
    private static final Logger logger=Logger.getLogger(BpmProcess. class);
    @Override
    public User process(User user) {
        try{
            if(logger.isDebugEnabled()){
                logger.debug("process method begins");
            }   

         userDetails=new User();
        userDetails.setSeqNo(user.getSeqNo());
        userList.add(userDetails);
        if(logger.isDebugEnabled()){
            logger.debug("process method ends");
        }   

    }
        catch(Exception e){
        logger.error("Exception at data processing");
        logger.error(e.getMessage());
    }
        return userDetails;
    }
}
M. Deinum
  • 115,695
  • 22
  • 220
  • 224
suri
  • 415
  • 1
  • 9
  • 22
  • If there is nothing to read nothing will happen. Also why are you keeping state in your custom `ItemProcessor`? And your `ItemWriter` will retrieve a `List` of `User` object not a list of lists... Actually I don't see the need for the custom classes as there is nothing that adds something or that cannot be done with the `JdbcBatchItemWriter` and the processor doesn't actually do anything special. – M. Deinum Mar 14 '16 at 10:34
  • no i am reading that's why at least it is reading the itemReader. this is my code to read the Job JobParameters jobParameters = new JobParametersBuilder().addLong("time", System.currentTimeMillis()).toJobParameters(); JobExecution execution = jobLauncher.run(job, jobParameters); – suri Mar 14 '16 at 10:39
  • No that is starting the job... That isn't reading (also don't add code as comments, improve your question). That doesn't mean the `pagingItemReader` is actually returning values. – M. Deinum Mar 14 '16 at 10:42
  • this what i am doing to run a job. it is calling the pagingItemReader and getting the data from database successfully. as for spring document to run a batch we have to call jobLauncher.run(job,jobParameters). you tell me am i missing any thing here. thanks for your reply. – suri Mar 14 '16 at 10:49
  • Again the fact that a job does something doesn't mean the `pagingItemReader` is actually returning something. If that query is wrong it doesn't do anything. Also your writer is wrong (see my comment). So you can launch the job but if nothing is read it will do nothing. – M. Deinum Mar 14 '16 at 10:51
  • can you give some reference so that i can do better. – suri Mar 14 '16 at 10:55

0 Answers0