Kotlin JDSL

Latest stable version: 3.5.4

What is Kotlin JDSL?

Kotlin JDSL์€ ๋ฉ”ํƒ€๋ชจ๋ธ ์—†์ด ์ฟผ๋ฆฌ๋ฅผ ์‰ฝ๊ฒŒ ๋งŒ๋“ค ์ˆ˜ ์žˆ๊ฒŒ ๋„์™€์ฃผ๋Š” Kotlin ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์ž…๋‹ˆ๋‹ค. ์ด๋ฏธ Annotation Processor Tool (APT)์„ ์ด์šฉํ•ด์„œ ์ฟผ๋ฆฌ๋ฅผ ์‰ฝ๊ฒŒ ๋งŒ๋“ค๋„๋ก ๋„์™€์ฃผ๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋Š” ๋งŽ์ด ์žˆ์Šต๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ APT๋ฅผ ์ด์šฉํ•˜๋ฉด ํด๋ž˜์Šค๋ช…์ด๋‚˜ ํ•„๋“œ๋ช…์ด ๋ณ€๊ฒฝ๋˜์—ˆ์„ ๋•Œ๋งˆ๋‹ค ๋‹ค์‹œ ์ปดํŒŒ์ผ ํ•ด์•ผ ํ•˜๋Š” ๋ถˆํŽธํ•จ์ด ์žˆ์Šต๋‹ˆ๋‹ค. Kotlin JDSL์€ ์ด๋Ÿฐ ๋ถˆํŽธํ•จ์„ ํ•ด์†Œํ•˜๋ฉด์„œ ์‰ฝ๊ฒŒ ์ฟผ๋ฆฌ๋ฅผ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋„๋ก KClass์™€ KProperty ๊ธฐ๋ฐ˜์˜ Domain-Specific Language๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.

Kotlin JDSL์€ ์ƒˆ๋กœ์šด DB ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๊ฐ€ ์•„๋‹Œ DB ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•  ๋•Œ ๋„์›€์„ ์ฃผ๊ธฐ ์œ„ํ•ด์„œ ๋งŒ๋“ค์–ด์ง„ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์ด๊ธฐ ๋•Œ๋ฌธ์— ์ง์ ‘ ์ฟผ๋ฆฌ๋ฅผ ์‹คํ–‰ํ•˜๊ฑฐ๋‚˜ DB ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ๋ž˜ํ•‘ํ•˜๋Š” ๋“ฑ์˜ ์ž‘์—…์€ ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

Supports

JPQL

val context = JpqlRenderContext()

val query = jpql {
    select(
        path(Author::authorId),
    ).from(
        entity(Author::class),
        join(BookAuthor::class).on(path(Author::authorId).equal(path(BookAuthor::authorId))),
    ).groupBy(
        path(Author::authorId),
    ).orderBy(
        count(Author::authorId).desc(),
    )
}

val `the most prolific author` = entityManager.createQuery(query, context).apply {
    maxResults = 1
}

JPQL์— ๋Œ€ํ•ด ๋” ๊ถ๊ธˆํ•˜์‹œ๋ฉด ์—ฌ๊ธฐ๋ฅผ ์ฐธ๊ณ ํ•ด์ฃผ์„ธ์š”.

Last updated