国产xxxx99真实实拍_久久不雅视频_高清韩国a级特黄毛片_嗯老师别我我受不了了小说

資訊專欄INFORMATION COLUMN

spring-batch實(shí)例

MycLambert / 1124人閱讀

config
@EnableBatchProcessing(modular = true)
@Configuration
public class BatchConfig {

    private static final Logger LOGGER = LoggerFactory.getLogger(BatchConfig.class);


    @Bean
    public Job importUserJob(JobBuilderFactory jobs, Step s1, JobExecutionListener listener) {
        return jobs.get("importUserJob")
                .incrementer(new RunIdIncrementer())
                .listener(listener)
                .flow(s1)
                .end()
                .build();
    }

    @Bean
    public Step step1(StepBuilderFactory stepBuilderFactory, ItemReader reader,
                      ItemWriter writer, ItemProcessor processor) {
        return stepBuilderFactory.get("step1")
                .chunk(5)
                .reader(reader)
                .processor(processor)
                .writer(writer)
                .build();
    }

    @Bean
    public JdbcTemplate jdbcTemplate(DataSource dataSource) {
        return new JdbcTemplate(dataSource);
    }

    @Bean
    public ItemReader reader(DataSource dataSource) {
        JdbcCursorItemReader reader = new JdbcCursorItemReader();
        reader.setSql("select id, first_name, last_name, random_num from reader");
        reader.setDataSource(dataSource);
        reader.setRowMapper(
                (ResultSet resultSet, int rowNum) -> {
                    LOGGER.info("RowMapper resultset: {}", resultSet);
                    if (!(resultSet.isAfterLast()) && !(resultSet.isBeforeFirst())) {
                        RecordSO recordSO = new RecordSO();
                        recordSO.setFirstName(resultSet.getString("first_name"));
                        recordSO.setLastName(resultSet.getString("last_name"));
                        recordSO.setId(resultSet.getLong("id"));
                        recordSO.setRandomNum(resultSet.getString("random_num"));

                        LOGGER.info("RowMapper record : {}", recordSO);
                        return recordSO;
                    } else {
                        LOGGER.info("Returning null from rowMapper");
                        return null;
                    }
                });
        return reader;
    }

    @Bean
    public ItemPreparedStatementSetter setter() {
        return (item, ps) -> {
            ps.setLong(1, item.getId());
            ps.setString(2, item.getFullName());
            ps.setString(3, item.getRandomNum());
        };
    }

    @Bean
    public ItemProcessor processor() {
        return new RecordProcessor();
    }

    @Bean
    public ItemWriter writer(DataSource dataSource, ItemPreparedStatementSetter setter) {
        JdbcBatchItemWriter writer = new JdbcBatchItemWriter<>();
        writer.setItemSqlParameterSourceProvider(new BeanPropertyItemSqlParameterSourceProvider());
        writer.setItemPreparedStatementSetter(setter);
        writer.setSql("insert into writer (id, full_name, random_num) values (?,?,?)");
        writer.setDataSource(dataSource);
        return writer;
    }
}
model
@Entity
@Table(name = "reader")
public class RecordSO {

    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    private Long id;

    private String firstName;
    private String lastName;
    private String randomNum;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public String getRandomNum() {
        return randomNum;
    }

    public void setRandomNum(String randomNum) {
        this.randomNum = randomNum;
    }
}

@Entity
@Table(name = "writer")
public class WriterSO {

    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    private Long id;
    private String fullName;
    private String randomNum;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getFullName() {
        return fullName;
    }

    public void setFullName(String fullName) {
        this.fullName = fullName;
    }

    public String getRandomNum() {
        return randomNum;
    }

    public void setRandomNum(String randomNum) {
        this.randomNum = randomNum;
    }
}
application.properties
spring.datasource.driverClassName=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://192.168.99.100:5432/batch
spring.datasource.username=postgres
spring.datasource.password=mypwd

##spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.show-sql=true
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
processor
public class RecordProcessor implements ItemProcessor {

    private static final Logger LOGGER = LoggerFactory.getLogger(RecordProcessor.class);

    @Override
    public WriterSO process(RecordSO item) throws Exception {
        LOGGER.info("Processing Record: {}", item);
        WriterSO writerSo = new WriterSO();
        writerSo.setId(item.getId());
        writerSo.setFullName(item.getFirstName() + " " + item.getLastName());
        writerSo.setRandomNum(String.valueOf(Math.random()).substring(3, 8));
        LOGGER.info("Processed Writer: {}", writerSo);
        return writerSo;
    }
}
docs

