diff --git a/docs/en/jpql-with-kotlin-jdsl/expressions.md b/docs/en/jpql-with-kotlin-jdsl/expressions.md index ec118d430..76524477c 100644 --- a/docs/en/jpql-with-kotlin-jdsl/expressions.md +++ b/docs/en/jpql-with-kotlin-jdsl/expressions.md @@ -226,7 +226,7 @@ Kotlin JDSL provides a series of functions to support built-in functions in JPA. | CURRENT\_DATE | not yet | | CURRENT\_TIME | not yet | | CURRENT\_TIMESTAMP | not yet | -| LOCAL DATE | not yet | +| LOCAL DATE | support | | LOCAL TIME | not yet | | LOCAL DATETIME | not yet | | EXTRACT | not yet | diff --git a/docs/ko/jpql-with-kotlin-jdsl/expressions.md b/docs/ko/jpql-with-kotlin-jdsl/expressions.md index e77eadfec..8f7ced589 100644 --- a/docs/ko/jpql-with-kotlin-jdsl/expressions.md +++ b/docs/ko/jpql-with-kotlin-jdsl/expressions.md @@ -224,7 +224,7 @@ Kotlin JDSL은 JPA에서 제공하는 여러 함수들을 지원하기 위함 | CURRENT\_DATE | not yet | | CURRENT\_TIME | not yet | | CURRENT\_TIMESTAMP | not yet | -| LOCAL DATE | not yet | +| LOCAL DATE | support | | LOCAL TIME | not yet | | LOCAL DATETIME | not yet | | EXTRACT | not yet | diff --git a/dsl/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/Jpql.kt b/dsl/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/Jpql.kt index bc4ee6d0a..bfbc1b5fa 100644 --- a/dsl/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/Jpql.kt +++ b/dsl/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/Jpql.kt @@ -44,6 +44,7 @@ import com.linecorp.kotlinjdsl.querymodel.jpql.select.SelectQuery import com.linecorp.kotlinjdsl.querymodel.jpql.sort.Sort import java.math.BigDecimal import java.math.BigInteger +import java.time.LocalDate import kotlin.internal.Exact import kotlin.internal.LowPriorityInOverloadResolution import kotlin.reflect.KClass @@ -1380,6 +1381,16 @@ open class Jpql : JpqlDsl { ) } + /** + * Creates an expression that represents the local date. + * + * This is the same as ```LOCAL DATE```. + */ + @SinceJdsl("3.4.0") + fun localDate(): Expression { + return Expressions.localDate() + } + /** * Creates an expression that represents predefined database functions and user-defined database functions. */ diff --git a/dsl/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/expression/LocalDateDslTest.kt b/dsl/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/expression/LocalDateDslTest.kt new file mode 100644 index 000000000..f7261ce2a --- /dev/null +++ b/dsl/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/expression/LocalDateDslTest.kt @@ -0,0 +1,26 @@ +package com.linecorp.kotlinjdsl.dsl.jpql.expression + +import com.linecorp.kotlinjdsl.dsl.jpql.queryPart +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expression +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expressions +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test +import java.time.LocalDate + +class LocalDateDslTest { + + @Test + fun localDate() { + // when + val expression = queryPart { + localDate() + }.toExpression() + + val actual: Expression = expression // for type check + + // then + val expected = Expressions.localDate() + + assertThat(actual).isEqualTo(expected) + } +} diff --git a/query-model/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/expression/Expressions.kt b/query-model/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/expression/Expressions.kt index 25f378881..451ac7d0a 100644 --- a/query-model/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/expression/Expressions.kt +++ b/query-model/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/expression/Expressions.kt @@ -17,6 +17,7 @@ import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlExpressionPar import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlFunctionExpression import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlLength import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlLiteral +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlLocalDate import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlLocate import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlLower import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlMax @@ -44,6 +45,7 @@ import com.linecorp.kotlinjdsl.querymodel.jpql.select.SelectQuery import com.linecorp.kotlinjdsl.querymodel.jpql.select.impl.JpqlSelectQuery import java.math.BigDecimal import java.math.BigInteger +import java.time.LocalDate import kotlin.internal.Exact import kotlin.reflect.KClass @@ -543,6 +545,14 @@ object Expressions { return JpqlLocate(substring, string, start) } + /** + * Creates an expression that represents the local date. + */ + @SinceJdsl("3.4.0") + fun localDate(): Expression { + return JpqlLocalDate + } + /** * Creates an expression that represents predefined database functions and user-defined database functions. */ diff --git a/query-model/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/expression/impl/JpqlLocalDate.kt b/query-model/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/expression/impl/JpqlLocalDate.kt new file mode 100644 index 000000000..019389e77 --- /dev/null +++ b/query-model/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/expression/impl/JpqlLocalDate.kt @@ -0,0 +1,8 @@ +package com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl + +import com.linecorp.kotlinjdsl.Internal +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expression +import java.time.LocalDate + +@Internal +object JpqlLocalDate : Expression diff --git a/query-model/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/expression/ExpressionsTest.kt b/query-model/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/expression/ExpressionsTest.kt index fae31a8ba..6c4c69d8e 100644 --- a/query-model/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/expression/ExpressionsTest.kt +++ b/query-model/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/expression/ExpressionsTest.kt @@ -19,6 +19,7 @@ import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlExpressionPar import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlFunctionExpression import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlLength import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlLiteral +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlLocalDate import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlLocate import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlLower import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlMax @@ -774,6 +775,17 @@ class ExpressionsTest : WithAssertions { assertThat(actual).isEqualTo(expected) } + @Test + fun localDate() { + // when + val actual = Expressions.localDate() + + // then + val expected = JpqlLocalDate + + assertThat(actual).isEqualTo(expected) + } + @Test fun function() { // when diff --git a/render/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/render/jpql/JpqlRenderContext.kt b/render/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/render/jpql/JpqlRenderContext.kt index ed5e4e135..15f979e82 100644 --- a/render/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/render/jpql/JpqlRenderContext.kt +++ b/render/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/render/jpql/JpqlRenderContext.kt @@ -69,6 +69,7 @@ import com.linecorp.kotlinjdsl.render.jpql.serializer.impl.JpqlLessThanOrEqualTo import com.linecorp.kotlinjdsl.render.jpql.serializer.impl.JpqlLessThanSerializer import com.linecorp.kotlinjdsl.render.jpql.serializer.impl.JpqlLikeSerializer import com.linecorp.kotlinjdsl.render.jpql.serializer.impl.JpqlLiteralSerializer +import com.linecorp.kotlinjdsl.render.jpql.serializer.impl.JpqlLocalDateSerializer import com.linecorp.kotlinjdsl.render.jpql.serializer.impl.JpqlLocateSerializer import com.linecorp.kotlinjdsl.render.jpql.serializer.impl.JpqlLowerSerializer import com.linecorp.kotlinjdsl.render.jpql.serializer.impl.JpqlMaxSerializer @@ -314,6 +315,7 @@ private class DefaultModule : JpqlRenderModule { JpqlLessThanSerializer(), JpqlLikeSerializer(), JpqlLiteralSerializer(), + JpqlLocalDateSerializer(), JpqlLocateSerializer(), JpqlLowerSerializer(), JpqlMaxSerializer(), diff --git a/render/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlLocalDateSerializer.kt b/render/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlLocalDateSerializer.kt new file mode 100644 index 000000000..651856951 --- /dev/null +++ b/render/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlLocalDateSerializer.kt @@ -0,0 +1,20 @@ +package com.linecorp.kotlinjdsl.render.jpql.serializer.impl + +import com.linecorp.kotlinjdsl.Internal +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlLocalDate +import com.linecorp.kotlinjdsl.render.RenderContext +import com.linecorp.kotlinjdsl.render.jpql.serializer.JpqlSerializer +import com.linecorp.kotlinjdsl.render.jpql.writer.JpqlWriter +import kotlin.reflect.KClass + +@Internal +class JpqlLocalDateSerializer : JpqlSerializer { + + override fun handledType(): KClass { + return JpqlLocalDate::class + } + + override fun serialize(part: JpqlLocalDate, writer: JpqlWriter, context: RenderContext) { + writer.write("LOCAL DATE") + } +} diff --git a/render/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlLocalDateSerializerTest.kt b/render/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlLocalDateSerializerTest.kt new file mode 100644 index 000000000..b3f3a2dea --- /dev/null +++ b/render/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlLocalDateSerializerTest.kt @@ -0,0 +1,46 @@ +package com.linecorp.kotlinjdsl.render.jpql.serializer.impl + +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlLocalDate +import com.linecorp.kotlinjdsl.render.TestRenderContext +import com.linecorp.kotlinjdsl.render.jpql.serializer.JpqlRenderSerializer +import com.linecorp.kotlinjdsl.render.jpql.serializer.JpqlSerializerTest +import com.linecorp.kotlinjdsl.render.jpql.writer.JpqlWriter +import io.mockk.impl.annotations.MockK +import io.mockk.verifySequence +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +@JpqlSerializerTest +class JpqlLocalDateSerializerTest { + private val sut = JpqlLocalDateSerializer() + + @MockK + private lateinit var writer: JpqlWriter + + @MockK + private lateinit var serializer: JpqlRenderSerializer + + @Test + fun handle() { + // when + val actual = sut.handledType() + + // then + assertThat(actual).isEqualTo(JpqlLocalDate::class) + } + + @Test + fun serialize() { + // given + val part = JpqlLocalDate + val context = TestRenderContext(serializer) + + // when + sut.serialize(part, writer, context) + + // then + verifySequence { + writer.write("LOCAL DATE") + } + } +}