Expressions
Kotlin JDSL์ JPQL์ expression๋ฅผ ํํํ๊ธฐ ์ํด Expression
์ธํฐํ์ด์ค๋ฅผ ๊ฐ์ง๊ณ ์์ต๋๋ค.
Alias
Expression
์ as()
๋ฅผ ํธ์ถํ๋ ๊ฒ์ผ๋ก Expression
์ alias๋ฅผ ๊ฑธ ์ ์์ต๋๋ค. expression()
์ ์ด์ฉํ๋ฉด Expression
์ ์ฐธ์กฐ๋ฅผ ๋ง๋ค ์ ์์ต๋๋ค. ์ฐธ์กฐ๋ alias๋ฅผ ํตํด์ ๊ตฌ๋ถ๋๋ฉฐ ๋์ผํ alias๋ฅผ ๊ฐ์ง๊ณ ์๋ Expression
์ ์ฐธ์กฐํ ์ ์์ต๋๋ค. ์ด๋ฅผ ํตํด Expression
์ alias๋ฅผ ๊ฑธ๊ณ alias๊ฐ ๊ฑธ๋ฆฐ Expression
์ ๋ค๋ฅธ clause์์ ์ฐธ์กฐํ ์ ์์ต๋๋ค.
Type Cast
์ด๋ค ๊ฒฝ์ฐ์๋ Expression
์ ํ์
์ ์ํ๋ ํ์
์ผ๋ก ๋ณ๊ฒฝํ๊ณ ์ถ์ ๋๊ฐ ์์ ๊ฒ์
๋๋ค. ์ด๋ฅผ ์ํด Kotlin JDSL์ as()
๋ฅผ ํตํด์ unsafe type casting์ ์ง์ํฉ๋๋ค.
This is a shortened form of as Expression<T>
, so it may not work as expected.
Arithmetic operations
์ฐ์ ์ฐ์ฐ์๋ฅผ ๋ง๋ค๊ธฐ ์ํด์๋ ๋ค์ ํจ์๋ค์ ์ฌ์ฉํ ์ ์์ต๋๋ค.
+ (plus)
- (minus)
* (times)
/ (div)
Parentheses
ํ์ฅ ํจ์๊ฐ ์๋ ์ผ๋ฐ ํจ์๋ฅผ ํธ์ถํ๋ ๊ฒ์ผ๋ก ์ฐ์ ์ฐ์ฐ์์ ์ฐ์ฐ ์์๋ฅผ ์ํ ์๊ดํธ๋ฅผ ์ถ๊ฐํ ์ ์์ต๋๋ค. ํ์ฅ ํจ์์ ๊ฒฝ์ฐ ์ฐ์ฐ ์์๊ฐ ๋ชจํธํด์ ์๊ดํธ๋ฅผ ์ถ๊ฐํ ์ ์์ต๋๋ค.
Values
๊ฐ์ ๋ง๋ค๊ธฐ ์ํด, value()
๋ฅผ ์ฌ์ฉํ ์ ์์ต๋๋ค. ๋ชจ๋ ๊ฐ์ ์ฟผ๋ฆฌ ํ๋ผ๋ฏธํฐ๋ก ์นํ๋๋ฉฐ, ์ด ํ๋ผ๋ฏธํฐ๋ ๋ณ๊ฒฝํ ์ ์์ต๋๋ค.
๋ง์ฝ KClass๊ฐ value()
์ ์ ๋ฌ๋๋ฉด ์ด๋ Entity๋ก ์ธ์๋ฉ๋๋ค.
Params
์ฟผ๋ฆฌ ํ๋ผ๋ฏธํฐ๋ฅผ ๋ง๋ค๊ธฐ ์ํด, value()
๋์ param()
์ ์ฌ์ฉํ ์ ์์ต๋๋ค. param()
์ผ๋ก ๋ง๋ค์ด์ง ํ๋ผ๋ฏธํฐ๋ ๋ณ๊ฒฝ์ด ๊ฐ๋ฅํฉ๋๋ค.
Literals
literal์ ๋ง๋ค๊ธฐ ์ํด, value()
๋์ xxxLiteral()
์ ์ด์ฉํ ์ ์์ต๋๋ค.
string literal์ ์ถ๋ ฅํ ๋ ๋ง์ฝ '(์์ ๋ฐ์ดํ)๊ฐ ์์ผ๋ฉด '(์์ ๋ฐ์ดํ)๋ ''(์์ ๋ฐ์ดํ 2๊ฐ)๋ก ๋ณ๊ฒฝ๋์ด ์ถ๋ ฅ๋ฉ๋๋ค. ์๋ก 'literal''s' ์ฒ๋ผ ์ถ๋ ฅ๋ฉ๋๋ค.
Int
intLiteral
{value}
Long
longLiteral
{value}L
Float
floatLiteral
{value}F
Double
doubleLiteral
{value}
Boolean
booleanLiteral
TRUE or FALSE
Char
charLiteral
'{value}'
String
stringLiteral
'{value}'
Enum
enumLiteral
{qualified name}.{enum name}
Aggregation functions
์งํฉ ํจ์๋ฅผ ๋ง๋ค๊ธฐ ์ํด, ๋ค์ ํจ์๋ค์ ์ฌ์ฉํ ์ ์์ต๋๋ค.
COUNT (count)
MIN (min)
MAX (max)
AVG (avg)
SUM (sum)
Sum
sum()
์ ํ๋ผ๋ฏธํฐ์ ๋ฐ๋ผ ๋ค๋ฅธ ๋ฐํ ํ์
์ ๊ฐ์ง๊ฒ ๋ฉ๋๋ค.
Int
Long
Long
Long
Float
Double
Double
Double
BigInteger
BigInteger
BigDecimal
BigDecimal
Functions
Kotlin JDSL์ JPA์์ ์ ๊ณตํ๋ ์ฌ๋ฌ ํจ์๋ค์ ์ง์ํ๊ธฐ ์ํ ํจ์๋ค์ ์ ๊ณตํฉ๋๋ค.
String functions
CONCAT (concat)
SUBSTRING (substring)
TRIM (trim)
LOWER (lower)
UPPER (upper)
LENGTH (length)
LOCATE (locate)
Arithmetic functions
ABS (abs)
CEILING (ceiling)
EXP (exp)
FLOOR (floor)
INDEX (index)
LN (ln)
MOD (mod)
POWER (power)
SIGN (sign)
SQRT (sqrt)
ROUND (round)
SIZE (size)
Datetime functions
CURRENT_DATE (currentDate)
CURRENT_TIME (currentTime)
CURRENT_TIMESTAMP (currentTimestamp)
LOCAL DATE (localDate)
LOCAL TIME (localTime)
LOCAL DATETIME (localDateTime)
Database function
DB ํจ์๋ ์ฌ์ฉ์ ์ ์ ํจ์๋ฅผ ๋ง๋ค๊ธฐ ์ํด, function()
์ ์ฌ์ฉํ ์ ์์ต๋๋ค.
์ฌ์ฉํ ํจ์์ ์ ๋ณด๋ฅผ JPA ์ ๊ณต์์ ๋ฑ๋กํ ํ์๊ฐ ์์ ์ ์์ต๋๋ค. ์๋ฅผ ๋ค์ด Hibernate๋ฅผ ์ฌ์ฉํ๊ณ ์๋ค๋ฉด FunctionContributor
๋ฅผ ๋ฐ๋์ ๋ฑ๋กํด์ผ ํฉ๋๋ค.
Cases
case๋ฅผ ๋ง๋ค๊ธฐ ์ํด, caseWhen()
๊ณผ caseValue()
๋ฅผ ์ฌ์ฉํ ์ ์์ต๋๋ค.
Coalesce
coalesce๋ฅผ ๋ง๋ค๊ธฐ ์ํด, coalesce()
์ ์ฌ์ฉํ ์ ์์ต๋๋ค.
NullIf
nullIf๋ฅผ ๋ง๋ค๊ธฐ ์ํด, nullIf()
์ ์ฌ์ฉํ ์ ์์ต๋๋ค.
New
DTO ํ๋ก์ ์
์ ๋ง๋ค๊ธฐ ์ํด, new()
๋ฅผ ์ฌ์ฉํ ์ ์์ต๋๋ค.
Type
type ์ฐ์ฐ์๋ฅผ ๋ง๋ค๊ธฐ ์ํด, type()
์ ์ฌ์ฉํ ์ ์์ต๋๋ค.
Custom expression
์ปค์คํ
expression์ ๋ง๋ค๊ธฐ ์ํด, customExpression()
์ ์ฌ์ฉํ ์ ์์ต๋๋ค.
๋ง์ฝ customExpression()
์ ๋ง์ด ์ฌ์ฉํ๋ค๋ฉด ๋๋ง์ DSL์ ๋ง๋๋ ๊ฒ์ ๊ณ ๋ คํด๋ณด์ธ์.
Last updated