spring-boot-batch-starter-example

spring-batch

spring-batch-admin-spring-boot

spring-batch-tutorial-with-spring-boot-and-java-configuration

文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請(qǐng)注明本文地址:http://m.specialneedsforspecialkids.com/yun/65019.html

相關(guān)文章

  • 阿里云服務(wù)器各實(shí)例規(guī)格名稱的含義,實(shí)例規(guī)格是怎么選擇?

    摘要:阿里云實(shí)例規(guī)格級(jí)別有哪些云服務(wù)器實(shí)例規(guī)格族可分為企業(yè)級(jí)實(shí)例規(guī)格族和入門級(jí)實(shí)例規(guī)格族。選購(gòu)云服務(wù)器時(shí),需要選擇云服務(wù)器實(shí)例的規(guī)格信息實(shí)例規(guī)格族,也就是配置信息,實(shí)例規(guī)格族涉及到架構(gòu)分類和應(yīng)用場(chǎng)景等。阿里云ecs各實(shí)例規(guī)格名稱的含義,實(shí)例規(guī)格是什么。 我們?cè)诹私夂唾?gòu)買阿里云產(chǎn)品的時(shí)候,實(shí)例、實(shí)例規(guī)格是出現(xiàn)比較多的,所以有必要從概念和作用方面做個(gè)了解: 1、阿里云實(shí)例規(guī)格族包括哪些類型? (1)阿...

    nanchen2251 評(píng)論0 收藏0
  • 刨刨 Carbon API

    摘要:介紹是對(duì)模塊的二次擴(kuò)展提供時(shí)間格式化,時(shí)間計(jì)算的功能官方主頁為地址為文件結(jié)構(gòu)目錄描述源文件源文件類的二次擴(kuò)展類主要用于時(shí)差計(jì)算類的二次擴(kuò)展類提供時(shí)間計(jì)算,格式化輸出的功能自定義異常文件夾語言本地化文件夾類的方法會(huì)用到 介紹 Carbon是對(duì)PHP DateTime模塊的二次擴(kuò)展;提供時(shí)間格式化,時(shí)間計(jì)算的功能; 官方主頁為 http://carbon.nesbot.com/; Git...

    Yuqi 評(píng)論0 收藏0
  • 阿里云服務(wù)器必須要建實(shí)例

    摘要:阿里云服務(wù)器必須要建實(shí)例嗎,阿里云服務(wù)器實(shí)例。我們來看看這次阿里云的云服務(wù)器折活動(dòng)有什么需要注意的阿里云云服務(wù)器折起的活動(dòng)什么時(shí)候結(jié)束目前得到的信息是,首購(gòu)折的活動(dòng)是長(zhǎng)期有效的喲。阿里云服務(wù)器必須要建實(shí)例嗎,阿里云ecs服務(wù)器實(shí)例。 接觸和使用阿里云服務(wù)器、阿里云數(shù)據(jù)庫,我們對(duì)阿里云實(shí)例并不陌生,對(duì)于剛使用阿里云服務(wù)的親來說,阿里云實(shí)例的基礎(chǔ)知識(shí)可以做個(gè)了解: 1、什么是阿里云實(shí)例,阿里云實(shí)...

    pubdreamcc 評(píng)論0 收藏0
  • 小白應(yīng)該如何快速入門阿里云服務(wù)器,新手使用ECS的方法

    摘要:今天呢,服務(wù)器吧小編就給剛接觸阿里云的新手小白帶來快速入門阿里云服務(wù)器的方法。注冊(cè)阿里云賬號(hào),并完成實(shí)名認(rèn)證。教你如何格式化阿里云服務(wù)器數(shù)據(jù)盤第六步釋放實(shí)例。相信阿里云服務(wù)器ECS已被廣大的企業(yè)和個(gè)人站長(zhǎng)所使用,但對(duì)于之前沒有使用過阿里云服務(wù)器的新手小白來說,無疑是一頭霧水。今天呢,服務(wù)器吧小編就給剛接觸阿里云ECS的新手小白帶來快速入門阿里云服務(wù)器的方法。請(qǐng)往下看! 第一步:完成準(zhǔn)備工作...

    Pikachu 評(píng)論0 收藏0

發(fā)表評(píng)論

0條評(píng)論

最新活動(dòng)
閱讀需要支付1元查看
<