package com.drumonii.loltrollbuild.batch.versions;

import com.drumonii.loltrollbuild.model.Version;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
import org.springframework.batch.core.configuration.annotation.StepScope;
import org.springframework.batch.core.launch.support.RunIdIncrementer;
import org.springframework.batch.item.ItemProcessor;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.item.database.BeanPropertyItemSqlParameterSourceProvider;
import org.springframework.batch.item.database.builder.JdbcBatchItemWriterBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

/**
 * {@link Job} configuration for retrieving the latest {@link Version} data from Riot's API.
 */
@Configuration
public class VersionsRetrievalJobConfig {

	@Autowired
	private JobBuilderFactory jobBuilderFactory;

	@Autowired
	private StepBuilderFactory stepBuilderFactory;

	@Autowired
	private DataSource dataSource;

	@Bean
	public Job versionsRetrievalJob() {
		return jobBuilderFactory.get("versionsRetrievalJob")
				.incrementer(new RunIdIncrementer())
				.start(versionsRetrievalStep())
				.build();
	}

	@Bean
	public Step versionsRetrievalStep() {
		return stepBuilderFactory.get("versionsRetrievalStep")
				.<Version, Version> chunk(25)
				.reader(versionsRetrievalItemReader())
				.processor(versionsRetrievalItemProcessor())
				.writer(versionsRetrievalItemWriter())
				.build();
	}

	@StepScope
	@Bean
	public VersionsRetrievalItemReader versionsRetrievalItemReader() {
		return new VersionsRetrievalItemReader();
	}

	@Bean
	public ItemProcessor<Version, Version> versionsRetrievalItemProcessor() {
		return new VersionsRetrievalItemProcessor();
	}

	@Bean
	public ItemWriter<Version> versionsRetrievalItemWriter() {
		return new JdbcBatchItemWriterBuilder<Version>()
				.dataSource(dataSource)
				.sql("INSERT INTO VERSION (PATCH, MAJOR, MINOR, REVISION) VALUES (:patch, :major, :minor, :revision)")
				.itemSqlParameterSourceProvider(new BeanPropertyItemSqlParameterSourceProvider<>())
				.assertUpdates(false)
				.build();
	}

}

@@ -598,99 +598,8 @@
 er;%0A
-import org.springframework.batch.item.database.BeanPropertyItemSqlParameterSourceProvider;%0A
 impo
@@ -2222,89 +2222,19 @@
 %09%09%09.
-itemSqlParameterSourceProvider(new BeanPropertyItemSqlParameterSourceProvider%3C%3E()
+beanMapped(
 )%0A%09%09

Use beanMapped in jdbc item writer builder