Skip to content

Long 의 wrapper 클래스를 value class 로 만들어서 사용중인데 이 타입에 대한 sum 쿼리를 할 수 있는 방법이 있을까요? #869

Closed Answered by WoongE
WoongE asked this question in Q&A
Discussion options

You must be logged in to vote
data class MoneySum(
    val expr: Expression<Money>,
    val distinct: Boolean = false,
) : Expression<Long>

class JpqlMoneySumSerializer : JpqlSerializer<MoneySum> {
    override fun handledType(): KClass<MoneySum> = MoneySum::class

    override fun serialize(part: MoneySum, writer: JpqlWriter, context: RenderContext) {
        val delegate = context.getValue(JpqlRenderSerializer)

        writer.write("SUM")

        writer.writeParentheses {
            if (part.distinct) {
                writer.write("DISTINCT")
                writer.write(" ")
            }

            delegate.serialize(part.expr, writer, context)
        }
    }
}

class MyJpql : Jpql() {
    companion object

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@shouwn
Comment options

Answer selected by WoongE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants