Expressions
Kotlin JDSL has the Expression
interface to represent an expression in JPQL.
Alias
Call as()
in Expression
to alias Expression
. You can create a reference of Expression
using expression()
. References are identified by an alias, and you can reference Expression
with the same alias. This allows you to alias Expression
or reference the aliased Expression
in other clauses.
Type cast
In some cases, you may want to change the type of Expression
. To this end, Kotlin JDSL provides unsafe type casting through as()
.
Arithmetic operations
Use the following functions to build arithmetic operations:
+ (plus)
- (minus)
* (times)
/ (div)
Parentheses
Call arithmetic operators using a normal function instead of an extension function to add parentheses for the order of operations. As for extension functions, Kotlin JDSL cannot add parentheses because the order is ambiguous.
Values
Use value()
to build a value. All values built by value()
are interpreted as query parameters. These query parameters cannot be overridden.
Params
Use param()
instead of value()
to build query parameters. Parameters created with param()
can be overridden.
Literals
Call xxxLiteral()
instead of value()
to build a literal in queries.
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
Use the following functions to build aggregate functions:
COUNT (count)
MIN (min)
MAX (max)
AVG (avg)
SUM (sum)
Sum
sum()
returns a different type, depending on the type of the parameter.
Int
Long
Long
Long
Float
Double
Double
Double
BigInteger
BigInteger
BigDecimal
BigDecimal
Functions
Kotlin JDSL provides a series of functions to support built-in functions in 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
Call function()
to create predefined database functions and user-defined database functions.
Cases
Use caseWhen()
and caseValue()
to build cases.
Coalesce
Use coalesce()
to build coalesce.
NullIf
Use nullIf()
to build nullIf.
New
Use new()
to build DTO projections.
Type
Use type()
to build type operators.
Custom expression
Call customExpression()
to build a custom expression.
Last updated
Was this helpful?