Skip to content

spring batch#6

Open
Bael wants to merge 3 commits into
masterfrom
spring_batch
Open

spring batch#6
Bael wants to merge 3 commits into
masterfrom
spring_batch

Conversation

@Bael
Copy link
Copy Markdown
Owner

@Bael Bael commented Nov 19, 2018

ДЗ #14, spring batch. запускается на старте приложения

ru.otus.spring.hw.kanban.domain.mongo.Board mongoBoard = new ru.otus.spring.hw.kanban.domain.mongo.Board();
mongoBoard.setName(board.getName());

List<Stage> stages = stageRepository.findStagesByBoard(board);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Делать запрос внутри Processor не совсем правильно, лучше будет сконфигурировать reader таким образом чтобы он сразу доставал stages.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

тут не понял как это сделать, если мы уже готовый пакетный ридер возвращаем. делать fetchtype - eager не хочется.


@Bean
public ItemReader<Board> reader() {
return new ItemReader<Board>() {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Кстати кастомный ридер здесь совсем не обязательно, spring batch очень крут тем что имеет много готовых компонентов для большинства задач.

Copy link
Copy Markdown
Owner Author

@Bael Bael Nov 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

применил RepositoryItemReader


@Bean
public ItemWriter<ru.otus.spring.hw.kanban.domain.mongo.Board> writer() {
return items -> items.forEach(o -> boardMongoRepository.save(o));
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Вот так точно не надо делать :) даже если мы пишем кастомный writer, есть repository.saveAll(). А вообще здесь легко будет использовать MongoItemWriter.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

переделал на монго итем врайтер

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants