Created
          March 22, 2016 01:01 
        
      - 
      
 - 
        
Save MafaldaLandeiro/f3c074d068ccad7c6c3c to your computer and use it in GitHub Desktop.  
    Listener
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | package org.springBatch.listener; | |
| import java.sql.ResultSet; | |
| import java.sql.SQLException; | |
| import java.util.List; | |
| import org.slf4j.Logger; | |
| import org.slf4j.LoggerFactory; | |
| import org.springBatch.entity.Country; | |
| import org.springframework.batch.core.BatchStatus; | |
| import org.springframework.batch.core.JobExecution; | |
| import org.springframework.batch.core.listener.JobExecutionListenerSupport; | |
| import org.springframework.beans.factory.annotation.Autowired; | |
| import org.springframework.jdbc.core.JdbcTemplate; | |
| import org.springframework.jdbc.core.RowMapper; | |
| public class JobCompletionNotificationListener extends JobExecutionListenerSupport { | |
| private static final Logger log = LoggerFactory.getLogger(JobCompletionNotificationListener.class); | |
| private final JdbcTemplate jdbcTemplate; | |
| @Autowired | |
| public JobCompletionNotificationListener(JdbcTemplate jdbcTemplate) { | |
| this.jdbcTemplate = jdbcTemplate; | |
| } | |
| @Override | |
| public void afterJob(JobExecution jobExecution) { | |
| if(jobExecution.getStatus() == BatchStatus.COMPLETED) { | |
| log.info("--- JOB FINISHED! ---"); | |
| log.info("Results:"); | |
| List<Country> results = jdbcTemplate.query("SELECT id, name, currency FROM countries", new RowMapper<Country>() { | |
| @Override | |
| public Country mapRow(ResultSet rs, int row) throws SQLException { | |
| return new Country(rs.getInt(1), rs.getString(2), rs.getString(3)); | |
| } | |
| }); | |
| for (Country country : results) { | |
| log.info("--- " + country + " ---"); | |
| } | |
| } | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment