Skip to content

Commit

Permalink
test: stream 활용
Browse files Browse the repository at this point in the history
  • Loading branch information
belljun3395 committed Jan 15, 2025
1 parent c54ee6b commit 853b2ff
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 50 deletions.
20 changes: 4 additions & 16 deletions api/src/main/kotlin/com/few/api/domain/article/repo/ArticleDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -138,22 +138,10 @@ class ArticleDao(
.and(ArticleIfo.ARTICLE_IFO.DELETED_AT.isNull)
.fetchOneInto(SelectArticleContentsRecord::class.java)

fun selectArticleContents(articleIds: Set<Long>): List<SelectArticleContentsRecord> {
return dslContext.transactionResult { configuration ->
val context = DSL.using(configuration)
return@transactionResult articleIds
.mapNotNull {
context
.select(
ArticleIfo.ARTICLE_IFO.ARTICLE_MST_ID.`as`(SelectArticleContentsRecord::articleId.name),
ArticleIfo.ARTICLE_IFO.CONTENT.`as`(SelectArticleContentsRecord::content.name),
).from(ArticleIfo.ARTICLE_IFO)
.where(ArticleIfo.ARTICLE_IFO.ARTICLE_MST_ID.eq(it))
.and(ArticleIfo.ARTICLE_IFO.DELETED_AT.isNull)
.fetchOneInto(SelectArticleContentsRecord::class.java)
}.toList()
}
}
fun selectArticleContents(articleIds: Set<Long>): List<SelectArticleContentsRecord> =
selectArticleContentsQuery(articleIds)
.fetchStreamInto(SelectArticleContentsRecord::class.java)
.toList()

fun selectArticleContentsQuery(articleIds: Set<Long>) =
dslContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import jooq.jooq_dsl.tables.ArticleMainCard.ARTICLE_MAIN_CARD
import org.jooq.*
import org.jooq.impl.DSL.*
import org.springframework.stereotype.Repository
import java.util.stream.Collectors

@Repository
class ArticleMainCardDao(
Expand Down Expand Up @@ -45,40 +46,11 @@ class ArticleMainCardDao(
.fetch(articleMainCardMapper)
.firstOrNull()

fun selectArticleMainCardsRecord(articleIds: Set<Long>): Set<ArticleMainCardRecord> {
return dslContext.transactionResult { configuration ->
val context = using(configuration)
return@transactionResult articleIds
.mapNotNull {
context
.select(
ARTICLE_MAIN_CARD.ID.`as`(ArticleMainCardRecord::articleId.name),
ARTICLE_MAIN_CARD.TITLE.`as`(ArticleMainCardRecord::articleTitle.name),
ARTICLE_MAIN_CARD.MAIN_IMAGE_URL.`as`(ArticleMainCardRecord::mainImageUrl.name),
ARTICLE_MAIN_CARD.CATEGORY_CD.`as`(ArticleMainCardRecord::categoryCd.name),
ARTICLE_MAIN_CARD.CREATED_AT.`as`(ArticleMainCardRecord::createdAt.name),
ARTICLE_MAIN_CARD.WRITER_ID.`as`(ArticleMainCardRecord::writerId.name),
ARTICLE_MAIN_CARD.WRITER_EMAIL.`as`(ArticleMainCardRecord::writerEmail.name),
jsonGetAttributeAsText(
ARTICLE_MAIN_CARD.WRITER_DESCRIPTION,
"name",
).`as`(ArticleMainCardRecord::writerName.name),
jsonGetAttribute(
ARTICLE_MAIN_CARD.WRITER_DESCRIPTION,
"url",
).`as`(ArticleMainCardRecord::writerUrl.name),
jsonGetAttribute(
ARTICLE_MAIN_CARD.WRITER_DESCRIPTION,
"imageUrl",
).`as`(ArticleMainCardRecord::writerImgUrl.name),
ARTICLE_MAIN_CARD.WORKBOOKS.`as`(ArticleMainCardRecord::workbooks.name),
).from(ARTICLE_MAIN_CARD)
.where(ARTICLE_MAIN_CARD.ID.eq(it))
.fetch(articleMainCardMapper)
.firstOrNull()
}.toSet()
}
}
fun selectArticleMainCardsRecord(articleIds: Set<Long>): Set<ArticleMainCardRecord> =
selectArticleMainCardsRecordQuery(articleIds)
.fetchStream()
.map { articleMainCardMapper.map(it) }
.collect(Collectors.toSet())

fun selectArticleMainCardsRecordQuery(articleIds: Set<Long>) =
dslContext
Expand Down

0 comments on commit 853b2ff

Please sign in to comment.