Search in sources :

Example 1 with User

use of com.ask.springbatch.entity.User in project tutorials by csh0034.

the class JdbcCursorItemReaderJobConfig method jdbcCursorItemReader.

@Bean
@StepScope
public JdbcCursorItemReader<User> jdbcCursorItemReader() {
    return new JdbcCursorItemReaderBuilder<User>().name("jdbcCursorItemReader").fetchSize(CHUNK_SIZE).dataSource(dataSource).rowMapper((rs, rowNum) -> {
        User user = User.create(rs.getString("name"), rs.getString("password"), rs.getBoolean("enabled"));
        user.setId(rs.getString("user_id"));
        return user;
    }).sql("SELECT user_id, name, password, enabled FROM tb_user").build();
}
Also used : User(com.ask.springbatch.entity.User) JdbcCursorItemReaderBuilder(org.springframework.batch.item.database.builder.JdbcCursorItemReaderBuilder) StepScope(org.springframework.batch.core.configuration.annotation.StepScope) Bean(org.springframework.context.annotation.Bean)

Example 2 with User

use of com.ask.springbatch.entity.User in project tutorials by csh0034.

the class MigrationUserJobConfig method defaultLineMapper.

private DefaultLineMapper<User> defaultLineMapper() {
    DefaultLineMapper<User> defaultLineMapper = new DefaultLineMapper<>();
    defaultLineMapper.setLineTokenizer(new DelimitedLineTokenizer());
    defaultLineMapper.setFieldSetMapper(fieldSet -> User.create(fieldSet.readString(0), fieldSet.readString(1), fieldSet.readBoolean(2, "1")));
    return defaultLineMapper;
}
Also used : DelimitedLineTokenizer(org.springframework.batch.item.file.transform.DelimitedLineTokenizer) User(com.ask.springbatch.entity.User) DefaultLineMapper(org.springframework.batch.item.file.mapping.DefaultLineMapper)

Aggregations

User (com.ask.springbatch.entity.User)2 StepScope (org.springframework.batch.core.configuration.annotation.StepScope)1 JdbcCursorItemReaderBuilder (org.springframework.batch.item.database.builder.JdbcCursorItemReaderBuilder)1 DefaultLineMapper (org.springframework.batch.item.file.mapping.DefaultLineMapper)1 DelimitedLineTokenizer (org.springframework.batch.item.file.transform.DelimitedLineTokenizer)1 Bean (org.springframework.context.annotation.Bean)1