Skip to content

Commit

Permalink
YEL-214 [feat] formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
hyeonjeongs committed Feb 29, 2024
1 parent 03a9898 commit a5f02fb
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import com.yello.server.domain.user.entity.User;
import lombok.RequiredArgsConstructor;
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
import org.springframework.batch.item.ItemProcessor;
import org.springframework.context.annotation.Configuration;

Expand All @@ -12,7 +11,7 @@
public class ChunkProcessor {
public ItemProcessor<User, User> lunchEventProcessor() {
ItemProcessor<User, User> item = user -> {
System.out.println(user.getId() + ", "+ user.getName() + " dds121212");
System.out.println(user.getId() + ", " + user.getName() + " dds121212");
return user;
};
return item;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,12 @@
import com.yello.server.domain.user.entity.User;
import com.yello.server.domain.user.repository.UserJpaRepository;
import jakarta.persistence.EntityManagerFactory;
import java.util.Collections;
import javax.sql.DataSource;
import lombok.RequiredArgsConstructor;
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
import org.springframework.batch.core.configuration.annotation.StepScope;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.data.RepositoryItemReader;
import org.springframework.batch.item.data.builder.RepositoryItemReaderBuilder;
import org.springframework.batch.item.database.JdbcCursorItemReader;
import org.springframework.batch.item.database.JdbcPagingItemReader;
import org.springframework.batch.item.database.JpaPagingItemReader;
import org.springframework.batch.item.database.Order;
import org.springframework.batch.item.database.PagingQueryProvider;
import org.springframework.batch.item.database.*;
import org.springframework.batch.item.database.builder.JdbcCursorItemReaderBuilder;
import org.springframework.batch.item.database.builder.JdbcPagingItemReaderBuilder;
import org.springframework.batch.item.database.builder.JpaPagingItemReaderBuilder;
Expand All @@ -25,6 +18,9 @@
import org.springframework.data.domain.Sort;
import org.springframework.jdbc.core.BeanPropertyRowMapper;

import javax.sql.DataSource;
import java.util.Collections;

@Configuration
@RequiredArgsConstructor
public class ChunkReader {
Expand All @@ -38,22 +34,22 @@ public class ChunkReader {
public RepositoryItemReader<User> usersDataRepositoryItemReader() {

return new RepositoryItemReaderBuilder<User>()
.name("userDataReader")
.repository(userRepository)
.methodName("findAllByPageable")
.pageSize(100)
.sorts(Collections.singletonMap("id", Sort.Direction.ASC))
.build();
.name("userDataReader")
.repository(userRepository)
.methodName("findAllByPageable")
.pageSize(100)
.sorts(Collections.singletonMap("id", Sort.Direction.ASC))
.build();
}

public JdbcCursorItemReader<User> jdbcCursorItemReader() {
return new JdbcCursorItemReaderBuilder<User>()
.fetchSize(10)
.dataSource(dataSource)
.rowMapper(new BeanPropertyRowMapper<>(User.class))
.sql("SELECT u.id, u.name FROM user u WHERE u.deleted_at is NULL ORDER BY u.id")
.name("jdbcCursorItemReader")
.build();
.fetchSize(10)
.dataSource(dataSource)
.rowMapper(new BeanPropertyRowMapper<>(User.class))
.sql("SELECT u.id, u.name FROM user u WHERE u.deleted_at is NULL ORDER BY u.id")
.name("jdbcCursorItemReader")
.build();
}

@Bean
Expand All @@ -72,25 +68,25 @@ public ItemReader<User> userDataItemReader() {
public JpaPagingItemReader<User> userDataJpaPagingItemReader() {

return new JpaPagingItemReaderBuilder<User>()
.name("userDataReader")
.pageSize(100)
.queryString("SELECT u FROM User u WHERE deletedAt is NULL ORDER BY id")
.entityManagerFactory(entityManagerFactory)
.build();
.name("userDataReader")
.pageSize(100)
.queryString("SELECT u FROM User u WHERE deletedAt is NULL ORDER BY id")
.entityManagerFactory(entityManagerFactory)
.build();
}

@Bean
@StepScope
public JdbcPagingItemReader<User> userDataJdbcPagingItemReader() throws Exception {

return new JdbcPagingItemReaderBuilder<User>()
.pageSize(100)
.fetchSize(100)
.dataSource(dataSource)
.queryProvider(createUserDataQueryProvider())
.rowMapper(new UserRowMapper())
.name("jdbcPagingItemReader")
.build();
.pageSize(100)
.fetchSize(100)
.dataSource(dataSource)
.queryProvider(createUserDataQueryProvider())
.rowMapper(new UserRowMapper())
.name("jdbcPagingItemReader")
.build();
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.yello.server.domain.user.entity.User;
import com.yello.server.infrastructure.firebase.service.NotificationService;
import lombok.RequiredArgsConstructor;
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
import org.springframework.batch.core.configuration.annotation.StepScope;
import org.springframework.batch.item.ItemWriter;
import org.springframework.context.annotation.Bean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
import org.springframework.batch.core.job.builder.JobBuilder;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.context.annotation.Bean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
import org.springframework.batch.core.configuration.annotation.JobScope;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.step.builder.StepBuilder;
Expand All @@ -24,11 +23,11 @@ public class StepConfiguration {
@Bean
@JobScope
public Step lunchEventAlarmStep(JobRepository jobRepository,
PlatformTransactionManager transactionManager) throws Exception {
PlatformTransactionManager transactionManager) throws Exception {
return new StepBuilder("lunchEventStep", jobRepository)
.<User, User>chunk(100, transactionManager)
.reader(chunkReader.userDataJdbcPagingItemReader())
.writer(chunkWriter.lunchEventWriter())
.build();
.<User, User>chunk(100, transactionManager)
.reader(chunkReader.userDataJdbcPagingItemReader())
.writer(chunkWriter.lunchEventWriter())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
package com.yello.server.infrastructure.scheduler;


import com.yello.server.domain.user.entity.User;
import com.yello.server.domain.user.entity.UserData;
import com.yello.server.domain.user.entity.UserDataType;
import com.yello.server.domain.user.repository.UserDataRepository;
import com.yello.server.infrastructure.batch.JobConfiguration;
import lombok.RequiredArgsConstructor;
import org.springframework.batch.core.JobParameter;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.JobParametersBuilder;
import org.springframework.batch.core.JobParametersInvalidException;
Expand All @@ -19,9 +14,6 @@
import org.springframework.stereotype.Component;
import org.springframework.transaction.PlatformTransactionManager;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

@Component
Expand All @@ -32,9 +24,8 @@ public class EventScheduler {
private final JobConfiguration jobConfiguration;
private final JobRepository jobRepository;
private final PlatformTransactionManager transactionManager;
private final UserDataRepository userDataRepository;

@Scheduled(cron="0 58 10 * * ?")
@Scheduled(cron = "0 0 12 * * ?")
public void lunchEventRunJob() {

//JobParamter의 역할은 반복해서 실행되는 Job의 유일한 ID임, 동일한 값이 세팅되면 두번째부터 실행안됨)
Expand Down

0 comments on commit a5f02fb

Please sign in to comment.