use of com.pkslow.batch.entity.Employee in project pkslow-samples by LarryDpk.
the class JobConfig method reader.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Bean
public FlatFileItemReader<Employee> reader() {
// Create reader instance
FlatFileItemReader<Employee> reader = new FlatFileItemReader<Employee>();
// Set number of lines to skips. Use it if file has header rows.
reader.setLinesToSkip(1);
// Configure how each line will be parsed and mapped to different values
reader.setLineMapper(new DefaultLineMapper() {
{
// 3 columns in each row
setLineTokenizer(new DelimitedLineTokenizer() {
{
setNames(new String[] { "id", "firstName", "lastName" });
}
});
// Set values in Employee class
setFieldSetMapper(new BeanWrapperFieldSetMapper<Employee>() {
{
setTargetType(Employee.class);
}
});
}
});
return reader;
}
use of com.pkslow.batch.entity.Employee in project pkslow-samples by LarryDpk.
the class JobConfig method writer.
@Bean
public FlatFileItemWriter<Employee> writer() {
// Create writer instance
FlatFileItemWriter<Employee> writer = new FlatFileItemWriter<>();
// Set output file location
writer.setResource(new FileSystemResource(outputFilename));
// All job repetitions should "append" to same output file
writer.setAppendAllowed(true);
// Name field values sequence based on object properties
writer.setLineAggregator(new DelimitedLineAggregator<Employee>() {
{
setDelimiter(",");
setFieldExtractor(new BeanWrapperFieldExtractor<Employee>() {
{
setNames(new String[] { "id", "firstName", "lastName" });
}
});
}
});
return writer;
}
Aggregations