Search in sources :

Example 21 with StepScope

use of org.springframework.batch.core.configuration.annotation.StepScope in project microservices by pwillhan.

the class BatchConfiguration method flatFileItemReader.

@Bean
@StepScope
FlatFileItemReader<Person> flatFileItemReader(@Value("#{jobParameters[file]}") File file) {
    FlatFileItemReader<Person> r = new FlatFileItemReader<>();
    r.setResource(new FileSystemResource(file));
    r.setLineMapper(new DefaultLineMapper<Person>() {

        {
            this.setLineTokenizer(new DelimitedLineTokenizer(",") {

                {
                    this.setNames(new String[] { "first", "last", "email" });
                }
            });
            this.setFieldSetMapper(new BeanWrapperFieldSetMapper<Person>() {

                {
                    this.setTargetType(Person.class);
                }
            });
        }
    });
    return r;
}
Also used : FlatFileItemReader(org.springframework.batch.item.file.FlatFileItemReader) DelimitedLineTokenizer(org.springframework.batch.item.file.transform.DelimitedLineTokenizer) FileSystemResource(org.springframework.core.io.FileSystemResource) BeanWrapperFieldSetMapper(org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper) StepScope(org.springframework.batch.core.configuration.annotation.StepScope) Bean(org.springframework.context.annotation.Bean)

Example 22 with StepScope

use of org.springframework.batch.core.configuration.annotation.StepScope in project RecordManager2 by moravianlibrary.

the class FilterCaslinRecordsBySiglaJobConfig method caslinRecordsReader.

@Bean(name = Constants.JOB_ID_FILTER_CASLIN + ":caslinRecordsReader")
@StepScope
public synchronized ItemReader<HarvestedRecordUniqueId> caslinRecordsReader() throws Exception {
    JdbcPagingItemReader<HarvestedRecordUniqueId> reader = new JdbcPagingItemReader<HarvestedRecordUniqueId>();
    SqlPagingQueryProviderFactoryBean pqpf = new SqlPagingQueryProviderFactoryBean();
    pqpf.setDataSource(dataSource);
    pqpf.setSelectClause("SELECT import_conf_id, record_id");
    pqpf.setFromClause("FROM harvested_record");
    pqpf.setWhereClause("WHERE import_conf_id = :conf_id and deleted is null");
    pqpf.setSortKey("record_id");
    Map<String, Object> parameterValues = new HashMap<String, Object>();
    parameterValues.put("conf_id", Constants.IMPORT_CONF_ID_CASLIN);
    reader.setParameterValues(parameterValues);
    reader.setRowMapper(new HarvestedRecordIdRowMapper());
    reader.setPageSize(20);
    reader.setQueryProvider(pqpf.getObject());
    reader.setDataSource(dataSource);
    reader.afterPropertiesSet();
    return reader;
}
Also used : HarvestedRecordUniqueId(cz.mzk.recordmanager.server.model.HarvestedRecord.HarvestedRecordUniqueId) SqlPagingQueryProviderFactoryBean(org.springframework.batch.item.database.support.SqlPagingQueryProviderFactoryBean) HashMap(java.util.HashMap) HarvestedRecordIdRowMapper(cz.mzk.recordmanager.server.export.HarvestedRecordIdRowMapper) JdbcPagingItemReader(org.springframework.batch.item.database.JdbcPagingItemReader) StepScope(org.springframework.batch.core.configuration.annotation.StepScope) SqlPagingQueryProviderFactoryBean(org.springframework.batch.item.database.support.SqlPagingQueryProviderFactoryBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

StepScope (org.springframework.batch.core.configuration.annotation.StepScope)22 Bean (org.springframework.context.annotation.Bean)22 SqlPagingQueryProviderFactoryBean (org.springframework.batch.item.database.support.SqlPagingQueryProviderFactoryBean)18 JdbcPagingItemReader (org.springframework.batch.item.database.JdbcPagingItemReader)17 HashMap (java.util.HashMap)14 HarvestedRecordUniqueId (cz.mzk.recordmanager.server.model.HarvestedRecord.HarvestedRecordUniqueId)7 HarvestedRecordIdRowMapper (cz.mzk.recordmanager.server.export.HarvestedRecordIdRowMapper)5 HarvestedRecord (cz.mzk.recordmanager.server.model.HarvestedRecord)4 Date (java.util.Date)4 LongValueRowMapper (cz.mzk.recordmanager.server.jdbc.LongValueRowMapper)3 FileSystemResource (org.springframework.core.io.FileSystemResource)3 Timestamp (java.sql.Timestamp)2 Transaction (org.baeldung.batch.model.Transaction)2 JobRepositoryFactoryBean (org.springframework.batch.core.repository.support.JobRepositoryFactoryBean)2 FlatFileItemReader (org.springframework.batch.item.file.FlatFileItemReader)2 DelimitedLineTokenizer (org.springframework.batch.item.file.transform.DelimitedLineTokenizer)2 Cosmotron996RowMapper (cz.mzk.recordmanager.server.jdbc.Cosmotron996RowMapper)1 DedupRecordRowMapper (cz.mzk.recordmanager.server.jdbc.DedupRecordRowMapper)1 Cosmotron996 (cz.mzk.recordmanager.server.model.Cosmotron996)1 DedupRecord (cz.mzk.recordmanager.server.model.DedupRecord)1