-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: ๐ ์ ๊ธฐ ํธ์ ์๋ฆผ ๋ฐฐ์น ์ฟผ๋ฆฌ ํฝ์ค & ItemReader ๊ธฐ๋ฅ ์์ (#140)
* fix: device_token_owner dto query ์ต์ ํ๋ฅผ ์ํ device_token pk ํ๋ ์ถ๊ฐ * fix: querydsl_no_offset_string_options id_name ๋ฐ๋ ์ ์ ํฉํ ๋ฆฌ ๋ฉ์๋์์ field=null ์์ * fix: query dsl no offset paging item reader id_select_query ์ถ๊ฐ * feat: step builder ํจํด์ ์ ์ฉํ querydsl_no_offset_paging_item_reader_builder ํด๋์ค ์ ์ * fix: active_device_token_reader query ์์
- Loading branch information
1 parent
ab0de1e
commit 6bd74c2
Showing
5 changed files
with
166 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
129 changes: 129 additions & 0 deletions
129
...main/java/kr/co/pennyway/batch/common/reader/QuerydslNoOffsetPagingItemReaderBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
package kr.co.pennyway.batch.common.reader; | ||
|
||
import com.querydsl.jpa.impl.JPAQuery; | ||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import jakarta.persistence.EntityManagerFactory; | ||
import kr.co.pennyway.batch.common.reader.options.QuerydslNoOffsetOptions; | ||
|
||
import java.util.function.Function; | ||
|
||
/** | ||
* {@link QuerydslNoOffsetPagingItemReader}๋ฅผ ์์ฑํ๊ธฐ ์ํ ๋น๋ ํด๋์ค | ||
* <p> | ||
* Step Builder ํจํด์ ์ฌ์ฉํ์์ผ๋ฉฐ, ๊ฐ ๋ฉ์๋๋ ํด๋นํ๋ ์ค์ ๊ฐ์ ์ค์ ํ๊ณ ๋ค์ ๋จ๊ณ์ ๋น๋๋ฅผ ๋ฐํํ๋ค. | ||
* | ||
* @author YANG JAESEO | ||
*/ | ||
public class QuerydslNoOffsetPagingItemReaderBuilder<T> { | ||
private QuerydslNoOffsetPagingItemReaderBuilder() { | ||
} | ||
|
||
public static <T> EntityManagerFactoryStep<T> builder() { | ||
return new Steps<>(); | ||
} | ||
|
||
public interface EntityManagerFactoryStep<T> { | ||
/** | ||
* The {@link EntityManagerFactory} to be used for executing the configured queryFunction. | ||
* | ||
* @param emf {@link EntityManagerFactory} used to create | ||
* {@link jakarta.persistence.EntityManager} | ||
* @return this instance for method chaining | ||
*/ | ||
PageSizeStep<T> entityManagerFactory(EntityManagerFactory emf); | ||
} | ||
|
||
public interface PageSizeStep<T> { | ||
/** | ||
* The number of items to be read with each page. | ||
* | ||
* @param pageSize number of items | ||
* @return this instance for method chaining | ||
*/ | ||
OptionsStep<T> pageSize(int pageSize); | ||
} | ||
|
||
public interface OptionsStep<T> { | ||
/** | ||
* The {@link QuerydslNoOffsetOptions} to be used for configuring the reader. | ||
* | ||
* @param options {@link QuerydslNoOffsetOptions} to be used | ||
* @return this instance for method chaining | ||
*/ | ||
QueryFunctionStep<T> options(QuerydslNoOffsetOptions<T> options); | ||
} | ||
|
||
public interface QueryFunctionStep<T> { | ||
/** | ||
* The function that creates the query to be executed. | ||
* | ||
* @param queryFunction function that creates the query | ||
* @return this instance for method chaining | ||
*/ | ||
BuildStep<T> queryFunction(Function<JPAQueryFactory, JPAQuery<T>> queryFunction); | ||
} | ||
|
||
public interface BuildStep<T> { | ||
/** | ||
* The function that creates the query to be executed to select the currentId and lastId. | ||
* This is used to determine the currentId when the reader is not on the last page. | ||
* If this is not provided, the reader will use the queryFunction to determine the currentId and lastId. | ||
* | ||
* @param idSelectQuery function that creates the query to select the currentId and lastId | ||
* @return this instance for method chaining | ||
*/ | ||
BuildStep<T> idSelectQuery(Function<JPAQueryFactory, JPAQuery<T>> idSelectQuery); | ||
|
||
QuerydslNoOffsetPagingItemReader<T> build(); | ||
} | ||
|
||
private static class Steps<T> implements | ||
EntityManagerFactoryStep<T>, PageSizeStep<T>, OptionsStep<T>, QueryFunctionStep<T>, BuildStep<T> { | ||
private EntityManagerFactory entityManagerFactory; | ||
private int pageSize; | ||
private QuerydslNoOffsetOptions<T> options; | ||
private Function<JPAQueryFactory, JPAQuery<T>> queryFunction; | ||
private Function<JPAQueryFactory, JPAQuery<T>> idSelectQuery; | ||
|
||
@Override | ||
public PageSizeStep<T> entityManagerFactory(EntityManagerFactory emf) { | ||
this.entityManagerFactory = emf; | ||
return this; | ||
} | ||
|
||
@Override | ||
public OptionsStep<T> pageSize(int pageSize) { | ||
this.pageSize = pageSize; | ||
return this; | ||
} | ||
|
||
@Override | ||
public QueryFunctionStep<T> options(QuerydslNoOffsetOptions<T> options) { | ||
this.options = options; | ||
return this; | ||
} | ||
|
||
@Override | ||
public BuildStep<T> queryFunction(Function<JPAQueryFactory, JPAQuery<T>> queryFunction) { | ||
this.queryFunction = queryFunction; | ||
return this; | ||
} | ||
|
||
@Override | ||
public BuildStep<T> idSelectQuery(Function<JPAQueryFactory, JPAQuery<T>> idSelectQuery) { | ||
this.idSelectQuery = idSelectQuery; | ||
return this; | ||
} | ||
|
||
@Override | ||
public QuerydslNoOffsetPagingItemReader<T> build() { | ||
return new QuerydslNoOffsetPagingItemReader<>( | ||
entityManagerFactory, | ||
pageSize, | ||
options, | ||
queryFunction, | ||
idSelectQuery | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters