From 46795107d6956dbd5040dd987b6e757aa786224f Mon Sep 17 00:00:00 2001 From: "jonghyon.s" Date: Tue, 16 Jan 2024 11:12:34 +0900 Subject: [PATCH 001/169] chore: snapshot 3.4.0 --- README.md | 4 ++-- build.gradle.kts | 2 +- docs/en/README.md | 2 +- docs/en/jpql-with-kotlin-jdsl/README.md | 12 ++++++------ docs/ko/README.md | 2 +- docs/ko/jpql-with-kotlin-jdsl/README.md | 12 ++++++------ 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 89b4e05a5..746029895 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,11 @@ -Visit [the gitbook](https://kotlin-jdsl.gitbook.io/docs/) for more information. +Visit [the gitbook](https://kotlin-jdsl.gitbook.io/snapshot-docs/) for more information. # Kotlin JDSL - + diff --git a/build.gradle.kts b/build.gradle.kts index 454b3ef31..ab65209d4 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -25,7 +25,7 @@ allprojects { apply(plugin = "signing") group = "com.linecorp.kotlin-jdsl" - version = "3.3.0" + version = "3.4.0-SNAPSHOT" repositories { mavenCentral() diff --git a/docs/en/README.md b/docs/en/README.md index d3beddc8d..71d63c90d 100644 --- a/docs/en/README.md +++ b/docs/en/README.md @@ -1,5 +1,5 @@ --- -description: 'Latest stable version: 3.3.0' +description: 'Latest stable version: 3.4.0-SNAPSHOT' --- # Kotlin JDSL diff --git a/docs/en/jpql-with-kotlin-jdsl/README.md b/docs/en/jpql-with-kotlin-jdsl/README.md index 6012faff3..089b36472 100644 --- a/docs/en/jpql-with-kotlin-jdsl/README.md +++ b/docs/en/jpql-with-kotlin-jdsl/README.md @@ -99,8 +99,8 @@ The following dependencies are the minimum requirement for all Kotlin JDSL appli ```kotlin dependencies { - implementation("com.linecorp.kotlin-jdsl:jpql-dsl:3.3.0") - implementation("com.linecorp.kotlin-jdsl:jpql-render:3.3.0") + implementation("com.linecorp.kotlin-jdsl:jpql-dsl:3.4.0-SNAPSHOT") + implementation("com.linecorp.kotlin-jdsl:jpql-render:3.4.0-SNAPSHOT") } ``` @@ -110,8 +110,8 @@ dependencies { ```groovy dependencies { - implementation 'com.linecorp.kotlin-jdsl:jpql-dsl:3.3.0' - implementation 'com.linecorp.kotlin-jdsl:jpql-render:3.3.0' + implementation 'com.linecorp.kotlin-jdsl:jpql-dsl:3.4.0-SNAPSHOT' + implementation 'com.linecorp.kotlin-jdsl:jpql-render:3.4.0-SNAPSHOT' } ``` @@ -125,12 +125,12 @@ dependencies { com.linecorp.kotlin-jdsl jpql-dsl - 3.3.0 + 3.4.0-SNAPSHOT com.linecorp.kotlin-jdsl jpql-render - 3.3.0 + 3.4.0-SNAPSHOT ``` diff --git a/docs/ko/README.md b/docs/ko/README.md index 1769392fd..3f0481bb2 100644 --- a/docs/ko/README.md +++ b/docs/ko/README.md @@ -1,5 +1,5 @@ --- -description: 'Latest stable version: 3.3.0' +description: 'Latest stable version: 3.4.0-SNAPSHOT' --- # Kotlin JDSL diff --git a/docs/ko/jpql-with-kotlin-jdsl/README.md b/docs/ko/jpql-with-kotlin-jdsl/README.md index 2daffa387..5e7e65855 100644 --- a/docs/ko/jpql-with-kotlin-jdsl/README.md +++ b/docs/ko/jpql-with-kotlin-jdsl/README.md @@ -100,8 +100,8 @@ Kotlin JDSL을 실행시키기 위해서는 다음 dependency들이 필수로 ```kotlin dependencies { - implementation("com.linecorp.kotlin-jdsl:jpql-dsl:3.3.0") - implementation("com.linecorp.kotlin-jdsl:jpql-render:3.3.0") + implementation("com.linecorp.kotlin-jdsl:jpql-dsl:3.4.0-SNAPSHOT") + implementation("com.linecorp.kotlin-jdsl:jpql-render:3.4.0-SNAPSHOT") } ``` @@ -111,8 +111,8 @@ dependencies { ```groovy dependencies { - implementation 'com.linecorp.kotlin-jdsl:jpql-dsl:3.3.0' - implementation 'com.linecorp.kotlin-jdsl:jpql-render:3.3.0' + implementation 'com.linecorp.kotlin-jdsl:jpql-dsl:3.4.0-SNAPSHOT' + implementation 'com.linecorp.kotlin-jdsl:jpql-render:3.4.0-SNAPSHOT' } ``` @@ -126,12 +126,12 @@ dependencies { com.linecorp.kotlin-jdsl jpql-dsl - 3.3.0 + 3.4.0-SNAPSHOT com.linecorp.kotlin-jdsl jpql-render - 3.3.0 + 3.4.0-SNAPSHOT ``` From 0e855748b7d39a2ec45eb450c235f172abd3b0ba Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 19 Jan 2024 09:17:10 +0900 Subject: [PATCH 002/169] chore(deps): update dependency org.hibernate:hibernate-core to v6.4.2.final (#569) * chore(deps): update dependency org.hibernate:hibernate-core to v6.4.2.final --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Hyunsik Kang --- libs.example.versions.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs.example.versions.toml b/libs.example.versions.toml index 95fbbe79a..28c19a769 100644 --- a/libs.example.versions.toml +++ b/libs.example.versions.toml @@ -28,7 +28,7 @@ spring-batch4-test = { module = "org.springframework.batch:spring-batch-test", v # hibernate hibernate5-core = { module = "org.hibernate:hibernate-core", version = "5.6.15.Final" } -hibernate6-core = { module = "org.hibernate:hibernate-core", version = "6.4.1.Final" } +hibernate6-core = { module = "org.hibernate:hibernate-core", version = "6.4.2.Final" } # hibernate-reactive hibernate-reactive1-core = { module = "org.hibernate.reactive:hibernate-reactive-core", version = "1.1.9.Final" } From 178957d3622cfcbbc8e0329541028e52b7ba5ac0 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 19 Jan 2024 23:13:49 +0000 Subject: [PATCH 003/169] chore(deps): update spring.boot3 to v3.2.2 --- libs.example.versions.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs.example.versions.toml b/libs.example.versions.toml index 28c19a769..58d56ed1b 100644 --- a/libs.example.versions.toml +++ b/libs.example.versions.toml @@ -1,5 +1,5 @@ [versions] -spring-boot3 = "3.2.1" +spring-boot3 = "3.2.2" spring-boot2 = "2.7.18" [libraries] From a5e5b656ffd6966bc6ac2771ba155175a682bb00 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 22 Jan 2024 10:26:40 +0000 Subject: [PATCH 004/169] chore(deps): update dependency @commitlint/cli to v18.5.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8cb37329e..22791485e 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "jdsl-commitlint-node-package", "devDependencies": { - "@commitlint/cli": "18.4.4", + "@commitlint/cli": "18.5.0", "@commitlint/config-conventional": "18.4.4" } } From 141e670ddeffbe0874bfee10d76a5c9e51e0bccf Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 22 Jan 2024 11:27:28 +0000 Subject: [PATCH 005/169] chore(deps): update dependency @commitlint/config-conventional to v18.5.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 22791485e..d15f4c4e4 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,6 @@ "name": "jdsl-commitlint-node-package", "devDependencies": { "@commitlint/cli": "18.5.0", - "@commitlint/config-conventional": "18.4.4" + "@commitlint/config-conventional": "18.5.0" } } From 0a799c64fdbd0ed8990c972d2f37b6561e596aa2 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 25 Jan 2024 11:30:38 +0900 Subject: [PATCH 006/169] chore(deps): update dependency org.hibernate.reactive:hibernate-reactive-core to v2.2.2.final (#580) * chore(deps): update dependency org.hibernate.reactive:hibernate-reactive-core to v2.2.2.final --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Hyunsik Kang --- libs.example.versions.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs.example.versions.toml b/libs.example.versions.toml index 58d56ed1b..b621111e1 100644 --- a/libs.example.versions.toml +++ b/libs.example.versions.toml @@ -32,7 +32,7 @@ hibernate6-core = { module = "org.hibernate:hibernate-core", version = "6.4.2.Fi # hibernate-reactive hibernate-reactive1-core = { module = "org.hibernate.reactive:hibernate-reactive-core", version = "1.1.9.Final" } -hibernate-reactive2-core = { module = "org.hibernate.reactive:hibernate-reactive-core", version = "2.2.1.Final" } +hibernate-reactive2-core = { module = "org.hibernate.reactive:hibernate-reactive-core", version = "2.2.2.Final" } # eclipse-link eclipselink2 = { module = "org.eclipse.persistence:org.eclipse.persistence.jpa", version = "2.7.14" } From 11c53e1cdc1ba4d09fe3e3a60f764fa7bdfd492d Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 25 Jan 2024 13:33:58 +0000 Subject: [PATCH 007/169] chore(deps): update dependency @commitlint/cli to v18.6.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d15f4c4e4..58764eda1 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "jdsl-commitlint-node-package", "devDependencies": { - "@commitlint/cli": "18.5.0", + "@commitlint/cli": "18.6.0", "@commitlint/config-conventional": "18.5.0" } } From 85488355e87a05011d144bb90b2caac385c61005 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 25 Jan 2024 18:26:40 +0000 Subject: [PATCH 008/169] chore(deps): update dependency @commitlint/config-conventional to v18.6.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 58764eda1..9f22be8ab 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,6 @@ "name": "jdsl-commitlint-node-package", "devDependencies": { "@commitlint/cli": "18.6.0", - "@commitlint/config-conventional": "18.5.0" + "@commitlint/config-conventional": "18.6.0" } } From 82ef72618b2aec2b25ad09564ac2047024334303 Mon Sep 17 00:00:00 2001 From: Jake Son Date: Sun, 28 Jan 2024 10:03:30 +0900 Subject: [PATCH 009/169] feat: implement abs expression --- .../querymodel/jpql/expression/Expressions.kt | 9 +++++++++ .../querymodel/jpql/expression/impl/JpqlAbs.kt | 12 ++++++++++++ .../querymodel/jpql/expression/ExpressionsTest.kt | 14 ++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 query-model/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/expression/impl/JpqlAbs.kt 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..b2815992b 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 @@ -2,6 +2,7 @@ package com.linecorp.kotlinjdsl.querymodel.jpql.expression import com.linecorp.kotlinjdsl.SinceJdsl import com.linecorp.kotlinjdsl.querymodel.jpql.entity.Entity +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlAbs import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlAliasedExpression import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlAvg import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlCaseValue @@ -166,6 +167,14 @@ object Expressions { return JpqlParam(name, value) } + /** + * Creates an expression that represents the absolute value. + */ + @SinceJdsl("3.3.2") + fun abs(value: Expression): Expression { + return JpqlAbs(value) + } + /** * Creates an expression that represents the plus of values. * diff --git a/query-model/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/expression/impl/JpqlAbs.kt b/query-model/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/expression/impl/JpqlAbs.kt new file mode 100644 index 000000000..02582021f --- /dev/null +++ b/query-model/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/expression/impl/JpqlAbs.kt @@ -0,0 +1,12 @@ +package com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl + +import com.linecorp.kotlinjdsl.Internal +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expression + +/** + * Expression that applies the absolute value function to [value]. + */ +@Internal +data class JpqlAbs internal constructor( + val value: Expression<*>, +) : 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..a5cf15d46 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 @@ -4,6 +4,7 @@ import com.linecorp.kotlinjdsl.querymodel.jpql.entity.Entities import com.linecorp.kotlinjdsl.querymodel.jpql.entity.book.Book import com.linecorp.kotlinjdsl.querymodel.jpql.entity.book.BookAuthorType import com.linecorp.kotlinjdsl.querymodel.jpql.entity.employee.Employee +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlAbs import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlAliasedExpression import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlAvg import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlCaseValue @@ -276,6 +277,19 @@ class ExpressionsTest : WithAssertions { assertThat(actual).isEqualTo(expected) } + @Test + fun abs() { + // when + val actual = Expressions.abs(intExpression1) + + // then + val expected = JpqlAbs( + intExpression1, + ) + + assertThat(actual).isEqualTo(expected) + } + @Test fun plus() { // when From b2036eaff6acea43a6614e365d07361ea670bcdb Mon Sep 17 00:00:00 2001 From: Jake Son Date: Sun, 28 Jan 2024 10:33:45 +0900 Subject: [PATCH 010/169] feat: implement abs function --- .../com/linecorp/kotlinjdsl/dsl/jpql/Jpql.kt | 16 +++++++ .../dsl/jpql/expression/AbsDslTest.kt | 48 +++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 dsl/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/expression/AbsDslTest.kt 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..e07d1c1de 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 @@ -336,6 +336,22 @@ open class Jpql : JpqlDsl { return Paths.treat(this.toPath(), type) } + /** + * Creates an expression that represents the absolute value. + */ + @SinceJdsl("3.3.2") + fun abs(expr: KProperty1): Expression { + return Expressions.abs(Paths.path(expr)) + } + + /** + * Creates an expression that represents the absolute value. + */ + @SinceJdsl("3.3.2") + fun abs(expr: Expressionable): Expression { + return Expressions.abs(expr.toExpression()) + } + /** * Creates an expression that represents the plus of values. * The values are each enclosed in parentheses. diff --git a/dsl/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/expression/AbsDslTest.kt b/dsl/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/expression/AbsDslTest.kt new file mode 100644 index 000000000..d66d71d09 --- /dev/null +++ b/dsl/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/expression/AbsDslTest.kt @@ -0,0 +1,48 @@ +package com.linecorp.kotlinjdsl.dsl.jpql.expression + +import com.linecorp.kotlinjdsl.dsl.jpql.entity.book.Book +import com.linecorp.kotlinjdsl.dsl.jpql.queryPart +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expression +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expressions +import com.linecorp.kotlinjdsl.querymodel.jpql.path.Paths +import org.assertj.core.api.WithAssertions +import org.junit.jupiter.api.Test +import java.math.BigDecimal + +class AbsDslTest : WithAssertions { + private val expression1 = Paths.path(Book::salePrice) + + @Test + fun `abs() with a property`() { + // when + val expression = queryPart { + abs(Book::price) + }.toExpression() + + val actual: Expression = expression // for type check + + // then + val expected = Expressions.abs( + value = Paths.path(Book::price), + ) + + assertThat(actual).isEqualTo(expected) + } + + @Test + fun `abs() with a expression`() { + // when + val expression = queryPart { + abs(expression1) + }.toExpression() + + val actual: Expression = expression // for type check + + // then + val expected = Expressions.abs( + value = expression1, + ) + + assertThat(actual).isEqualTo(expected) + } +} From ce3ddbea46412165798cf7f394b7f228e5192702 Mon Sep 17 00:00:00 2001 From: Jake Son Date: Sun, 28 Jan 2024 10:41:28 +0900 Subject: [PATCH 011/169] feat: implement abs serializer --- .../render/jpql/JpqlRenderContext.kt | 2 + .../jpql/serializer/impl/JpqlAbsSerializer.kt | 26 +++++++++ .../serializer/impl/JpqlAbsSerializerTest.kt | 55 +++++++++++++++++++ 3 files changed, 83 insertions(+) create mode 100644 render/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlAbsSerializer.kt create mode 100644 render/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlAbsSerializerTest.kt 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..3cee42804 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 @@ -13,6 +13,7 @@ import com.linecorp.kotlinjdsl.render.jpql.introspector.impl.KotlinStyleJpqlProp import com.linecorp.kotlinjdsl.render.jpql.serializer.JpqlRenderSerializer import com.linecorp.kotlinjdsl.render.jpql.serializer.JpqlSerializer import com.linecorp.kotlinjdsl.render.jpql.serializer.JpqlSerializerModifier +import com.linecorp.kotlinjdsl.render.jpql.serializer.impl.JpqlAbsSerializer import com.linecorp.kotlinjdsl.render.jpql.serializer.impl.JpqlAliasedExpressionSerializer import com.linecorp.kotlinjdsl.render.jpql.serializer.impl.JpqlAndSerializer import com.linecorp.kotlinjdsl.render.jpql.serializer.impl.JpqlAvgSerializer @@ -258,6 +259,7 @@ private class DefaultModule : JpqlRenderModule { context.appendIntrospector(KotlinStyleJpqlPropertyIntrospector()) context.addAllSerializer( + JpqlAbsSerializer(), JpqlAliasedExpressionSerializer(), JpqlAndSerializer(), JpqlAvgSerializer(), diff --git a/render/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlAbsSerializer.kt b/render/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlAbsSerializer.kt new file mode 100644 index 000000000..34ab66f98 --- /dev/null +++ b/render/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlAbsSerializer.kt @@ -0,0 +1,26 @@ +package com.linecorp.kotlinjdsl.render.jpql.serializer.impl + +import com.linecorp.kotlinjdsl.Internal +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlAbs +import com.linecorp.kotlinjdsl.render.RenderContext +import com.linecorp.kotlinjdsl.render.jpql.serializer.JpqlRenderSerializer +import com.linecorp.kotlinjdsl.render.jpql.serializer.JpqlSerializer +import com.linecorp.kotlinjdsl.render.jpql.writer.JpqlWriter +import kotlin.reflect.KClass + +@Internal +class JpqlAbsSerializer : JpqlSerializer> { + override fun handledType(): KClass> { + return JpqlAbs::class + } + + override fun serialize(part: JpqlAbs<*>, writer: JpqlWriter, context: RenderContext) { + val delegate = context.getValue(JpqlRenderSerializer) + + writer.write("ABS") + + writer.writeParentheses { + delegate.serialize(part.value, writer, context) + } + } +} diff --git a/render/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlAbsSerializerTest.kt b/render/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlAbsSerializerTest.kt new file mode 100644 index 000000000..aa707ba35 --- /dev/null +++ b/render/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlAbsSerializerTest.kt @@ -0,0 +1,55 @@ +package com.linecorp.kotlinjdsl.render.jpql.serializer.impl + +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expressions +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlAbs +import com.linecorp.kotlinjdsl.querymodel.jpql.path.Paths +import com.linecorp.kotlinjdsl.render.TestRenderContext +import com.linecorp.kotlinjdsl.render.jpql.entity.book.Book +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.WithAssertions +import org.junit.jupiter.api.Test + +@JpqlSerializerTest +class JpqlAbsSerializerTest : WithAssertions { + private val sut = JpqlAbsSerializer() + + @MockK + private lateinit var writer: JpqlWriter + + @MockK + private lateinit var serializer: JpqlRenderSerializer + + private val expression1 = Paths.path(Book::price) + + @Test + fun handledType() { + // when + val actual = sut.handledType() + + // then + assertThat(actual).isEqualTo(JpqlAbs::class) + } + + @Test + fun serialize() { + // given + val part = Expressions.abs( + value = expression1, + ) + val context = TestRenderContext(serializer) + + // when + sut.serialize(part as JpqlAbs<*>, writer, context) + + // then + verifySequence { + writer.write("ABS") + writer.writeParentheses(any()) + serializer.serialize(expression1, writer, context) + } + } +} From 90edab6826ed8de57c92d46918f3daaa1c66298b Mon Sep 17 00:00:00 2001 From: Jake Son Date: Sun, 28 Jan 2024 10:46:51 +0900 Subject: [PATCH 012/169] docs: add abs function support --- docs/en/jpql-with-kotlin-jdsl/expressions.md | 4 +++- docs/ko/jpql-with-kotlin-jdsl/expressions.md | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/en/jpql-with-kotlin-jdsl/expressions.md b/docs/en/jpql-with-kotlin-jdsl/expressions.md index ec118d430..16f360f96 100644 --- a/docs/en/jpql-with-kotlin-jdsl/expressions.md +++ b/docs/en/jpql-with-kotlin-jdsl/expressions.md @@ -153,6 +153,7 @@ It will look like 'literal''s'. Use the following functions to build aggregate functions: +* ABS (abs) * COUNT (count) * MIN (min) * MAX (max) @@ -160,6 +161,8 @@ Use the following functions to build aggregate functions: * SUM (sum) ```kotlin +abs(path(Book::price)) + count(path(Book::price)) countDistinct(path(Book::price)) @@ -206,7 +209,6 @@ Kotlin JDSL provides a series of functions to support built-in functions in JPA. | Function | DSL function | |----------|--------------| -| ABS | not yet | | CEILING | not yet | | EXP | not yet | | FLOOR | not yet | diff --git a/docs/ko/jpql-with-kotlin-jdsl/expressions.md b/docs/ko/jpql-with-kotlin-jdsl/expressions.md index e77eadfec..cd9143959 100644 --- a/docs/ko/jpql-with-kotlin-jdsl/expressions.md +++ b/docs/ko/jpql-with-kotlin-jdsl/expressions.md @@ -48,12 +48,15 @@ avg(path(FullTimeEmployee::annualSalary)(EmployeeSalary::value)).`as`(BigDecimal 산술 연사자를 만들기 위해서는 다음 함수들을 사용할 수 있습니다. +* abs * \+ (plus) * \- (minus) * \* (times) * / (div) ```kotlin +abs(path(Book::price)) + path(Book::price).plus(path(Book::salePrice)) plus(path(Book::price), path(Book::salePrice)) @@ -204,7 +207,6 @@ Kotlin JDSL은 JPA에서 제공하는 여러 함수들을 지원하기 위함 | Function | DSL function | |----------|--------------| -| ABS | not yet | | CEILING | not yet | | EXP | not yet | | FLOOR | not yet | From 2a952ea76f95bb1896250169a8507e914c091df7 Mon Sep 17 00:00:00 2001 From: Jake Son Date: Sun, 28 Jan 2024 10:53:57 +0900 Subject: [PATCH 013/169] fix: change version --- .../src/main/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/Jpql.kt | 4 ++-- .../kotlinjdsl/querymodel/jpql/expression/Expressions.kt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) 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 e07d1c1de..888898258 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 @@ -339,7 +339,7 @@ open class Jpql : JpqlDsl { /** * Creates an expression that represents the absolute value. */ - @SinceJdsl("3.3.2") + @SinceJdsl("3.4.0") fun abs(expr: KProperty1): Expression { return Expressions.abs(Paths.path(expr)) } @@ -347,7 +347,7 @@ open class Jpql : JpqlDsl { /** * Creates an expression that represents the absolute value. */ - @SinceJdsl("3.3.2") + @SinceJdsl("3.4.0") fun abs(expr: Expressionable): Expression { return Expressions.abs(expr.toExpression()) } 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 b2815992b..31e162e93 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 @@ -170,7 +170,7 @@ object Expressions { /** * Creates an expression that represents the absolute value. */ - @SinceJdsl("3.3.2") + @SinceJdsl("3.4.0") fun abs(value: Expression): Expression { return JpqlAbs(value) } From 754bc4cfab26da1f2c23923d2b2f3c1d074177cf Mon Sep 17 00:00:00 2001 From: Jake Son Date: Mon, 29 Jan 2024 08:24:00 +0900 Subject: [PATCH 014/169] fix: correct wrong description --- docs/en/jpql-with-kotlin-jdsl/expressions.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/en/jpql-with-kotlin-jdsl/expressions.md b/docs/en/jpql-with-kotlin-jdsl/expressions.md index 16f360f96..3b899e65c 100644 --- a/docs/en/jpql-with-kotlin-jdsl/expressions.md +++ b/docs/en/jpql-with-kotlin-jdsl/expressions.md @@ -48,12 +48,15 @@ avg(path(FullTimeEmployee::annualSalary)(EmployeeSalary::value)).`as`(BigDecimal Use the following functions to build arithmetic operations: +* abs * \+ (plus) * \- (minus) * \* (times) * / (div) ```kotlin +abs(path(Book::price)) + path(Book::price).plus(path(Book::salePrice)) plus(path(Book::price), path(Book::salePrice)) @@ -153,7 +156,6 @@ It will look like 'literal''s'. Use the following functions to build aggregate functions: -* ABS (abs) * COUNT (count) * MIN (min) * MAX (max) @@ -161,8 +163,6 @@ Use the following functions to build aggregate functions: * SUM (sum) ```kotlin -abs(path(Book::price)) - count(path(Book::price)) countDistinct(path(Book::price)) From be3669e995efd5648842822c701059149704ba49 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 29 Jan 2024 22:26:26 +0000 Subject: [PATCH 015/169] chore(deps): update gradle/wrapper-validation-action action to v2 --- .github/workflows/lint.yaml | 2 +- .github/workflows/publish.yaml | 2 +- .github/workflows/test.yaml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index 64747c879..19de69716 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -37,7 +37,7 @@ jobs: distribution: 'adopt' cache: gradle - name: Validate Gradle wrapper - uses: gradle/wrapper-validation-action@v1 + uses: gradle/wrapper-validation-action@v2 - name: Lint Kotlin with Gradle run: ./gradlew lintKotlin - name: Cleanup Gradle Cache diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 541c3f7ca..b52a03279 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -24,7 +24,7 @@ jobs: distribution: 'adopt' cache: gradle - name: Validate Gradle wrapper - uses: gradle/wrapper-validation-action@v1 + uses: gradle/wrapper-validation-action@v2 - name: Build with Grade run: ./gradlew build - name: Publish to the Maven Central Repository diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 6f4d0d8b8..6882db836 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -24,7 +24,7 @@ jobs: distribution: 'adopt' cache: gradle - name: Validate Gradle wrapper - uses: gradle/wrapper-validation-action@v1 + uses: gradle/wrapper-validation-action@v2 - name: CodeCoverage(with test) with Gradle run: ./gradlew koverXmlReport - name: Upload coverage to Codecov From 6efa51031626fa2dd594e2f2dcbaf64ec9fdfc51 Mon Sep 17 00:00:00 2001 From: "jonghyon.s" Date: Tue, 30 Jan 2024 10:51:50 +0900 Subject: [PATCH 016/169] fix: invalid timezone when hibernate run script --- .../src/main/resources/META-INF/persistence.xml | 1 + example/hibernate/src/main/resources/META-INF/persistence.xml | 1 + 2 files changed, 2 insertions(+) diff --git a/example/hibernate-reactive/src/main/resources/META-INF/persistence.xml b/example/hibernate-reactive/src/main/resources/META-INF/persistence.xml index 50be6f0f4..c7694b96a 100644 --- a/example/hibernate-reactive/src/main/resources/META-INF/persistence.xml +++ b/example/hibernate-reactive/src/main/resources/META-INF/persistence.xml @@ -41,6 +41,7 @@ + diff --git a/example/hibernate/src/main/resources/META-INF/persistence.xml b/example/hibernate/src/main/resources/META-INF/persistence.xml index 039be4de4..fe81cac32 100644 --- a/example/hibernate/src/main/resources/META-INF/persistence.xml +++ b/example/hibernate/src/main/resources/META-INF/persistence.xml @@ -35,6 +35,7 @@ + From 57372c2bea6e28338222b533b98174e497d1cbed Mon Sep 17 00:00:00 2001 From: Jake Son Date: Tue, 30 Jan 2024 12:31:55 +0900 Subject: [PATCH 017/169] refactor: change order of abs method --- .../com/linecorp/kotlinjdsl/dsl/jpql/Jpql.kt | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) 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 888898258..a103cef67 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 @@ -336,22 +336,6 @@ open class Jpql : JpqlDsl { return Paths.treat(this.toPath(), type) } - /** - * Creates an expression that represents the absolute value. - */ - @SinceJdsl("3.4.0") - fun abs(expr: KProperty1): Expression { - return Expressions.abs(Paths.path(expr)) - } - - /** - * Creates an expression that represents the absolute value. - */ - @SinceJdsl("3.4.0") - fun abs(expr: Expressionable): Expression { - return Expressions.abs(expr.toExpression()) - } - /** * Creates an expression that represents the plus of values. * The values are each enclosed in parentheses. @@ -552,6 +536,22 @@ open class Jpql : JpqlDsl { return Expressions.div(this.toExpression(), value.toExpression()) } + /** + * Creates an expression that represents the absolute value. + */ + @SinceJdsl("3.4.0") + fun abs(expr: KProperty1): Expression { + return Expressions.abs(Paths.path(expr)) + } + + /** + * Creates an expression that represents the absolute value. + */ + @SinceJdsl("3.4.0") + fun abs(expr: Expressionable): Expression { + return Expressions.abs(expr.toExpression()) + } + /** * Creates an expression that represents the count of non-null values. * From 766e61513980013b62869c474275daf0f7a6962f Mon Sep 17 00:00:00 2001 From: Jake Son Date: Tue, 30 Jan 2024 12:35:38 +0900 Subject: [PATCH 018/169] docs: move abs function to arithmetic function --- docs/en/jpql-with-kotlin-jdsl/expressions.md | 11 ++++++++--- docs/ko/jpql-with-kotlin-jdsl/expressions.md | 13 +++++++++---- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/docs/en/jpql-with-kotlin-jdsl/expressions.md b/docs/en/jpql-with-kotlin-jdsl/expressions.md index 3b899e65c..9f23554ab 100644 --- a/docs/en/jpql-with-kotlin-jdsl/expressions.md +++ b/docs/en/jpql-with-kotlin-jdsl/expressions.md @@ -48,15 +48,12 @@ avg(path(FullTimeEmployee::annualSalary)(EmployeeSalary::value)).`as`(BigDecimal Use the following functions to build arithmetic operations: -* abs * \+ (plus) * \- (minus) * \* (times) * / (div) ```kotlin -abs(path(Book::price)) - path(Book::price).plus(path(Book::salePrice)) plus(path(Book::price), path(Book::salePrice)) @@ -207,6 +204,14 @@ Kotlin JDSL provides a series of functions to support built-in functions in JPA. ### Arithmetic functions +Use the following functions to build arithmetic functions: + +* abs + +```kotlin +abs(path(Book::price)) +``` + | Function | DSL function | |----------|--------------| | CEILING | not yet | diff --git a/docs/ko/jpql-with-kotlin-jdsl/expressions.md b/docs/ko/jpql-with-kotlin-jdsl/expressions.md index cd9143959..9cebe0441 100644 --- a/docs/ko/jpql-with-kotlin-jdsl/expressions.md +++ b/docs/ko/jpql-with-kotlin-jdsl/expressions.md @@ -46,17 +46,14 @@ avg(path(FullTimeEmployee::annualSalary)(EmployeeSalary::value)).`as`(BigDecimal ## Arithmetic operations -산술 연사자를 만들기 위해서는 다음 함수들을 사용할 수 있습니다. +산술 연산자를 만들기 위해서는 다음 함수들을 사용할 수 있습니다. -* abs * \+ (plus) * \- (minus) * \* (times) * / (div) ```kotlin -abs(path(Book::price)) - path(Book::price).plus(path(Book::salePrice)) plus(path(Book::price), path(Book::salePrice)) @@ -205,6 +202,14 @@ Kotlin JDSL은 JPA에서 제공하는 여러 함수들을 지원하기 위함 ### Arithmetic functions +산술 함수를 만들기 위해서는 다음 함수들을 사용할 수 있습니다. + +* abs + +```kotlin +abs(path(Book::price)) +``` + | Function | DSL function | |----------|--------------| | CEILING | not yet | From 57d582d95a16bbd69303f2e8caf3faf42229b84a Mon Sep 17 00:00:00 2001 From: JeJune Lee <81547780+LeeJejune@users.noreply.github.com> Date: Tue, 30 Jan 2024 12:44:05 +0900 Subject: [PATCH 019/169] docs: add round function description --- docs/en/jpql-with-kotlin-jdsl/expressions.md | 6 +++++- docs/ko/jpql-with-kotlin-jdsl/expressions.md | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/docs/en/jpql-with-kotlin-jdsl/expressions.md b/docs/en/jpql-with-kotlin-jdsl/expressions.md index ec118d430..b25e1b3a9 100644 --- a/docs/en/jpql-with-kotlin-jdsl/expressions.md +++ b/docs/en/jpql-with-kotlin-jdsl/expressions.md @@ -203,6 +203,11 @@ Kotlin JDSL provides a series of functions to support built-in functions in JPA. | LOCATE | support | ### Arithmetic functions +* round + +```kotlin +round(path(Book::price), Expressions.value(Int::class)) +``` | Function | DSL function | |----------|--------------| @@ -213,7 +218,6 @@ Kotlin JDSL provides a series of functions to support built-in functions in JPA. | LN | not yet | | MOD | not yet | | POWER | not yet | -| ROUND | not yet | | SIGN | not yet | | SQRT | not yet | | SIZE | not yet | diff --git a/docs/ko/jpql-with-kotlin-jdsl/expressions.md b/docs/ko/jpql-with-kotlin-jdsl/expressions.md index e77eadfec..aebbf522e 100644 --- a/docs/ko/jpql-with-kotlin-jdsl/expressions.md +++ b/docs/ko/jpql-with-kotlin-jdsl/expressions.md @@ -201,6 +201,11 @@ Kotlin JDSL은 JPA에서 제공하는 여러 함수들을 지원하기 위함 | LOCATE | support | ### Arithmetic functions +* round + +```kotlin +round(path(Book::price), Expressions.value(Int::class)) +``` | Function | DSL function | |----------|--------------| @@ -211,7 +216,6 @@ Kotlin JDSL은 JPA에서 제공하는 여러 함수들을 지원하기 위함 | LN | not yet | | MOD | not yet | | POWER | not yet | -| ROUND | not yet | | SIGN | not yet | | SQRT | not yet | | SIZE | not yet | From 110cdd08b07b7c4ffc7dbb037d03d873d7a7d83a Mon Sep 17 00:00:00 2001 From: JeJune Lee <81547780+LeeJejune@users.noreply.github.com> Date: Tue, 30 Jan 2024 12:44:31 +0900 Subject: [PATCH 020/169] feat: implement round function expression --- .../com/linecorp/kotlinjdsl/dsl/jpql/Jpql.kt | 16 ++++++ .../dsl/jpql/expression/RoundDslTest.kt | 51 +++++++++++++++++++ .../querymodel/jpql/expression/Expressions.kt | 9 ++++ .../jpql/expression/impl/JpqlRound.kt | 14 +++++ .../jpql/expression/ExpressionsTest.kt | 15 ++++++ 5 files changed, 105 insertions(+) create mode 100644 dsl/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/expression/RoundDslTest.kt create mode 100644 query-model/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/expression/impl/JpqlRound.kt 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..fddc908b9 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 @@ -366,6 +366,22 @@ open class Jpql : JpqlDsl { ) } + /** + * Creates an expression that represents the rounding of the specified property's value to a specified scale. + */ + @SinceJdsl("3.4.0") + fun round(expr: KProperty1, scale: Expression): Expression { + return Expressions.round(Paths.path(expr), scale.toExpression()) + } + + /** + * Creates an expression that represents the rounding of the specified property's value to a specified scale. + */ + @SinceJdsl("3.4.0") + fun round(value: Expressionable, scale: Expressionable): Expression { + return Expressions.round(value.toExpression(), scale.toExpression()) + } + /** * Creates an expression that represents the plus of values. * diff --git a/dsl/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/expression/RoundDslTest.kt b/dsl/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/expression/RoundDslTest.kt new file mode 100644 index 000000000..54664611b --- /dev/null +++ b/dsl/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/expression/RoundDslTest.kt @@ -0,0 +1,51 @@ +package com.linecorp.kotlinjdsl.dsl.jpql.expression + +import com.linecorp.kotlinjdsl.dsl.jpql.entity.book.Book +import com.linecorp.kotlinjdsl.dsl.jpql.queryPart +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expression +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expressions +import com.linecorp.kotlinjdsl.querymodel.jpql.path.Paths +import org.assertj.core.api.WithAssertions +import org.junit.jupiter.api.Test + +class RoundDslTest : WithAssertions { + private val expression1 = Paths.path(Book::salePrice) + private val intExpression1: Expression = Expressions.value(3) + private val int1 = 3 + + @Test + fun `round() with a expression`() { + // when + val expression = queryPart { + round(expression1, intExpression1) + }.toExpression() + + val actual: Expression = expression // for type check + + // then + val expected = Expressions.round( + value = expression1, + scale = intExpression1, + ) + + assertThat(actual).isEqualTo(expected) + } + + @Test + fun `round() with a property`() { + // when + val expression = queryPart { + round(Book::price, intExpression1) + }.toExpression() + + val actual: Expression = expression // for type check + + // then + val expected = Expressions.round( + value = Paths.path(Book::price), + scale = Expressions.value(int1), + ) + + 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..bc417a9a0 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 @@ -38,6 +38,7 @@ import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlTrimLeading import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlTrimTrailing import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlUpper import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlValue +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlRound import com.linecorp.kotlinjdsl.querymodel.jpql.path.Path import com.linecorp.kotlinjdsl.querymodel.jpql.predicate.Predicate import com.linecorp.kotlinjdsl.querymodel.jpql.select.SelectQuery @@ -246,6 +247,14 @@ object Expressions { return JpqlAvg(distinct, expr) } + /** + * Creates an expression that represents the rounding of the specified property's value to a specified scale. + */ + @SinceJdsl("3.4.0") + fun round(value: Expression, scale: Expression): Expression { + return JpqlRound(value, scale) + } + /** * Creates an expression that represents the sum of values. * diff --git a/query-model/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/expression/impl/JpqlRound.kt b/query-model/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/expression/impl/JpqlRound.kt new file mode 100644 index 000000000..3af3c5160 --- /dev/null +++ b/query-model/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/expression/impl/JpqlRound.kt @@ -0,0 +1,14 @@ +package com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl + +import com.linecorp.kotlinjdsl.Internal +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expression + +/** + * Expression that calculates the rounding of a numeric [value] to a specified [scale]. + */ +@Internal +data class JpqlRound internal constructor( + val value: Expression, + val scale: Expression, +) : 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..6bf579a5d 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 @@ -30,6 +30,7 @@ import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlNullIf import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlParam import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlPathType import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlPlus +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlRound import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlSubquery import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlSubstring import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlSum @@ -392,6 +393,20 @@ class ExpressionsTest : WithAssertions { assertThat(actual).isEqualTo(expected) } + @Test + fun round() { + // when + val actual = Expressions.round(doubleExpression1, intExpression1) + + // then + val expected = JpqlRound( + doubleExpression1, + intExpression1 + ) + + assertThat(actual).isEqualTo(expected) + } + @ParameterizedTest @ValueSource(booleans = [true, false]) fun `sum() with an int expression`(distinct: Boolean) { From 96c740bc908bac159c4613372829495264096dbf Mon Sep 17 00:00:00 2001 From: JeJune Lee <81547780+LeeJejune@users.noreply.github.com> Date: Tue, 30 Jan 2024 12:44:40 +0900 Subject: [PATCH 021/169] feat: implement round function expression --- .../render/jpql/JpqlRenderContext.kt | 2 + .../serializer/impl/JpqlRoundSerializer.kt | 27 +++++++++ .../impl/JpqlRoundSerializerTest.kt | 58 +++++++++++++++++++ 3 files changed, 87 insertions(+) create mode 100644 render/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlRoundSerializer.kt create mode 100644 render/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlRoundSerializerTest.kt 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..b60d0336e 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 @@ -93,6 +93,7 @@ import com.linecorp.kotlinjdsl.render.jpql.serializer.impl.JpqlPathTreatSerializ import com.linecorp.kotlinjdsl.render.jpql.serializer.impl.JpqlPathTypeSerializer import com.linecorp.kotlinjdsl.render.jpql.serializer.impl.JpqlPlusSerializer import com.linecorp.kotlinjdsl.render.jpql.serializer.impl.JpqlPredicateParenthesesSerializer +import com.linecorp.kotlinjdsl.render.jpql.serializer.impl.JpqlRoundSerializer import com.linecorp.kotlinjdsl.render.jpql.serializer.impl.JpqlSelectQuerySerializer import com.linecorp.kotlinjdsl.render.jpql.serializer.impl.JpqlSortSerializer import com.linecorp.kotlinjdsl.render.jpql.serializer.impl.JpqlSubquerySerializer @@ -261,6 +262,7 @@ private class DefaultModule : JpqlRenderModule { JpqlAliasedExpressionSerializer(), JpqlAndSerializer(), JpqlAvgSerializer(), + JpqlRoundSerializer(), JpqlBetweenSerializer(), JpqlCaseValueSerializer(), JpqlCaseWhenSerializer(), diff --git a/render/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlRoundSerializer.kt b/render/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlRoundSerializer.kt new file mode 100644 index 000000000..d630b37c8 --- /dev/null +++ b/render/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlRoundSerializer.kt @@ -0,0 +1,27 @@ +package com.linecorp.kotlinjdsl.render.jpql.serializer.impl + +import com.linecorp.kotlinjdsl.Internal +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlRound +import com.linecorp.kotlinjdsl.render.RenderContext +import com.linecorp.kotlinjdsl.render.jpql.serializer.JpqlRenderSerializer +import com.linecorp.kotlinjdsl.render.jpql.serializer.JpqlSerializer +import com.linecorp.kotlinjdsl.render.jpql.writer.JpqlWriter +import kotlin.reflect.KClass + +@Internal +class JpqlRoundSerializer : JpqlSerializer>{ + override fun handledType(): KClass> { + return JpqlRound::class + } + + override fun serialize(part: JpqlRound<*>, writer: JpqlWriter, context: RenderContext) { + val delegate = context.getValue(JpqlRenderSerializer) + + writer.write("ROUND") + writer.write(" ") + delegate.serialize(part.value, writer, context) + + writer.write(", ") + delegate.serialize(part.scale, writer, context) + } +} diff --git a/render/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlRoundSerializerTest.kt b/render/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlRoundSerializerTest.kt new file mode 100644 index 000000000..0f4d97742 --- /dev/null +++ b/render/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlRoundSerializerTest.kt @@ -0,0 +1,58 @@ +package com.linecorp.kotlinjdsl.render.jpql.serializer.impl + +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expressions +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlRound +import com.linecorp.kotlinjdsl.querymodel.jpql.path.Paths +import com.linecorp.kotlinjdsl.render.TestRenderContext +import com.linecorp.kotlinjdsl.render.jpql.entity.book.Book +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 JpqlRoundSerializerTest { + private val sut = JpqlRoundSerializer() + + @MockK + private lateinit var writer: JpqlWriter + + @MockK + private lateinit var serializer: JpqlRenderSerializer + + private val expression1 = Paths.path(Book::price) + private val expression2 = Expressions.value(3) + + @Test + fun handledType() { + // when + val actual = sut.handledType() + + // then + assertThat(actual).isEqualTo(JpqlRound::class) + } + @Test + fun serialize() { + // given + val part = Expressions.round( + value = expression1, + scale = expression2 + ) + val context = TestRenderContext(serializer) + + // when + sut.serialize(part as JpqlRound<*>, writer, context) + + // then + verifySequence { + writer.write("ROUND") + writer.write(" ") + serializer.serialize(expression1, writer, context) + writer.write(", ") + serializer.serialize(expression2, writer, context) + } + } +} From 526276335607215d3e7f34845319bbb8f59fa80a Mon Sep 17 00:00:00 2001 From: aesperer Date: Tue, 30 Jan 2024 14:03:26 +0900 Subject: [PATCH 022/169] add :: ceiling docs in jpql with kotlin jdsl md --- docs/en/jpql-with-kotlin-jdsl/expressions.md | 3 +++ docs/ko/jpql-with-kotlin-jdsl/expressions.md | 3 +++ 2 files changed, 6 insertions(+) diff --git a/docs/en/jpql-with-kotlin-jdsl/expressions.md b/docs/en/jpql-with-kotlin-jdsl/expressions.md index ec118d430..c9f67b0ed 100644 --- a/docs/en/jpql-with-kotlin-jdsl/expressions.md +++ b/docs/en/jpql-with-kotlin-jdsl/expressions.md @@ -52,6 +52,7 @@ Use the following functions to build arithmetic operations: * \- (minus) * \* (times) * / (div) +* ceiling ```kotlin path(Book::price).plus(path(Book::salePrice)) @@ -65,6 +66,8 @@ times(path(Book::price), path(Book::salePrice)) path(Book::price).div(path(Book::salePrice)) div(path(Book::price), path(Book::salePrice)) + +ceiling(path(Book::price)) ``` ### Parentheses diff --git a/docs/ko/jpql-with-kotlin-jdsl/expressions.md b/docs/ko/jpql-with-kotlin-jdsl/expressions.md index e77eadfec..77b35b5d8 100644 --- a/docs/ko/jpql-with-kotlin-jdsl/expressions.md +++ b/docs/ko/jpql-with-kotlin-jdsl/expressions.md @@ -52,6 +52,7 @@ avg(path(FullTimeEmployee::annualSalary)(EmployeeSalary::value)).`as`(BigDecimal * \- (minus) * \* (times) * / (div) +* ceiling ```kotlin path(Book::price).plus(path(Book::salePrice)) @@ -65,6 +66,8 @@ times(path(Book::price), path(Book::salePrice)) path(Book::price).div(path(Book::salePrice)) div(path(Book::price), path(Book::salePrice)) + +ceiling(path(Book::price)) ``` ### Parentheses From 168648c49b797bec18e90fe1bcaa92e7eaa148d0 Mon Sep 17 00:00:00 2001 From: aesperer Date: Tue, 30 Jan 2024 14:16:21 +0900 Subject: [PATCH 023/169] add ceiling operator jdsl --- .../kotlin/com/linecorp/kotlinjdsl/dsl/jpql/Jpql.kt | 5 +++++ .../querymodel/jpql/expression/Expressions.kt | 9 +++++++++ .../querymodel/jpql/expression/impl/JpqlCeiling.kt | 12 ++++++++++++ 3 files changed, 26 insertions(+) create mode 100644 query-model/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/expression/impl/JpqlCeiling.kt 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..22d806f9e 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 @@ -436,6 +436,11 @@ open class Jpql : JpqlDsl { return Expressions.minus(this.toExpression(), value.toExpression()) } + @SinceJdsl("3.4.0") + fun ceiling(value: Expressionable): Expression { + return Expressions.ceiling(value.toExpression()) + } + /** * Creates an expression that represents the times of values. * The values are each enclosed in parentheses. 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..f096f6105 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 @@ -6,6 +6,7 @@ import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlAliasedExpres import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlAvg import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlCaseValue import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlCaseWhen +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlCeiling import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlCoalesce import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlConcat import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlCount @@ -633,4 +634,12 @@ object Expressions { fun parentheses(expr: Expression): Expression { return JpqlExpressionParentheses(expr) } + + /** + * Creates an expression that is enclosed in ceiling + */ + @SinceJdsl("3.4.0") + fun ceiling(expr: Expression): Expression { + return JpqlCeiling(expr) + } } diff --git a/query-model/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/expression/impl/JpqlCeiling.kt b/query-model/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/expression/impl/JpqlCeiling.kt new file mode 100644 index 000000000..c4bc973e4 --- /dev/null +++ b/query-model/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/expression/impl/JpqlCeiling.kt @@ -0,0 +1,12 @@ +package com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl + +import com.linecorp.kotlinjdsl.Internal +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expression + +/** + * Expression that calculates the ceiling of [value]. + */ +@Internal +data class JpqlCeiling internal constructor( + val value: Expression +) : Expression From 4c1185aa9fef9479b7ceb082112b8dc171a5118d Mon Sep 17 00:00:00 2001 From: aesperer Date: Tue, 30 Jan 2024 14:18:38 +0900 Subject: [PATCH 024/169] create expression test ceiling --- .../com/linecorp/kotlinjdsl/dsl/jpql/Jpql.kt | 2 +- .../querymodel/jpql/expression/Expressions.kt | 2 +- .../querymodel/jpql/expression/impl/JpqlCeiling.kt | 4 ++-- .../querymodel/jpql/expression/ExpressionsTest.kt | 14 ++++++++++++++ 4 files changed, 18 insertions(+), 4 deletions(-) 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 22d806f9e..1153e0753 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 @@ -437,7 +437,7 @@ open class Jpql : JpqlDsl { } @SinceJdsl("3.4.0") - fun ceiling(value: Expressionable): Expression { + fun ceiling(value: Expressionable): Expression { return Expressions.ceiling(value.toExpression()) } 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 f096f6105..a08041660 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 @@ -639,7 +639,7 @@ object Expressions { * Creates an expression that is enclosed in ceiling */ @SinceJdsl("3.4.0") - fun ceiling(expr: Expression): Expression { + fun ceiling(expr: Expression): Expression { return JpqlCeiling(expr) } } diff --git a/query-model/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/expression/impl/JpqlCeiling.kt b/query-model/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/expression/impl/JpqlCeiling.kt index c4bc973e4..d66fc5db2 100644 --- a/query-model/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/expression/impl/JpqlCeiling.kt +++ b/query-model/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/expression/impl/JpqlCeiling.kt @@ -7,6 +7,6 @@ import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expression * Expression that calculates the ceiling of [value]. */ @Internal -data class JpqlCeiling internal constructor( - val value: Expression +data class JpqlCeiling internal constructor( + val value: Expression, ) : 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..bcb93e81b 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 @@ -8,6 +8,7 @@ import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlAliasedExpres import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlAvg import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlCaseValue import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlCaseWhen +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlCeiling import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlCoalesce import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlConcat import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlCount @@ -887,4 +888,17 @@ class ExpressionsTest : WithAssertions { assertThat(actual).isEqualTo(expected) } + + @Test + fun ceiling() { + // when + val actual = Expressions.ceiling(doubleExpression1) + + // then + val expected = JpqlCeiling( + doubleExpression1 + ) + + assertThat(actual).isEqualTo(expected) + } } From 0b2d55aedc17b993014dc18162468f0dac4b24ba Mon Sep 17 00:00:00 2001 From: aesperer Date: Tue, 30 Jan 2024 14:22:02 +0900 Subject: [PATCH 025/169] create jpql ceiling serializer, render context --- .../jpql/expression/ExpressionsTest.kt | 2 +- .../render/jpql/JpqlRenderContext.kt | 2 ++ .../serializer/impl/JpqlCeilingSerializer.kt | 26 +++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 render/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlCeilingSerializer.kt 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 bcb93e81b..a9f000f83 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 @@ -896,7 +896,7 @@ class ExpressionsTest : WithAssertions { // then val expected = JpqlCeiling( - doubleExpression1 + doubleExpression1, ) assertThat(actual).isEqualTo(expected) 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..fd38144ce 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 @@ -19,6 +19,7 @@ import com.linecorp.kotlinjdsl.render.jpql.serializer.impl.JpqlAvgSerializer import com.linecorp.kotlinjdsl.render.jpql.serializer.impl.JpqlBetweenSerializer import com.linecorp.kotlinjdsl.render.jpql.serializer.impl.JpqlCaseValueSerializer import com.linecorp.kotlinjdsl.render.jpql.serializer.impl.JpqlCaseWhenSerializer +import com.linecorp.kotlinjdsl.render.jpql.serializer.impl.JpqlCeilingSerializer import com.linecorp.kotlinjdsl.render.jpql.serializer.impl.JpqlCoalesceSerializer import com.linecorp.kotlinjdsl.render.jpql.serializer.impl.JpqlConcatSerializer import com.linecorp.kotlinjdsl.render.jpql.serializer.impl.JpqlCountSerializer @@ -351,6 +352,7 @@ private class DefaultModule : JpqlRenderModule { JpqlUpdateQuerySerializer(), JpqlUpperSerializer(), JpqlValueSerializer(), + JpqlCeilingSerializer(), ) } } diff --git a/render/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlCeilingSerializer.kt b/render/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlCeilingSerializer.kt new file mode 100644 index 000000000..321d3dca3 --- /dev/null +++ b/render/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlCeilingSerializer.kt @@ -0,0 +1,26 @@ +package com.linecorp.kotlinjdsl.render.jpql.serializer.impl + +import com.linecorp.kotlinjdsl.Internal +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlCeiling +import com.linecorp.kotlinjdsl.render.RenderContext +import com.linecorp.kotlinjdsl.render.jpql.serializer.JpqlRenderSerializer +import com.linecorp.kotlinjdsl.render.jpql.serializer.JpqlSerializer +import com.linecorp.kotlinjdsl.render.jpql.writer.JpqlWriter +import kotlin.reflect.KClass + +@Internal +class JpqlCeilingSerializer : JpqlSerializer> { + override fun handledType(): KClass> { + return JpqlCeiling::class + } + + override fun serialize(part: JpqlCeiling<*>, writer: JpqlWriter, context: RenderContext) { + val delegate = context.getValue(JpqlRenderSerializer) + + writer.write("CEILING") + + writer.writeParentheses { + delegate.serialize(part.value, writer, context) + } + } +} From ad8e5dd0335fa96946a036de6feb0269ebdfca2b Mon Sep 17 00:00:00 2001 From: aesperer Date: Tue, 30 Jan 2024 14:30:15 +0900 Subject: [PATCH 026/169] create test jpql celing serializer test --- .../querymodel/jpql/expression/Expressions.kt | 16 +++--- .../impl/JpqlCeilingSerializerTest.kt | 55 +++++++++++++++++++ 2 files changed, 64 insertions(+), 7 deletions(-) create mode 100644 render/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlCeilingSerializerTest.kt 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 a08041660..15ead4931 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 @@ -187,6 +187,14 @@ object Expressions { return JpqlMinus(value1, value2) } + /** + * Creates an expression that is enclosed in ceiling + */ + @SinceJdsl("3.4.0") + fun ceiling(value: Expression): Expression { + return JpqlCeiling(value) + } + /** * Creates an expression that represents the times of values. * @@ -635,11 +643,5 @@ object Expressions { return JpqlExpressionParentheses(expr) } - /** - * Creates an expression that is enclosed in ceiling - */ - @SinceJdsl("3.4.0") - fun ceiling(expr: Expression): Expression { - return JpqlCeiling(expr) - } + } diff --git a/render/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlCeilingSerializerTest.kt b/render/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlCeilingSerializerTest.kt new file mode 100644 index 000000000..1a042ce43 --- /dev/null +++ b/render/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlCeilingSerializerTest.kt @@ -0,0 +1,55 @@ +package com.linecorp.kotlinjdsl.render.jpql.serializer.impl + +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expressions +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlCeiling +import com.linecorp.kotlinjdsl.querymodel.jpql.path.Paths +import com.linecorp.kotlinjdsl.render.TestRenderContext +import com.linecorp.kotlinjdsl.render.jpql.entity.book.Book +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.WithAssertions +import org.junit.jupiter.api.Test + +@JpqlSerializerTest +class JpqlCeilingSerializerTest : WithAssertions { + private val sut = JpqlCeilingSerializer() + + @MockK + private lateinit var writer: JpqlWriter + + @MockK + private lateinit var serializer: JpqlRenderSerializer + + private val expression1 = Paths.path(Book::price) + + @Test + fun handledType() { + // when + val actual = sut.handledType() + + // then + assertThat(actual).isEqualTo(JpqlCeiling::class) + } + + @Test + fun serialize() { + // given + val part = Expressions.ceiling( + value = expression1, + ) + val context = TestRenderContext(serializer) + + // when + sut.serialize(part as JpqlCeiling<*>, writer, context) + + // then + verifySequence { + writer.write("CEILING") + writer.writeParentheses(any()) + serializer.serialize(expression1, writer, context) + } + } +} From 15c2591733b896d04e6aabf8d9917f36451f212b Mon Sep 17 00:00:00 2001 From: aesperer Date: Tue, 30 Jan 2024 14:49:42 +0900 Subject: [PATCH 027/169] update docs, and create celing dsl test 2 case --- docs/en/jpql-with-kotlin-jdsl/expressions.md | 15 ++++-- docs/ko/jpql-with-kotlin-jdsl/expressions.md | 32 +++++++----- .../com/linecorp/kotlinjdsl/dsl/jpql/Jpql.kt | 13 ++++- .../dsl/jpql/expression/CeilingDslTest.kt | 49 +++++++++++++++++++ .../querymodel/jpql/expression/Expressions.kt | 4 +- .../jpql/expression/impl/JpqlCeiling.kt | 2 +- 6 files changed, 93 insertions(+), 22 deletions(-) create mode 100644 dsl/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/expression/CeilingDslTest.kt diff --git a/docs/en/jpql-with-kotlin-jdsl/expressions.md b/docs/en/jpql-with-kotlin-jdsl/expressions.md index c9f67b0ed..ea8652748 100644 --- a/docs/en/jpql-with-kotlin-jdsl/expressions.md +++ b/docs/en/jpql-with-kotlin-jdsl/expressions.md @@ -52,7 +52,6 @@ Use the following functions to build arithmetic operations: * \- (minus) * \* (times) * / (div) -* ceiling ```kotlin path(Book::price).plus(path(Book::salePrice)) @@ -66,8 +65,6 @@ times(path(Book::price), path(Book::salePrice)) path(Book::price).div(path(Book::salePrice)) div(path(Book::price), path(Book::salePrice)) - -ceiling(path(Book::price)) ``` ### Parentheses @@ -174,6 +171,8 @@ minDistinct(path(Book::price)) sum(path(Book::price)) sumDistinct(path(Book::price)) + +ceiling(path(Book::price)) ``` ### Sum @@ -205,12 +204,20 @@ Kotlin JDSL provides a series of functions to support built-in functions in JPA. | LENGTH | support | | LOCATE | support | + ### Arithmetic functions +Use the following functions to build arithmetic functions: + +* ceiling + +```kotlin +ceiling(path(Book::price)) +``` + | Function | DSL function | |----------|--------------| | ABS | not yet | -| CEILING | not yet | | EXP | not yet | | FLOOR | not yet | | LN | not yet | diff --git a/docs/ko/jpql-with-kotlin-jdsl/expressions.md b/docs/ko/jpql-with-kotlin-jdsl/expressions.md index 77b35b5d8..c4327a60a 100644 --- a/docs/ko/jpql-with-kotlin-jdsl/expressions.md +++ b/docs/ko/jpql-with-kotlin-jdsl/expressions.md @@ -46,7 +46,7 @@ avg(path(FullTimeEmployee::annualSalary)(EmployeeSalary::value)).`as`(BigDecimal ## Arithmetic operations -산술 연사자를 만들기 위해서는 다음 함수들을 사용할 수 있습니다. +산술 연산자를 만들기 위해서는 다음 함수들을 사용할 수 있습니다. * \+ (plus) * \- (minus) @@ -66,8 +66,6 @@ times(path(Book::price), path(Book::salePrice)) path(Book::price).div(path(Book::salePrice)) div(path(Book::price), path(Book::salePrice)) - -ceiling(path(Book::price)) ``` ### Parentheses @@ -193,22 +191,30 @@ Kotlin JDSL은 JPA에서 제공하는 여러 함수들을 지원하기 위함 ### String functions -| Function | DSL function | -|-----------|--------------| -| CONCAT | support | -| SUBSTRING | support | -| TRIM | support | -| LOWER | support | -| UPPER | support | -| LENGTH | support | -| LOCATE | support | +| Function | DSL function | +|------------|--------------| +| CONCAT | support | +| SUBSTRING | support | +| TRIM | support | +| LOWER | support | +| UPPER | support | +| LENGTH | support | +| LOCATE | support | +| CEILING | support | ### Arithmetic functions +산술 함수를 만들기 위해서는 다음 함수들을 사용할 수 있습니다. + +* ceiling + +```kotlin +ceiling(path(Book::price)) +``` + | Function | DSL function | |----------|--------------| | ABS | not yet | -| CEILING | not yet | | EXP | not yet | | FLOOR | not yet | | LN | 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 1153e0753..b950e7272 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 @@ -436,11 +436,22 @@ open class Jpql : JpqlDsl { return Expressions.minus(this.toExpression(), value.toExpression()) } + /** + * Creates an expression that is enclosed in ceiling + */ @SinceJdsl("3.4.0") - fun ceiling(value: Expressionable): Expression { + fun ceiling(value: Expressionable): Expression { return Expressions.ceiling(value.toExpression()) } + /** + * Creates an expression that is enclosed in ceiling + */ + @SinceJdsl("3.4.0") + fun ceiling(expr: KProperty1): Expression { + return Expressions.ceiling(Paths.path(expr)) + } + /** * Creates an expression that represents the times of values. * The values are each enclosed in parentheses. diff --git a/dsl/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/expression/CeilingDslTest.kt b/dsl/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/expression/CeilingDslTest.kt new file mode 100644 index 000000000..d4ac3324d --- /dev/null +++ b/dsl/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/expression/CeilingDslTest.kt @@ -0,0 +1,49 @@ +package com.linecorp.kotlinjdsl.dsl.jpql.expression + +import com.linecorp.kotlinjdsl.dsl.jpql.entity.book.Book +import com.linecorp.kotlinjdsl.dsl.jpql.queryPart +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expression +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expressions +import com.linecorp.kotlinjdsl.querymodel.jpql.path.Paths +import org.assertj.core.api.WithAssertions +import org.junit.jupiter.api.Test +import java.math.BigDecimal +import kotlin.math.ceil + +class CeilingDslTest : WithAssertions { + private val expression1 = Paths.path(Book::price) + + @Test + fun `ceiling() with a property`() { + // when + val expression = queryPart { + ceiling(Book::price) + }.toExpression() + + val actual: Expression = expression // for type check + + // then + val expected = Expressions.ceiling( + value = Paths.path(Book::price), + ) + + assertThat(actual).isEqualTo(expected) + } + + @Test + fun `ceiling() with a expression`() { + // when + val expression = queryPart { + ceiling(expression1) + }.toExpression() + + val actual: Expression = expression // for type check + + // then + val expected = Expressions.ceiling( + value = expression1 + ) + + 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 15ead4931..10528221d 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 @@ -191,7 +191,7 @@ object Expressions { * Creates an expression that is enclosed in ceiling */ @SinceJdsl("3.4.0") - fun ceiling(value: Expression): Expression { + fun ceiling(value: Expression): Expression { return JpqlCeiling(value) } @@ -642,6 +642,4 @@ object Expressions { fun parentheses(expr: Expression): Expression { return JpqlExpressionParentheses(expr) } - - } diff --git a/query-model/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/expression/impl/JpqlCeiling.kt b/query-model/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/expression/impl/JpqlCeiling.kt index d66fc5db2..928f88615 100644 --- a/query-model/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/expression/impl/JpqlCeiling.kt +++ b/query-model/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/expression/impl/JpqlCeiling.kt @@ -9,4 +9,4 @@ import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expression @Internal data class JpqlCeiling internal constructor( val value: Expression, -) : Expression +) : Expression From 5644b86bd13aafc230ce45b7de7f5f82221e484b Mon Sep 17 00:00:00 2001 From: aesperer Date: Tue, 30 Jan 2024 14:51:44 +0900 Subject: [PATCH 028/169] delete why ceiling in the string functions list.. --- docs/ko/jpql-with-kotlin-jdsl/expressions.md | 1 - .../linecorp/kotlinjdsl/dsl/jpql/expression/CeilingDslTest.kt | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/docs/ko/jpql-with-kotlin-jdsl/expressions.md b/docs/ko/jpql-with-kotlin-jdsl/expressions.md index c4327a60a..44870c8d4 100644 --- a/docs/ko/jpql-with-kotlin-jdsl/expressions.md +++ b/docs/ko/jpql-with-kotlin-jdsl/expressions.md @@ -200,7 +200,6 @@ Kotlin JDSL은 JPA에서 제공하는 여러 함수들을 지원하기 위함 | UPPER | support | | LENGTH | support | | LOCATE | support | -| CEILING | support | ### Arithmetic functions diff --git a/dsl/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/expression/CeilingDslTest.kt b/dsl/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/expression/CeilingDslTest.kt index d4ac3324d..697318e05 100644 --- a/dsl/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/expression/CeilingDslTest.kt +++ b/dsl/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/expression/CeilingDslTest.kt @@ -8,7 +8,6 @@ import com.linecorp.kotlinjdsl.querymodel.jpql.path.Paths import org.assertj.core.api.WithAssertions import org.junit.jupiter.api.Test import java.math.BigDecimal -import kotlin.math.ceil class CeilingDslTest : WithAssertions { private val expression1 = Paths.path(Book::price) @@ -41,7 +40,7 @@ class CeilingDslTest : WithAssertions { // then val expected = Expressions.ceiling( - value = expression1 + value = expression1, ) assertThat(actual).isEqualTo(expected) From 4ea6f4a0b4b54741fdeec35e31d7c895ef289469 Mon Sep 17 00:00:00 2001 From: JeJune Lee <81547780+LeeJejune@users.noreply.github.com> Date: Tue, 30 Jan 2024 15:08:30 +0900 Subject: [PATCH 029/169] fix: round function with writeParentheses --- .../render/jpql/serializer/impl/JpqlRoundSerializer.kt | 10 ++++++---- .../jpql/serializer/impl/JpqlRoundSerializerTest.kt | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/render/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlRoundSerializer.kt b/render/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlRoundSerializer.kt index d630b37c8..cba82561d 100644 --- a/render/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlRoundSerializer.kt +++ b/render/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlRoundSerializer.kt @@ -18,10 +18,12 @@ class JpqlRoundSerializer : JpqlSerializer>{ val delegate = context.getValue(JpqlRenderSerializer) writer.write("ROUND") - writer.write(" ") - delegate.serialize(part.value, writer, context) - writer.write(", ") - delegate.serialize(part.scale, writer, context) + writer.writeParentheses { + delegate.serialize(part.value, writer, context) + + writer.write(", ") + delegate.serialize(part.scale, writer, context) + } } } diff --git a/render/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlRoundSerializerTest.kt b/render/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlRoundSerializerTest.kt index 0f4d97742..766641b7e 100644 --- a/render/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlRoundSerializerTest.kt +++ b/render/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlRoundSerializerTest.kt @@ -49,7 +49,7 @@ class JpqlRoundSerializerTest { // then verifySequence { writer.write("ROUND") - writer.write(" ") + writer.writeParentheses(any()) serializer.serialize(expression1, writer, context) writer.write(", ") serializer.serialize(expression2, writer, context) From ed52f0053fb601cc6c50133d4024efe9c23a76ad Mon Sep 17 00:00:00 2001 From: aesperer Date: Tue, 30 Jan 2024 15:09:36 +0900 Subject: [PATCH 030/169] delet space string functions table --- docs/ko/jpql-with-kotlin-jdsl/expressions.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/docs/ko/jpql-with-kotlin-jdsl/expressions.md b/docs/ko/jpql-with-kotlin-jdsl/expressions.md index 44870c8d4..1aa094025 100644 --- a/docs/ko/jpql-with-kotlin-jdsl/expressions.md +++ b/docs/ko/jpql-with-kotlin-jdsl/expressions.md @@ -191,15 +191,15 @@ Kotlin JDSL은 JPA에서 제공하는 여러 함수들을 지원하기 위함 ### String functions -| Function | DSL function | -|------------|--------------| -| CONCAT | support | -| SUBSTRING | support | -| TRIM | support | -| LOWER | support | -| UPPER | support | -| LENGTH | support | -| LOCATE | support | +| Function | DSL function | +|-----------|--------------| +| CONCAT | support | +| SUBSTRING | support | +| TRIM | support | +| LOWER | support | +| UPPER | support | +| LENGTH | support | +| LOCATE | support | ### Arithmetic functions From 27401bd996895359b2e0257cd925e43b770855e1 Mon Sep 17 00:00:00 2001 From: JeJune Lee <81547780+LeeJejune@users.noreply.github.com> Date: Tue, 30 Jan 2024 16:43:05 +0900 Subject: [PATCH 031/169] fix: fix serializers order by alphabetical order --- .../com/linecorp/kotlinjdsl/render/jpql/JpqlRenderContext.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 b60d0336e..3e2c20840 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 @@ -262,7 +262,6 @@ private class DefaultModule : JpqlRenderModule { JpqlAliasedExpressionSerializer(), JpqlAndSerializer(), JpqlAvgSerializer(), - JpqlRoundSerializer(), JpqlBetweenSerializer(), JpqlCaseValueSerializer(), JpqlCaseWhenSerializer(), @@ -340,6 +339,7 @@ private class DefaultModule : JpqlRenderModule { JpqlPathTypeSerializer(), JpqlPlusSerializer(), JpqlPredicateParenthesesSerializer(), + JpqlRoundSerializer(), JpqlSelectQuerySerializer(), JpqlSortSerializer(), JpqlSubquerySerializer(), From 50a8ab468f6fe09781d1813cc97d96737c152dd4 Mon Sep 17 00:00:00 2001 From: aesperer Date: Tue, 30 Jan 2024 23:01:01 +0900 Subject: [PATCH 032/169] chore :: move to ceiling under abs --- .../com/linecorp/kotlinjdsl/dsl/jpql/Jpql.kt | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) 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 12262df65..dd82803f3 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 @@ -436,22 +436,6 @@ open class Jpql : JpqlDsl { return Expressions.minus(this.toExpression(), value.toExpression()) } - /** - * Creates an expression that is enclosed in ceiling - */ - @SinceJdsl("3.4.0") - fun ceiling(value: Expressionable): Expression { - return Expressions.ceiling(value.toExpression()) - } - - /** - * Creates an expression that is enclosed in ceiling - */ - @SinceJdsl("3.4.0") - fun ceiling(expr: KProperty1): Expression { - return Expressions.ceiling(Paths.path(expr)) - } - /** * Creates an expression that represents the times of values. * The values are each enclosed in parentheses. @@ -568,6 +552,22 @@ open class Jpql : JpqlDsl { return Expressions.abs(expr.toExpression()) } + /** + * Creates an expression that is enclosed in ceiling + */ + @SinceJdsl("3.4.0") + fun ceiling(value: Expressionable): Expression { + return Expressions.ceiling(value.toExpression()) + } + + /** + * Creates an expression that is enclosed in ceiling + */ + @SinceJdsl("3.4.0") + fun ceiling(expr: KProperty1): Expression { + return Expressions.ceiling(Paths.path(expr)) + } + /** * Creates an expression that represents the count of non-null values. * From 0ad8b41258d1e2dbe0b0e568fba6f305fc9a4d3a Mon Sep 17 00:00:00 2001 From: "jonghyon.s" Date: Tue, 30 Jan 2024 23:38:58 +0900 Subject: [PATCH 033/169] style: order function position --- .../main/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/Jpql.kt | 8 ++++---- .../linecorp/kotlinjdsl/render/jpql/JpqlRenderContext.kt | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) 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 dd82803f3..c6bd4b53e 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 @@ -556,16 +556,16 @@ open class Jpql : JpqlDsl { * Creates an expression that is enclosed in ceiling */ @SinceJdsl("3.4.0") - fun ceiling(value: Expressionable): Expression { - return Expressions.ceiling(value.toExpression()) + fun ceiling(expr: KProperty1): Expression { + return Expressions.ceiling(Paths.path(expr)) } /** * Creates an expression that is enclosed in ceiling */ @SinceJdsl("3.4.0") - fun ceiling(expr: KProperty1): Expression { - return Expressions.ceiling(Paths.path(expr)) + fun ceiling(value: Expressionable): Expression { + return Expressions.ceiling(value.toExpression()) } /** 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 dbbddb044..d17578ed3 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 @@ -267,6 +267,7 @@ private class DefaultModule : JpqlRenderModule { JpqlBetweenSerializer(), JpqlCaseValueSerializer(), JpqlCaseWhenSerializer(), + JpqlCeilingSerializer(), JpqlCoalesceSerializer(), JpqlConcatSerializer(), JpqlCountSerializer(), @@ -354,7 +355,6 @@ private class DefaultModule : JpqlRenderModule { JpqlUpdateQuerySerializer(), JpqlUpperSerializer(), JpqlValueSerializer(), - JpqlCeilingSerializer(), ) } } From 3cab441702e09698c1f3e4975006aca3127c09b8 Mon Sep 17 00:00:00 2001 From: "jonghyon.s" Date: Tue, 30 Jan 2024 23:49:38 +0900 Subject: [PATCH 034/169] docs: reformat functions --- docs/en/jpql-with-kotlin-jdsl/expressions.md | 37 ++++++++++++------ docs/ko/jpql-with-kotlin-jdsl/expressions.md | 41 +++++++++++++------- 2 files changed, 53 insertions(+), 25 deletions(-) diff --git a/docs/en/jpql-with-kotlin-jdsl/expressions.md b/docs/en/jpql-with-kotlin-jdsl/expressions.md index 338ed2b4c..a3f0f2995 100644 --- a/docs/en/jpql-with-kotlin-jdsl/expressions.md +++ b/docs/en/jpql-with-kotlin-jdsl/expressions.md @@ -194,26 +194,41 @@ Kotlin JDSL provides a series of functions to support built-in functions in JPA. ### String functions -| Function | DSL function | -|-----------|--------------| -| CONCAT | support | -| SUBSTRING | support | -| TRIM | support | -| LOWER | support | -| UPPER | support | -| LENGTH | support | -| LOCATE | support | +* CONCAT (concat) +* SUBSTRING (substring) +* TRIM (trim) +* LOWER (lower) +* UPPER (upper) +* LENGTH (length) +* LOCATE (locate) +```kotlin +concat(path(Book::title), literal(":"), path(Book::imageUrl)) + +substring(path(Book::title), 4) + +trim(path(Book::title)) +trim('B').from(path(Book::title)) + +lower(path(Book::title)) + +upper(path(Book::title)) + +length(path(Book::title)) + +locate("Book", path(Book::title)) +``` ### Arithmetic functions Use the following functions to build arithmetic functions: -* ceiling -* abs +* ABS (abs) +* CEILING (ceiling) ```kotlin abs(path(Book::price)) + ceiling(path(Book::price)) ``` diff --git a/docs/ko/jpql-with-kotlin-jdsl/expressions.md b/docs/ko/jpql-with-kotlin-jdsl/expressions.md index e9b81e9e7..8726fef12 100644 --- a/docs/ko/jpql-with-kotlin-jdsl/expressions.md +++ b/docs/ko/jpql-with-kotlin-jdsl/expressions.md @@ -191,33 +191,46 @@ Kotlin JDSL은 JPA에서 제공하는 여러 함수들을 지원하기 위함 ### String functions -| Function | DSL function | -|-----------|--------------| -| CONCAT | support | -| SUBSTRING | support | -| TRIM | support | -| LOWER | support | -| UPPER | support | -| LENGTH | support | -| LOCATE | support | +* CONCAT (concat) +* SUBSTRING (substring) +* TRIM (trim) +* LOWER (lower) +* UPPER (upper) +* LENGTH (length) +* LOCATE (locate) + +```kotlin +concat(path(Book::title), literal(":"), path(Book::imageUrl)) + +substring(path(Book::title), 4) + +trim(path(Book::title)) +trim('B').from(path(Book::title)) + +lower(path(Book::title)) + +upper(path(Book::title)) + +length(path(Book::title)) + +locate("Book", path(Book::title)) +``` ### Arithmetic functions 산술 함수를 만들기 위해서는 다음 함수들을 사용할 수 있습니다. - -* ceiling -* abs +* ABS (abs) +* CEILING (ceiling) ```kotlin abs(path(Book::price)) + ceiling(path(Book::price)) ``` | Function | DSL function | |----------|--------------| -| ABS | not yet | -| CEILING | not yet | | EXP | not yet | | FLOOR | not yet | | LN | not yet | From 8622b29bf142aaf24041cdc17583f189d73ecbe7 Mon Sep 17 00:00:00 2001 From: sinkyoungdeok Date: Wed, 31 Jan 2024 00:33:13 +0900 Subject: [PATCH 035/169] docs: add floor function description --- docs/en/jpql-with-kotlin-jdsl/expressions.md | 3 +++ docs/ko/jpql-with-kotlin-jdsl/expressions.md | 3 +++ 2 files changed, 6 insertions(+) diff --git a/docs/en/jpql-with-kotlin-jdsl/expressions.md b/docs/en/jpql-with-kotlin-jdsl/expressions.md index a3f0f2995..af8620116 100644 --- a/docs/en/jpql-with-kotlin-jdsl/expressions.md +++ b/docs/en/jpql-with-kotlin-jdsl/expressions.md @@ -225,11 +225,14 @@ Use the following functions to build arithmetic functions: * ABS (abs) * CEILING (ceiling) +* FLOOR (floor) ```kotlin abs(path(Book::price)) ceiling(path(Book::price)) + +floor(path(Book::price)) ``` | Function | DSL function | diff --git a/docs/ko/jpql-with-kotlin-jdsl/expressions.md b/docs/ko/jpql-with-kotlin-jdsl/expressions.md index 8726fef12..ab828352f 100644 --- a/docs/ko/jpql-with-kotlin-jdsl/expressions.md +++ b/docs/ko/jpql-with-kotlin-jdsl/expressions.md @@ -222,11 +222,14 @@ locate("Book", path(Book::title)) * ABS (abs) * CEILING (ceiling) +* FLOOR (floor) ```kotlin abs(path(Book::price)) ceiling(path(Book::price)) + +floor(path(Book::price)) ``` | Function | DSL function | From 0a746b452bbcd30c9e41c5bbb9f6ef3ece8e56db Mon Sep 17 00:00:00 2001 From: sinkyoungdeok Date: Wed, 31 Jan 2024 00:33:30 +0900 Subject: [PATCH 036/169] feat: implement floor function expression --- .../com/linecorp/kotlinjdsl/dsl/jpql/Jpql.kt | 16 ++++++ .../dsl/jpql/expression/FloorDslTest.kt | 48 ++++++++++++++++ .../querymodel/jpql/expression/Expressions.kt | 9 +++ .../jpql/expression/impl/JpqlFloor.kt | 12 ++++ .../jpql/expression/ExpressionsTest.kt | 14 +++++ .../render/jpql/JpqlRenderContext.kt | 2 + .../serializer/impl/JpqlFloorSerializer.kt | 26 +++++++++ .../impl/JpqlFloorSerializerTest.kt | 55 +++++++++++++++++++ 8 files changed, 182 insertions(+) create mode 100644 dsl/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/expression/FloorDslTest.kt create mode 100644 query-model/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/expression/impl/JpqlFloor.kt create mode 100644 render/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlFloorSerializer.kt create mode 100644 render/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlFloorSerializerTest.kt 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 c6bd4b53e..f0fe0889e 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 @@ -568,6 +568,22 @@ open class Jpql : JpqlDsl { return Expressions.ceiling(value.toExpression()) } + /** + * Creates an expression that is enclosed in floor + */ + @SinceJdsl("3.4.0") + fun floor(expr: KProperty1): Expression { + return Expressions.floor(Paths.path(expr)) + } + + /** + * Creates an expression that is enclosed in floor + */ + @SinceJdsl("3.4.0") + fun floor(value: Expressionable): Expression { + return Expressions.floor(value.toExpression()) + } + /** * Creates an expression that represents the count of non-null values. * diff --git a/dsl/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/expression/FloorDslTest.kt b/dsl/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/expression/FloorDslTest.kt new file mode 100644 index 000000000..4205b5c8a --- /dev/null +++ b/dsl/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/expression/FloorDslTest.kt @@ -0,0 +1,48 @@ +package com.linecorp.kotlinjdsl.dsl.jpql.expression + +import com.linecorp.kotlinjdsl.dsl.jpql.entity.book.Book +import com.linecorp.kotlinjdsl.dsl.jpql.queryPart +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expression +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expressions +import com.linecorp.kotlinjdsl.querymodel.jpql.path.Paths +import org.assertj.core.api.WithAssertions +import org.junit.jupiter.api.Test +import java.math.BigDecimal + +class FloorDslTest : WithAssertions { + private val expression1 = Paths.path(Book::salePrice) + + @Test + fun `floor() with a property`() { + // when + val expression = queryPart { + floor(Book::price) + }.toExpression() + + val actual: Expression = expression // for type check + + // then + val expected = Expressions.floor( + value = Paths.path(Book::price), + ) + + assertThat(actual).isEqualTo(expected) + } + + @Test + fun `floor() with a expression`() { + // when + val expression = queryPart { + floor(expression1) + }.toExpression() + + val actual: Expression = expression // for type check + + // then + val expected = Expressions.floor( + value = expression1, + ) + + 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 fb06e5926..fe8a4487e 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 @@ -16,6 +16,7 @@ import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlDivide import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlEntityType import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlExpression import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlExpressionParentheses +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlFloor 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 @@ -204,6 +205,14 @@ object Expressions { return JpqlCeiling(value) } + /** + * Creates an expression that is enclosed in floor + */ + @SinceJdsl("3.4.0") + fun floor(value: Expression): Expression { + return JpqlFloor(value) + } + /** * Creates an expression that represents the times of values. * diff --git a/query-model/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/expression/impl/JpqlFloor.kt b/query-model/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/expression/impl/JpqlFloor.kt new file mode 100644 index 000000000..88364ccb8 --- /dev/null +++ b/query-model/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/expression/impl/JpqlFloor.kt @@ -0,0 +1,12 @@ +package com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl + +import com.linecorp.kotlinjdsl.Internal +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expression + +/** + * Expression that applies the floor function to [value]. + */ +@Internal +data class JpqlFloor internal constructor( + val value: Expression, +) : 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 9e1155a49..1c8402282 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 @@ -18,6 +18,7 @@ import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlDivide import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlEntityType import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlExpression import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlExpressionParentheses +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlFloor 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 @@ -915,4 +916,17 @@ class ExpressionsTest : WithAssertions { assertThat(actual).isEqualTo(expected) } + + @Test + fun floor() { + // when + val actual = Expressions.floor(doubleExpression1) + + // then + val expected = JpqlFloor( + doubleExpression1, + ) + + assertThat(actual).isEqualTo(expected) + } } 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 d17578ed3..4fd1c6960 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 @@ -39,6 +39,7 @@ import com.linecorp.kotlinjdsl.render.jpql.serializer.impl.JpqlEqualSerializer import com.linecorp.kotlinjdsl.render.jpql.serializer.impl.JpqlExistsSerializer import com.linecorp.kotlinjdsl.render.jpql.serializer.impl.JpqlExpressionParenthesesSerializer import com.linecorp.kotlinjdsl.render.jpql.serializer.impl.JpqlExpressionSerializer +import com.linecorp.kotlinjdsl.render.jpql.serializer.impl.JpqlFloorSerializer import com.linecorp.kotlinjdsl.render.jpql.serializer.impl.JpqlFunctionExpressionSerializer import com.linecorp.kotlinjdsl.render.jpql.serializer.impl.JpqlFunctionPredicateSerializer import com.linecorp.kotlinjdsl.render.jpql.serializer.impl.JpqlGreaterThanAllSerializer @@ -286,6 +287,7 @@ private class DefaultModule : JpqlRenderModule { JpqlExistsSerializer(), JpqlExpressionParenthesesSerializer(), JpqlExpressionSerializer(), + JpqlFloorSerializer(), JpqlFunctionExpressionSerializer(), JpqlFunctionPredicateSerializer(), JpqlGreaterThanAllSerializer(), diff --git a/render/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlFloorSerializer.kt b/render/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlFloorSerializer.kt new file mode 100644 index 000000000..04dd9157e --- /dev/null +++ b/render/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlFloorSerializer.kt @@ -0,0 +1,26 @@ +package com.linecorp.kotlinjdsl.render.jpql.serializer.impl + +import com.linecorp.kotlinjdsl.Internal +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlFloor +import com.linecorp.kotlinjdsl.render.RenderContext +import com.linecorp.kotlinjdsl.render.jpql.serializer.JpqlRenderSerializer +import com.linecorp.kotlinjdsl.render.jpql.serializer.JpqlSerializer +import com.linecorp.kotlinjdsl.render.jpql.writer.JpqlWriter +import kotlin.reflect.KClass + +@Internal +class JpqlFloorSerializer : JpqlSerializer> { + override fun handledType(): KClass> { + return JpqlFloor::class + } + + override fun serialize(part: JpqlFloor<*>, writer: JpqlWriter, context: RenderContext) { + val delegate = context.getValue(JpqlRenderSerializer) + + writer.write("FLOOR") + + writer.writeParentheses { + delegate.serialize(part.value, writer, context) + } + } +} diff --git a/render/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlFloorSerializerTest.kt b/render/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlFloorSerializerTest.kt new file mode 100644 index 000000000..528548a4a --- /dev/null +++ b/render/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlFloorSerializerTest.kt @@ -0,0 +1,55 @@ +package com.linecorp.kotlinjdsl.render.jpql.serializer.impl + +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expressions +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlFloor +import com.linecorp.kotlinjdsl.querymodel.jpql.path.Paths +import com.linecorp.kotlinjdsl.render.TestRenderContext +import com.linecorp.kotlinjdsl.render.jpql.entity.book.Book +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.WithAssertions +import org.junit.jupiter.api.Test + +@JpqlSerializerTest +class JpqlFloorSerializerTest : WithAssertions { + private val sut = JpqlFloorSerializer() + + @MockK + private lateinit var writer: JpqlWriter + + @MockK + private lateinit var serializer: JpqlRenderSerializer + + private val expression1 = Paths.path(Book::price) + + @Test + fun handledType() { + // when + val actual = sut.handledType() + + // then + assertThat(actual).isEqualTo(JpqlFloor::class) + } + + @Test + fun serialize() { + // given + val part = Expressions.floor( + value = expression1, + ) + val context = TestRenderContext(serializer) + + // when + sut.serialize(part as JpqlFloor<*>, writer, context) + + // then + verifySequence { + writer.write("FLOOR") + writer.writeParentheses(any()) + serializer.serialize(expression1, writer, context) + } + } +} From c4f3612690a0d178333256de0922a3659c25a931 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 30 Jan 2024 16:34:47 +0000 Subject: [PATCH 037/169] chore(deps): update dependency io.vertx:vertx-jdbc-client to v4.5.2 --- libs.example.versions.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs.example.versions.toml b/libs.example.versions.toml index b621111e1..b84f250b5 100644 --- a/libs.example.versions.toml +++ b/libs.example.versions.toml @@ -39,7 +39,7 @@ eclipselink2 = { module = "org.eclipse.persistence:org.eclipse.persistence.jpa", eclipselink4 = { module = "org.eclipse.persistence:org.eclipse.persistence.jpa", version = "4.0.2" } # vertx -vertx-jdbc-client = { module = "io.vertx:vertx-jdbc-client", version = "4.5.1" } +vertx-jdbc-client = { module = "io.vertx:vertx-jdbc-client", version = "4.5.2" } agroal-pool = { module = "io.agroal:agroal-pool", version = "2.2" } h2 = { module = "com.h2database:h2", version = "2.2.224" } From 20ef0f5b54df63d1ad1bed0c57f2d6fc357c379e Mon Sep 17 00:00:00 2001 From: Jake Son Date: Mon, 29 Jan 2024 08:14:46 +0900 Subject: [PATCH 038/169] feat: implement sqrt function expression --- .../com/linecorp/kotlinjdsl/dsl/jpql/Jpql.kt | 16 +++++++ .../dsl/jpql/expression/SqrtDslTest.kt | 47 +++++++++++++++++++ .../querymodel/jpql/expression/Expressions.kt | 9 ++++ .../jpql/expression/impl/JpqlSqrt.kt | 12 +++++ .../jpql/expression/ExpressionsTest.kt | 14 ++++++ 5 files changed, 98 insertions(+) create mode 100644 dsl/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/expression/SqrtDslTest.kt create mode 100644 query-model/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/expression/impl/JpqlSqrt.kt 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 c6bd4b53e..82d3a3405 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 @@ -336,6 +336,22 @@ open class Jpql : JpqlDsl { return Paths.treat(this.toPath(), type) } + /** + * Creates an expression that represents the square root of value. + */ + @SinceJdsl("3.4.0") + fun sqrt(expr: KProperty1): Expression { + return Expressions.sqrt(Paths.path(expr)) + } + + /** + * Creates an expression that represents the square root of value. + */ + @SinceJdsl("3.4.0") + fun sqrt(value: Expressionable): Expression { + return Expressions.sqrt(value.toExpression()) + } + /** * Creates an expression that represents the plus of values. * The values are each enclosed in parentheses. diff --git a/dsl/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/expression/SqrtDslTest.kt b/dsl/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/expression/SqrtDslTest.kt new file mode 100644 index 000000000..f6463f70a --- /dev/null +++ b/dsl/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/expression/SqrtDslTest.kt @@ -0,0 +1,47 @@ +package com.linecorp.kotlinjdsl.dsl.jpql.expression + +import com.linecorp.kotlinjdsl.dsl.jpql.entity.book.Book +import com.linecorp.kotlinjdsl.dsl.jpql.queryPart +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expression +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expressions +import com.linecorp.kotlinjdsl.querymodel.jpql.path.Paths +import org.assertj.core.api.WithAssertions +import org.junit.jupiter.api.Test + +class SqrtDslTest : WithAssertions { + private val expression1 = Paths.path(Book::salePrice) + + @Test + fun `sqrt() with a property`() { + // when + val expression = queryPart { + sqrt(Book::price) + }.toExpression() + + val actual: Expression = expression // for type check + + // then + val expected = Expressions.sqrt( + value = Paths.path(Book::price), + ) + + assertThat(actual).isEqualTo(expected) + } + + @Test + fun `sqrt() with a expression`() { + // when + val expression = queryPart { + sqrt(expression1) + }.toExpression() + + val actual: Expression = expression // for type check + + // then + val expected = Expressions.sqrt( + value = expression1, + ) + + 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 fb06e5926..1313701f6 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 @@ -30,6 +30,7 @@ import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlNullIf import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlParam import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlPathType import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlPlus +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlSqrt import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlSubquery import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlSubstring import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlSum @@ -176,6 +177,14 @@ object Expressions { return JpqlAbs(value) } + /** + * Creates an expression that represents the square root of the value. + */ + @SinceJdsl("3.4.0") + fun sqrt(value: Expression): Expression { + return JpqlSqrt(value) + } + /** * Creates an expression that represents the plus of values. * diff --git a/query-model/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/expression/impl/JpqlSqrt.kt b/query-model/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/expression/impl/JpqlSqrt.kt new file mode 100644 index 000000000..4beb72c3d --- /dev/null +++ b/query-model/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/expression/impl/JpqlSqrt.kt @@ -0,0 +1,12 @@ +package com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl + +import com.linecorp.kotlinjdsl.Internal +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expression + +/** + * Expression that calculates the square root of [value]. + */ +@Internal +data class JpqlSqrt internal constructor( + val value: Expression, +) : 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 9e1155a49..255c8e9ef 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 @@ -32,6 +32,7 @@ import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlNullIf import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlParam import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlPathType import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlPlus +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlSqrt import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlSubquery import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlSubstring import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlSum @@ -291,6 +292,19 @@ class ExpressionsTest : WithAssertions { assertThat(actual).isEqualTo(expected) } + @Test + fun sqrt() { + // when + val actual = Expressions.sqrt(intExpression1) + + // then + val expected = JpqlSqrt( + intExpression1, + ) + + assertThat(actual).isEqualTo(expected) + } + @Test fun plus() { // when From b94a1100743c57315256db607aabadfe93e2cde1 Mon Sep 17 00:00:00 2001 From: Jake Son Date: Mon, 29 Jan 2024 08:18:34 +0900 Subject: [PATCH 039/169] feat: implement jpql sqrt serializer --- .../render/jpql/JpqlRenderContext.kt | 2 + .../serializer/impl/JpqlSqrtSerializer.kt | 26 +++++++++ .../serializer/impl/JpqlSqrtSerializerTest.kt | 55 +++++++++++++++++++ 3 files changed, 83 insertions(+) create mode 100644 render/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlSqrtSerializer.kt create mode 100644 render/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlSqrtSerializerTest.kt 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 d17578ed3..a26efdcee 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 @@ -97,6 +97,7 @@ import com.linecorp.kotlinjdsl.render.jpql.serializer.impl.JpqlPlusSerializer import com.linecorp.kotlinjdsl.render.jpql.serializer.impl.JpqlPredicateParenthesesSerializer import com.linecorp.kotlinjdsl.render.jpql.serializer.impl.JpqlSelectQuerySerializer import com.linecorp.kotlinjdsl.render.jpql.serializer.impl.JpqlSortSerializer +import com.linecorp.kotlinjdsl.render.jpql.serializer.impl.JpqlSqrtSerializer import com.linecorp.kotlinjdsl.render.jpql.serializer.impl.JpqlSubquerySerializer import com.linecorp.kotlinjdsl.render.jpql.serializer.impl.JpqlSubstringSerializer import com.linecorp.kotlinjdsl.render.jpql.serializer.impl.JpqlSumSerializer @@ -344,6 +345,7 @@ private class DefaultModule : JpqlRenderModule { JpqlPredicateParenthesesSerializer(), JpqlSelectQuerySerializer(), JpqlSortSerializer(), + JpqlSqrtSerializer(), JpqlSubquerySerializer(), JpqlSubstringSerializer(), JpqlSumSerializer(), diff --git a/render/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlSqrtSerializer.kt b/render/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlSqrtSerializer.kt new file mode 100644 index 000000000..ffa9c9949 --- /dev/null +++ b/render/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlSqrtSerializer.kt @@ -0,0 +1,26 @@ +package com.linecorp.kotlinjdsl.render.jpql.serializer.impl + +import com.linecorp.kotlinjdsl.Internal +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlSqrt +import com.linecorp.kotlinjdsl.render.RenderContext +import com.linecorp.kotlinjdsl.render.jpql.serializer.JpqlRenderSerializer +import com.linecorp.kotlinjdsl.render.jpql.serializer.JpqlSerializer +import com.linecorp.kotlinjdsl.render.jpql.writer.JpqlWriter +import kotlin.reflect.KClass + +@Internal +class JpqlSqrtSerializer : JpqlSerializer> { + override fun handledType(): KClass> { + return JpqlSqrt::class + } + + override fun serialize(part: JpqlSqrt<*>, writer: JpqlWriter, context: RenderContext) { + val delegate = context.getValue(JpqlRenderSerializer) + + writer.write("SQRT") + + writer.writeParentheses { + delegate.serialize(part.value, writer, context) + } + } +} diff --git a/render/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlSqrtSerializerTest.kt b/render/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlSqrtSerializerTest.kt new file mode 100644 index 000000000..8c4e5769a --- /dev/null +++ b/render/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlSqrtSerializerTest.kt @@ -0,0 +1,55 @@ +package com.linecorp.kotlinjdsl.render.jpql.serializer.impl + +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expressions +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlSqrt +import com.linecorp.kotlinjdsl.querymodel.jpql.path.Paths +import com.linecorp.kotlinjdsl.render.TestRenderContext +import com.linecorp.kotlinjdsl.render.jpql.entity.book.Book +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.WithAssertions +import org.junit.jupiter.api.Test + +@JpqlSerializerTest +class JpqlSqrtSerializerTest : WithAssertions { + private val sut = JpqlSqrtSerializer() + + @MockK + private lateinit var writer: JpqlWriter + + @MockK + private lateinit var serializer: JpqlRenderSerializer + + private val expression1 = Paths.path(Book::price) + + @Test + fun handledType() { + // when + val actual = sut.handledType() + + // then + assertThat(actual).isEqualTo(JpqlSqrt::class) + } + + @Test + fun serialize() { + // given + val part = Expressions.sqrt( + value = expression1, + ) + val context = TestRenderContext(serializer) + + // when + sut.serialize(part as JpqlSqrt<*>, writer, context) + + // then + verifySequence { + writer.write("SQRT") + writer.writeParentheses(any()) + serializer.serialize(expression1, writer, context) + } + } +} From 1e4473462c679f1ebc64b755086b34b60feda83e Mon Sep 17 00:00:00 2001 From: Jake Son Date: Mon, 29 Jan 2024 08:22:11 +0900 Subject: [PATCH 040/169] docs: add sqrt function description --- docs/en/jpql-with-kotlin-jdsl/expressions.md | 4 +++- docs/ko/jpql-with-kotlin-jdsl/expressions.md | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/docs/en/jpql-with-kotlin-jdsl/expressions.md b/docs/en/jpql-with-kotlin-jdsl/expressions.md index a3f0f2995..2c2528890 100644 --- a/docs/en/jpql-with-kotlin-jdsl/expressions.md +++ b/docs/en/jpql-with-kotlin-jdsl/expressions.md @@ -225,11 +225,14 @@ Use the following functions to build arithmetic functions: * ABS (abs) * CEILING (ceiling) +* SQRT (sqrt) ```kotlin abs(path(Book::price)) ceiling(path(Book::price)) + +sqrt(path(Book::price)) ``` | Function | DSL function | @@ -241,7 +244,6 @@ ceiling(path(Book::price)) | POWER | not yet | | ROUND | not yet | | SIGN | not yet | -| SQRT | not yet | | SIZE | not yet | | INDEX | not yet | diff --git a/docs/ko/jpql-with-kotlin-jdsl/expressions.md b/docs/ko/jpql-with-kotlin-jdsl/expressions.md index 8726fef12..ffbdfb878 100644 --- a/docs/ko/jpql-with-kotlin-jdsl/expressions.md +++ b/docs/ko/jpql-with-kotlin-jdsl/expressions.md @@ -52,7 +52,6 @@ avg(path(FullTimeEmployee::annualSalary)(EmployeeSalary::value)).`as`(BigDecimal * \- (minus) * \* (times) * / (div) -* ceiling ```kotlin path(Book::price).plus(path(Book::salePrice)) @@ -222,11 +221,14 @@ locate("Book", path(Book::title)) * ABS (abs) * CEILING (ceiling) +* SQRT (sqrt) ```kotlin abs(path(Book::price)) ceiling(path(Book::price)) + +sqrt(path(Book::price)) ``` | Function | DSL function | @@ -238,7 +240,6 @@ ceiling(path(Book::price)) | POWER | not yet | | ROUND | not yet | | SIGN | not yet | -| SQRT | not yet | | SIZE | not yet | | INDEX | not yet | From 968d8380901c8e273dade3fe56fba9a27ebead4a Mon Sep 17 00:00:00 2001 From: Jake Son Date: Wed, 31 Jan 2024 06:31:38 +0900 Subject: [PATCH 041/169] refactor: change order of methods --- .../com/linecorp/kotlinjdsl/dsl/jpql/Jpql.kt | 36 +++++----- .../querymodel/jpql/expression/Expressions.kt | 48 +++++++------- .../jpql/expression/ExpressionsTest.kt | 66 +++++++++---------- 3 files changed, 75 insertions(+), 75 deletions(-) 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 82d3a3405..bd66a02eb 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 @@ -336,22 +336,6 @@ open class Jpql : JpqlDsl { return Paths.treat(this.toPath(), type) } - /** - * Creates an expression that represents the square root of value. - */ - @SinceJdsl("3.4.0") - fun sqrt(expr: KProperty1): Expression { - return Expressions.sqrt(Paths.path(expr)) - } - - /** - * Creates an expression that represents the square root of value. - */ - @SinceJdsl("3.4.0") - fun sqrt(value: Expressionable): Expression { - return Expressions.sqrt(value.toExpression()) - } - /** * Creates an expression that represents the plus of values. * The values are each enclosed in parentheses. @@ -569,7 +553,7 @@ open class Jpql : JpqlDsl { } /** - * Creates an expression that is enclosed in ceiling + * Creates an expression that is enclosed in ceiling. */ @SinceJdsl("3.4.0") fun ceiling(expr: KProperty1): Expression { @@ -577,13 +561,29 @@ open class Jpql : JpqlDsl { } /** - * Creates an expression that is enclosed in ceiling + * Creates an expression that is enclosed in ceiling. */ @SinceJdsl("3.4.0") fun ceiling(value: Expressionable): Expression { return Expressions.ceiling(value.toExpression()) } + /** + * Creates an expression that represents the square root of value. + */ + @SinceJdsl("3.4.0") + fun sqrt(expr: KProperty1): Expression { + return Expressions.sqrt(Paths.path(expr)) + } + + /** + * Creates an expression that represents the square root of value. + */ + @SinceJdsl("3.4.0") + fun sqrt(value: Expressionable): Expression { + return Expressions.sqrt(value.toExpression()) + } + /** * Creates an expression that represents the count of non-null values. * 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 1313701f6..8dea29f7c 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 @@ -169,22 +169,6 @@ object Expressions { return JpqlParam(name, value) } - /** - * Creates an expression that represents the absolute value. - */ - @SinceJdsl("3.4.0") - fun abs(value: Expression): Expression { - return JpqlAbs(value) - } - - /** - * Creates an expression that represents the square root of the value. - */ - @SinceJdsl("3.4.0") - fun sqrt(value: Expression): Expression { - return JpqlSqrt(value) - } - /** * Creates an expression that represents the plus of values. * @@ -205,14 +189,6 @@ object Expressions { return JpqlMinus(value1, value2) } - /** - * Creates an expression that is enclosed in ceiling - */ - @SinceJdsl("3.4.0") - fun ceiling(value: Expression): Expression { - return JpqlCeiling(value) - } - /** * Creates an expression that represents the times of values. * @@ -233,6 +209,30 @@ object Expressions { return JpqlDivide(value1, value2) } + /** + * Creates an expression that represents the absolute value. + */ + @SinceJdsl("3.4.0") + fun abs(value: Expression): Expression { + return JpqlAbs(value) + } + + /** + * Creates an expression that is enclosed in ceiling. + */ + @SinceJdsl("3.4.0") + fun ceiling(value: Expression): Expression { + return JpqlCeiling(value) + } + + /** + * Creates an expression that represents the square root of the value. + */ + @SinceJdsl("3.4.0") + fun sqrt(value: Expression): Expression { + return JpqlSqrt(value) + } + /** * Creates an expression that represents the count of non-null values. * 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 255c8e9ef..ae4abfdda 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 @@ -280,38 +280,40 @@ class ExpressionsTest : WithAssertions { } @Test - fun abs() { + fun plus() { // when - val actual = Expressions.abs(intExpression1) + val actual = Expressions.plus(intExpression1, intExpression2) // then - val expected = JpqlAbs( + val expected = JpqlPlus( intExpression1, + intExpression2, ) assertThat(actual).isEqualTo(expected) } @Test - fun sqrt() { + fun minus() { // when - val actual = Expressions.sqrt(intExpression1) + val actual = Expressions.minus(intExpression1, intExpression2) // then - val expected = JpqlSqrt( + val expected = JpqlMinus( intExpression1, + intExpression2, ) assertThat(actual).isEqualTo(expected) } @Test - fun plus() { + fun times() { // when - val actual = Expressions.plus(intExpression1, intExpression2) + val actual = Expressions.times(intExpression1, intExpression2) // then - val expected = JpqlPlus( + val expected = JpqlTimes( intExpression1, intExpression2, ) @@ -320,12 +322,12 @@ class ExpressionsTest : WithAssertions { } @Test - fun minus() { + fun div() { // when - val actual = Expressions.minus(intExpression1, intExpression2) + val actual = Expressions.div(intExpression1, intExpression2) // then - val expected = JpqlMinus( + val expected = JpqlDivide( intExpression1, intExpression2, ) @@ -334,28 +336,39 @@ class ExpressionsTest : WithAssertions { } @Test - fun times() { + fun abs() { // when - val actual = Expressions.times(intExpression1, intExpression2) + val actual = Expressions.abs(intExpression1) // then - val expected = JpqlTimes( + val expected = JpqlAbs( intExpression1, - intExpression2, ) assertThat(actual).isEqualTo(expected) } @Test - fun div() { + fun ceiling() { // when - val actual = Expressions.div(intExpression1, intExpression2) + val actual = Expressions.ceiling(doubleExpression1) // then - val expected = JpqlDivide( + val expected = JpqlCeiling( + doubleExpression1, + ) + + assertThat(actual).isEqualTo(expected) + } + + @Test + fun sqrt() { + // when + val actual = Expressions.sqrt(intExpression1) + + // then + val expected = JpqlSqrt( intExpression1, - intExpression2, ) assertThat(actual).isEqualTo(expected) @@ -916,17 +929,4 @@ class ExpressionsTest : WithAssertions { assertThat(actual).isEqualTo(expected) } - - @Test - fun ceiling() { - // when - val actual = Expressions.ceiling(doubleExpression1) - - // then - val expected = JpqlCeiling( - doubleExpression1, - ) - - assertThat(actual).isEqualTo(expected) - } } From 050b988f17166d04528bb087172b266224a3ecc4 Mon Sep 17 00:00:00 2001 From: JeJune Lee <81547780+LeeJejune@users.noreply.github.com> Date: Wed, 31 Jan 2024 09:28:36 +0900 Subject: [PATCH 042/169] fix: round function return first argument and method order --- .../com/linecorp/kotlinjdsl/dsl/jpql/Jpql.kt | 26 +++++++------------ .../jpql/expression/impl/JpqlRound.kt | 2 +- 2 files changed, 11 insertions(+), 17 deletions(-) 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 fddc908b9..2b454afd6 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 @@ -366,22 +366,6 @@ open class Jpql : JpqlDsl { ) } - /** - * Creates an expression that represents the rounding of the specified property's value to a specified scale. - */ - @SinceJdsl("3.4.0") - fun round(expr: KProperty1, scale: Expression): Expression { - return Expressions.round(Paths.path(expr), scale.toExpression()) - } - - /** - * Creates an expression that represents the rounding of the specified property's value to a specified scale. - */ - @SinceJdsl("3.4.0") - fun round(value: Expressionable, scale: Expressionable): Expression { - return Expressions.round(value.toExpression(), scale.toExpression()) - } - /** * Creates an expression that represents the plus of values. * @@ -552,6 +536,16 @@ open class Jpql : JpqlDsl { return Expressions.div(this.toExpression(), value.toExpression()) } + @SinceJdsl("3.4.0") + fun round(expr: KProperty1, scale: Expression): Expression { + return Expressions.round(Paths.path(expr), scale.toExpression()) + } + + @SinceJdsl("3.4.0") + fun round(value: Expressionable, scale: Expressionable): Expression { + return Expressions.round(value.toExpression(), scale.toExpression()) + } + /** * Creates an expression that represents the count of non-null values. * diff --git a/query-model/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/expression/impl/JpqlRound.kt b/query-model/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/expression/impl/JpqlRound.kt index 3af3c5160..69c2a8a4b 100644 --- a/query-model/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/expression/impl/JpqlRound.kt +++ b/query-model/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/expression/impl/JpqlRound.kt @@ -10,5 +10,5 @@ import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expression data class JpqlRound internal constructor( val value: Expression, val scale: Expression, -) : Expression { +) : Expression { } From 602b0e4909d382ae5870fbba91415b10b684cb84 Mon Sep 17 00:00:00 2001 From: JeJune Lee <81547780+LeeJejune@users.noreply.github.com> Date: Wed, 31 Jan 2024 09:29:14 +0900 Subject: [PATCH 043/169] fix: method comment --- .../main/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/Jpql.kt | 6 ++++++ 1 file changed, 6 insertions(+) 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 2b454afd6..1c9063f2e 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 @@ -536,11 +536,17 @@ open class Jpql : JpqlDsl { return Expressions.div(this.toExpression(), value.toExpression()) } + /** + * Creates an expression that represents the rounding of the value to a specified scale. + */ @SinceJdsl("3.4.0") fun round(expr: KProperty1, scale: Expression): Expression { return Expressions.round(Paths.path(expr), scale.toExpression()) } + /** + * Creates an expression that represents the rounding of the value to a specified scale. + */ @SinceJdsl("3.4.0") fun round(value: Expressionable, scale: Expressionable): Expression { return Expressions.round(value.toExpression(), scale.toExpression()) From 96e7e6ec9d36b9bef2ab724d9e885048791d4021 Mon Sep 17 00:00:00 2001 From: JeJune Lee <81547780+LeeJejune@users.noreply.github.com> Date: Wed, 31 Jan 2024 09:29:50 +0900 Subject: [PATCH 044/169] fix: round expression method --- .../kotlinjdsl/querymodel/jpql/expression/Expressions.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 bc417a9a0..5323aa508 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 @@ -248,10 +248,10 @@ object Expressions { } /** - * Creates an expression that represents the rounding of the specified property's value to a specified scale. + * Creates an expression that represents the rounding of the specified value to a specified scale. */ @SinceJdsl("3.4.0") - fun round(value: Expression, scale: Expression): Expression { + fun round(value: Expression, scale: Expression): Expression { return JpqlRound(value, scale) } From 74f758a15674454994f9c5158acb34fc434747ce Mon Sep 17 00:00:00 2001 From: JeJune Lee <81547780+LeeJejune@users.noreply.github.com> Date: Wed, 31 Jan 2024 09:30:09 +0900 Subject: [PATCH 045/169] fix: roundDsl test and Expression Test --- .../dsl/jpql/expression/RoundDslTest.kt | 49 +++++++++++++++++-- .../jpql/expression/ExpressionsTest.kt | 42 ++++++++++------ 2 files changed, 72 insertions(+), 19 deletions(-) diff --git a/dsl/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/expression/RoundDslTest.kt b/dsl/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/expression/RoundDslTest.kt index 54664611b..7cb81590f 100644 --- a/dsl/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/expression/RoundDslTest.kt +++ b/dsl/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/expression/RoundDslTest.kt @@ -7,20 +7,23 @@ import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expressions import com.linecorp.kotlinjdsl.querymodel.jpql.path.Paths import org.assertj.core.api.WithAssertions import org.junit.jupiter.api.Test +import java.math.BigDecimal class RoundDslTest : WithAssertions { private val expression1 = Paths.path(Book::salePrice) private val intExpression1: Expression = Expressions.value(3) + private val doubleExpression1: Expression = Expressions.value(3.0) private val int1 = 3 + private val double1 = 3.0 @Test - fun `round() with a expression`() { + fun `round() with a BigDecimalExpression`() { // when val expression = queryPart { round(expression1, intExpression1) }.toExpression() - val actual: Expression = expression // for type check + val actual: Expression = expression // for type check // then val expected = Expressions.round( @@ -32,13 +35,13 @@ class RoundDslTest : WithAssertions { } @Test - fun `round() with a property`() { + fun `round() with a BigDecimalProperty`() { // when val expression = queryPart { - round(Book::price, intExpression1) + round(Book::price, Expressions.value(int1)) }.toExpression() - val actual: Expression = expression // for type check + val actual: Expression = expression // for type check // then val expected = Expressions.round( @@ -48,4 +51,40 @@ class RoundDslTest : WithAssertions { assertThat(actual).isEqualTo(expected) } + + @Test + fun `round() with a DoubleExpression`() { + // when + val expression = queryPart { + round(doubleExpression1, intExpression1) + }.toExpression() + + val actual: Expression = expression // for type check + + // then + val expected = Expressions.round( + value = doubleExpression1, + scale = intExpression1, + ) + + assertThat(actual).isEqualTo(expected) + } + + @Test + fun `round() with a DoubleProperty`() { + // when + val expression = queryPart { + round(Expressions.value(double1), Expressions.value(int1)) + }.toExpression() + + val actual: Expression = expression // for type check + + // then + val expected = Expressions.round( + value = Expressions.value(double1), + scale = Expressions.value(int1), + ) + + assertThat(actual).isEqualTo(expected) + } } 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 6bf579a5d..89398ce67 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 @@ -333,6 +333,34 @@ class ExpressionsTest : WithAssertions { assertThat(actual).isEqualTo(expected) } + @Test + fun `round() with doubleExpression`() { + // when + val actual = Expressions.round(doubleExpression1, intExpression1) + + // then + val expected = JpqlRound( + doubleExpression1, + intExpression1 + ) + + assertThat(actual).isEqualTo(expected) + } + + @Test + fun `round() with BigDecimalExpression`() { + // when + val actual = Expressions.round(bigDecimalExpression1, intExpression1) + + // then + val expected = JpqlRound( + bigDecimalExpression1, + intExpression1 + ) + + assertThat(actual).isEqualTo(expected) + } + @ParameterizedTest @ValueSource(booleans = [true, false]) fun count(distinct: Boolean) { @@ -393,20 +421,6 @@ class ExpressionsTest : WithAssertions { assertThat(actual).isEqualTo(expected) } - @Test - fun round() { - // when - val actual = Expressions.round(doubleExpression1, intExpression1) - - // then - val expected = JpqlRound( - doubleExpression1, - intExpression1 - ) - - assertThat(actual).isEqualTo(expected) - } - @ParameterizedTest @ValueSource(booleans = [true, false]) fun `sum() with an int expression`(distinct: Boolean) { From bc38ac8d53b44c34345d18a86c35e3624c30f9ca Mon Sep 17 00:00:00 2001 From: "jonghyon.s" Date: Wed, 31 Jan 2024 10:14:26 +0900 Subject: [PATCH 046/169] style: format code style --- docs/en/jpql-with-kotlin-jdsl/expressions.md | 8 +- docs/ko/jpql-with-kotlin-jdsl/expressions.md | 8 +- .../com/linecorp/kotlinjdsl/dsl/jpql/Jpql.kt | 18 +++- .../dsl/jpql/expression/RoundDslTest.kt | 83 ++++++++----------- .../querymodel/jpql/expression/Expressions.kt | 2 +- .../jpql/expression/impl/JpqlRound.kt | 5 +- .../jpql/expression/ExpressionsTest.kt | 18 +--- .../serializer/impl/JpqlRoundSerializer.kt | 6 +- .../impl/JpqlRoundSerializerTest.kt | 6 +- 9 files changed, 70 insertions(+), 84 deletions(-) diff --git a/docs/en/jpql-with-kotlin-jdsl/expressions.md b/docs/en/jpql-with-kotlin-jdsl/expressions.md index 5f39e1738..cfe6bfa58 100644 --- a/docs/en/jpql-with-kotlin-jdsl/expressions.md +++ b/docs/en/jpql-with-kotlin-jdsl/expressions.md @@ -220,17 +220,13 @@ locate("Book", path(Book::title)) ``` ### Arithmetic functions -* round - -```kotlin -round(path(Book::price), Expressions.value(Int::class)) -``` Use the following functions to build arithmetic functions: * ABS (abs) * CEILING (ceiling) * SQRT (sqrt) +* ROUND (round) ```kotlin abs(path(Book::price)) @@ -238,6 +234,8 @@ abs(path(Book::price)) ceiling(path(Book::price)) sqrt(path(Book::price)) + +round(path(Book::price), 2) ``` | Function | DSL function | diff --git a/docs/ko/jpql-with-kotlin-jdsl/expressions.md b/docs/ko/jpql-with-kotlin-jdsl/expressions.md index c50bb34a7..e5dbfa6f4 100644 --- a/docs/ko/jpql-with-kotlin-jdsl/expressions.md +++ b/docs/ko/jpql-with-kotlin-jdsl/expressions.md @@ -216,17 +216,13 @@ locate("Book", path(Book::title)) ``` ### Arithmetic functions -* round - -```kotlin -round(path(Book::price), Expressions.value(Int::class)) -``` 산술 함수를 만들기 위해서는 다음 함수들을 사용할 수 있습니다. * ABS (abs) * CEILING (ceiling) * SQRT (sqrt) +* ROUND (round) ```kotlin abs(path(Book::price)) @@ -234,6 +230,8 @@ abs(path(Book::price)) ceiling(path(Book::price)) sqrt(path(Book::price)) + +round(path(Book::price), 2) ``` | Function | DSL function | 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 422e8f4e8..e4dcf3e2d 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 @@ -583,7 +583,23 @@ open class Jpql : JpqlDsl { fun sqrt(value: Expressionable): Expression { return Expressions.sqrt(value.toExpression()) } - + + /** + * Creates an expression that represents the rounding of the value to a specified scale. + */ + @SinceJdsl("3.4.0") + fun round(expr: KProperty1, scale: Int): Expression { + return Expressions.round(Paths.path(expr), Expressions.value(scale)) + } + + /** + * Creates an expression that represents the rounding of the value to a specified scale. + */ + @SinceJdsl("3.4.0") + fun round(value: Expressionable, scale: Int): Expression { + return Expressions.round(value.toExpression(), Expressions.value(scale)) + } + /** * Creates an expression that represents the rounding of the value to a specified scale. */ diff --git a/dsl/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/expression/RoundDslTest.kt b/dsl/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/expression/RoundDslTest.kt index 7cb81590f..4bc58a4fe 100644 --- a/dsl/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/expression/RoundDslTest.kt +++ b/dsl/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/expression/RoundDslTest.kt @@ -10,81 +10,66 @@ import org.junit.jupiter.api.Test import java.math.BigDecimal class RoundDslTest : WithAssertions { - private val expression1 = Paths.path(Book::salePrice) - private val intExpression1: Expression = Expressions.value(3) - private val doubleExpression1: Expression = Expressions.value(3.0) - private val int1 = 3 - private val double1 = 3.0 + private val bigDecimalExpression1 = Paths.path(Book::price) + private val intExpression1 = Expressions.value(2) + + private val int1 = 2 @Test - fun `round() with a BigDecimalExpression`() { + fun `round() with a property`() { // when - val expression = queryPart { - round(expression1, intExpression1) + val expression1 = queryPart { + round(Book::price, int1) }.toExpression() - val actual: Expression = expression // for type check - - // then - val expected = Expressions.round( - value = expression1, - scale = intExpression1, - ) - - assertThat(actual).isEqualTo(expected) - } - - @Test - fun `round() with a BigDecimalProperty`() { - // when - val expression = queryPart { - round(Book::price, Expressions.value(int1)) + val expression2 = queryPart { + round(Book::price, intExpression1) }.toExpression() - val actual: Expression = expression // for type check + val actual1: Expression = expression1 // for type check + val actual2: Expression = expression2 // for type check // then - val expected = Expressions.round( + val expected1 = Expressions.round( value = Paths.path(Book::price), scale = Expressions.value(int1), ) - assertThat(actual).isEqualTo(expected) - } - - @Test - fun `round() with a DoubleExpression`() { - // when - val expression = queryPart { - round(doubleExpression1, intExpression1) - }.toExpression() - - val actual: Expression = expression // for type check - - // then - val expected = Expressions.round( - value = doubleExpression1, + val expected2 = Expressions.round( + value = Paths.path(Book::price), scale = intExpression1, ) - assertThat(actual).isEqualTo(expected) + assertThat(actual1).isEqualTo(expected1) + assertThat(actual2).isEqualTo(expected2) } @Test - fun `round() with a DoubleProperty`() { + fun `round() with a expression`() { // when - val expression = queryPart { - round(Expressions.value(double1), Expressions.value(int1)) + val expression1 = queryPart { + round(bigDecimalExpression1, int1) + }.toExpression() + + val expression2 = queryPart { + round(bigDecimalExpression1, intExpression1) }.toExpression() - val actual: Expression = expression // for type check + val actual1: Expression = expression1 // for type check + val actual2: Expression = expression2 // for type check // then - val expected = Expressions.round( - value = Expressions.value(double1), + val expected1 = Expressions.round( + value = bigDecimalExpression1, scale = Expressions.value(int1), ) - assertThat(actual).isEqualTo(expected) + val expected2 = Expressions.round( + value = bigDecimalExpression1, + scale = intExpression1, + ) + + assertThat(actual1).isEqualTo(expected1) + assertThat(actual2).isEqualTo(expected2) } } 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 34abe4db4..4b3df31bb 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 @@ -30,6 +30,7 @@ import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlNullIf import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlParam import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlPathType import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlPlus +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlRound import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlSqrt import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlSubquery import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlSubstring @@ -41,7 +42,6 @@ import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlTrimLeading import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlTrimTrailing import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlUpper import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlValue -import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlRound import com.linecorp.kotlinjdsl.querymodel.jpql.path.Path import com.linecorp.kotlinjdsl.querymodel.jpql.predicate.Predicate import com.linecorp.kotlinjdsl.querymodel.jpql.select.SelectQuery diff --git a/query-model/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/expression/impl/JpqlRound.kt b/query-model/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/expression/impl/JpqlRound.kt index 69c2a8a4b..3f2624a5f 100644 --- a/query-model/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/expression/impl/JpqlRound.kt +++ b/query-model/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/expression/impl/JpqlRound.kt @@ -7,8 +7,7 @@ import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expression * Expression that calculates the rounding of a numeric [value] to a specified [scale]. */ @Internal -data class JpqlRound internal constructor( +data class JpqlRound internal constructor( val value: Expression, val scale: Expression, -) : Expression { -} +) : 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 9d99530fb..5d26774bb 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 @@ -376,28 +376,14 @@ class ExpressionsTest : WithAssertions { } @Test - fun `round() with BigDecimalExpression`() { + fun round() { // when val actual = Expressions.round(bigDecimalExpression1, intExpression1) // then val expected = JpqlRound( bigDecimalExpression1, - intExpression1 - ) - - assertThat(actual).isEqualTo(expected) - } - - @Test - fun `round() with doubleExpression`() { - // when - val actual = Expressions.round(doubleExpression1, intExpression1) - - // then - val expected = JpqlRound( - doubleExpression1, - intExpression1 + intExpression1, ) assertThat(actual).isEqualTo(expected) diff --git a/render/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlRoundSerializer.kt b/render/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlRoundSerializer.kt index cba82561d..e9519dc6d 100644 --- a/render/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlRoundSerializer.kt +++ b/render/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlRoundSerializer.kt @@ -9,7 +9,7 @@ import com.linecorp.kotlinjdsl.render.jpql.writer.JpqlWriter import kotlin.reflect.KClass @Internal -class JpqlRoundSerializer : JpqlSerializer>{ +class JpqlRoundSerializer : JpqlSerializer> { override fun handledType(): KClass> { return JpqlRound::class } @@ -22,7 +22,9 @@ class JpqlRoundSerializer : JpqlSerializer>{ writer.writeParentheses { delegate.serialize(part.value, writer, context) - writer.write(", ") + writer.write(",") + writer.write(" ") + delegate.serialize(part.scale, writer, context) } } diff --git a/render/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlRoundSerializerTest.kt b/render/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlRoundSerializerTest.kt index 766641b7e..a63104776 100644 --- a/render/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlRoundSerializerTest.kt +++ b/render/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlRoundSerializerTest.kt @@ -34,12 +34,13 @@ class JpqlRoundSerializerTest { // then assertThat(actual).isEqualTo(JpqlRound::class) } + @Test fun serialize() { // given val part = Expressions.round( value = expression1, - scale = expression2 + scale = expression2, ) val context = TestRenderContext(serializer) @@ -51,7 +52,8 @@ class JpqlRoundSerializerTest { writer.write("ROUND") writer.writeParentheses(any()) serializer.serialize(expression1, writer, context) - writer.write(", ") + writer.write(",") + writer.write(" ") serializer.serialize(expression2, writer, context) } } From aac989d3c14d3e7a0448ea492a53172bbf777566 Mon Sep 17 00:00:00 2001 From: "jonghyon.s" Date: Wed, 31 Jan 2024 10:39:14 +0900 Subject: [PATCH 047/169] style: reorder functions --- docs/en/jpql-with-kotlin-jdsl/expressions.md | 6 ++-- docs/ko/jpql-with-kotlin-jdsl/expressions.md | 6 ++-- .../com/linecorp/kotlinjdsl/dsl/jpql/Jpql.kt | 32 +++++++++---------- .../querymodel/jpql/expression/Expressions.kt | 16 +++++----- .../jpql/expression/ExpressionsTest.kt | 14 ++++---- 5 files changed, 37 insertions(+), 37 deletions(-) diff --git a/docs/en/jpql-with-kotlin-jdsl/expressions.md b/docs/en/jpql-with-kotlin-jdsl/expressions.md index cfe6bfa58..ee124dee0 100644 --- a/docs/en/jpql-with-kotlin-jdsl/expressions.md +++ b/docs/en/jpql-with-kotlin-jdsl/expressions.md @@ -225,17 +225,17 @@ Use the following functions to build arithmetic functions: * ABS (abs) * CEILING (ceiling) -* SQRT (sqrt) * ROUND (round) +* SQRT (sqrt) ```kotlin abs(path(Book::price)) ceiling(path(Book::price)) -sqrt(path(Book::price)) - round(path(Book::price), 2) + +sqrt(path(Book::price)) ``` | Function | DSL function | diff --git a/docs/ko/jpql-with-kotlin-jdsl/expressions.md b/docs/ko/jpql-with-kotlin-jdsl/expressions.md index e5dbfa6f4..e0acf2968 100644 --- a/docs/ko/jpql-with-kotlin-jdsl/expressions.md +++ b/docs/ko/jpql-with-kotlin-jdsl/expressions.md @@ -221,17 +221,17 @@ locate("Book", path(Book::title)) * ABS (abs) * CEILING (ceiling) -* SQRT (sqrt) * ROUND (round) +* SQRT (sqrt) ```kotlin abs(path(Book::price)) ceiling(path(Book::price)) -sqrt(path(Book::price)) - round(path(Book::price), 2) + +sqrt(path(Book::price)) ``` | Function | DSL function | 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 e4dcf3e2d..4d67fcf5c 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 @@ -568,22 +568,6 @@ open class Jpql : JpqlDsl { return Expressions.ceiling(value.toExpression()) } - /** - * Creates an expression that represents the square root of value. - */ - @SinceJdsl("3.4.0") - fun sqrt(expr: KProperty1): Expression { - return Expressions.sqrt(Paths.path(expr)) - } - - /** - * Creates an expression that represents the square root of value. - */ - @SinceJdsl("3.4.0") - fun sqrt(value: Expressionable): Expression { - return Expressions.sqrt(value.toExpression()) - } - /** * Creates an expression that represents the rounding of the value to a specified scale. */ @@ -616,6 +600,22 @@ open class Jpql : JpqlDsl { return Expressions.round(value.toExpression(), scale.toExpression()) } + /** + * Creates an expression that represents the square root of value. + */ + @SinceJdsl("3.4.0") + fun sqrt(expr: KProperty1): Expression { + return Expressions.sqrt(Paths.path(expr)) + } + + /** + * Creates an expression that represents the square root of value. + */ + @SinceJdsl("3.4.0") + fun sqrt(value: Expressionable): Expression { + return Expressions.sqrt(value.toExpression()) + } + /** * Creates an expression that represents the count of non-null values. * 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 4b3df31bb..39be02418 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 @@ -226,6 +226,14 @@ object Expressions { return JpqlCeiling(value) } + /** + * Creates an expression that represents the rounding of the specified value to a specified scale. + */ + @SinceJdsl("3.4.0") + fun round(value: Expression, scale: Expression): Expression { + return JpqlRound(value, scale) + } + /** * Creates an expression that represents the square root of the value. */ @@ -274,14 +282,6 @@ object Expressions { return JpqlAvg(distinct, expr) } - /** - * Creates an expression that represents the rounding of the specified value to a specified scale. - */ - @SinceJdsl("3.4.0") - fun round(value: Expression, scale: Expression): Expression { - return JpqlRound(value, scale) - } - /** * Creates an expression that represents the sum of values. * 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 5d26774bb..b06ae991f 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 @@ -363,12 +363,13 @@ class ExpressionsTest : WithAssertions { } @Test - fun sqrt() { + fun round() { // when - val actual = Expressions.sqrt(intExpression1) + val actual = Expressions.round(bigDecimalExpression1, intExpression1) // then - val expected = JpqlSqrt( + val expected = JpqlRound( + bigDecimalExpression1, intExpression1, ) @@ -376,13 +377,12 @@ class ExpressionsTest : WithAssertions { } @Test - fun round() { + fun sqrt() { // when - val actual = Expressions.round(bigDecimalExpression1, intExpression1) + val actual = Expressions.sqrt(intExpression1) // then - val expected = JpqlRound( - bigDecimalExpression1, + val expected = JpqlSqrt( intExpression1, ) From 1d27b82afff438ef8015d02543c12d55f0ca1c51 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 31 Jan 2024 19:36:59 +0000 Subject: [PATCH 048/169] chore(deps): update codecov/codecov-action action to v4 --- .github/workflows/test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 6882db836..054c4bdf3 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -28,7 +28,7 @@ jobs: - name: CodeCoverage(with test) with Gradle run: ./gradlew koverXmlReport - name: Upload coverage to Codecov - uses: codecov/codecov-action@v3 + uses: codecov/codecov-action@v4 with: token: ${{ secrets.CODECOV_TOKEN }} file: ./build/reports/kover/report.xml From cad88abc434678d3b54abec3de6efc8c24618adc Mon Sep 17 00:00:00 2001 From: Jake Son Date: Thu, 1 Feb 2024 06:52:10 +0900 Subject: [PATCH 049/169] feat: implement exp function --- .../com/linecorp/kotlinjdsl/dsl/jpql/Jpql.kt | 16 +++++++ .../dsl/jpql/expression/ExpDslTest.kt | 47 +++++++++++++++++++ .../querymodel/jpql/expression/Expressions.kt | 9 ++++ .../jpql/expression/impl/JpqlExp.kt | 12 +++++ .../jpql/expression/ExpressionsTest.kt | 14 ++++++ 5 files changed, 98 insertions(+) create mode 100644 dsl/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/expression/ExpDslTest.kt create mode 100644 query-model/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/expression/impl/JpqlExp.kt 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 75b37025d..9e372a559 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 @@ -568,6 +568,22 @@ open class Jpql : JpqlDsl { return Expressions.ceiling(value.toExpression()) } + /** + * Creates an expression that represents the exponential value. + */ + @SinceJdsl("3.4.0") + fun exp(expr: KProperty1): Expression { + return Expressions.exp(Paths.path(expr)) + } + + /** + * Creates an expression that represents the exponential value. + */ + @SinceJdsl("3.4.0") + fun exp(value: Expressionable): Expression { + return Expressions.exp(value.toExpression()) + } + /** * Creates an expression that is enclosed in floor. */ diff --git a/dsl/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/expression/ExpDslTest.kt b/dsl/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/expression/ExpDslTest.kt new file mode 100644 index 000000000..f8068a8ff --- /dev/null +++ b/dsl/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/expression/ExpDslTest.kt @@ -0,0 +1,47 @@ +package com.linecorp.kotlinjdsl.dsl.jpql.expression + +import com.linecorp.kotlinjdsl.dsl.jpql.entity.book.Book +import com.linecorp.kotlinjdsl.dsl.jpql.queryPart +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expression +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expressions +import com.linecorp.kotlinjdsl.querymodel.jpql.path.Paths +import org.assertj.core.api.WithAssertions +import org.junit.jupiter.api.Test + +class ExpDslTest : WithAssertions { + private val expression1 = Paths.path(Book::salePrice) + + @Test + fun `exp() with a property`() { + // when + val expression = queryPart { + exp(Book::price) + }.toExpression() + + val actual: Expression = expression // for type check + + // then + val expected = Expressions.exp( + value = Paths.path(Book::price), + ) + + assertThat(actual).isEqualTo(expected) + } + + @Test + fun `exp() with a expression`() { + // when + val expression = queryPart { + exp(expression1) + }.toExpression() + + val actual: Expression = expression // for type check + + // then + val expected = Expressions.exp( + value = expression1, + ) + + 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 045d93ea7..991c6fcac 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 @@ -14,6 +14,7 @@ import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlCount import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlCustomExpression import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlDivide import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlEntityType +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlExp import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlExpression import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlExpressionParentheses import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlFloor @@ -227,6 +228,14 @@ object Expressions { return JpqlCeiling(value) } + /** + * Creates an expression that represents the exponential value. + */ + @SinceJdsl("3.4.0") + fun exp(value: Expression): Expression { + return JpqlExp(value) + } + /** * Creates an expression that is enclosed in floor. */ diff --git a/query-model/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/expression/impl/JpqlExp.kt b/query-model/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/expression/impl/JpqlExp.kt new file mode 100644 index 000000000..a9fa75de7 --- /dev/null +++ b/query-model/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/expression/impl/JpqlExp.kt @@ -0,0 +1,12 @@ +package com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl + +import com.linecorp.kotlinjdsl.Internal +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expression + +/** + * Expression that applies exponential function to [value]. + */ +@Internal +data class JpqlExp internal constructor( + val value: Expression, +) : 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 9fb1f6b87..79e3a3ad6 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 @@ -16,6 +16,7 @@ import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlCount import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlCustomExpression import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlDivide import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlEntityType +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlExp import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlExpression import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlExpressionParentheses import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlFloor @@ -363,6 +364,19 @@ class ExpressionsTest : WithAssertions { assertThat(actual).isEqualTo(expected) } + @Test + fun exp() { + // when + val actual = Expressions.exp(doubleExpression1) + + // then + val expected = JpqlExp( + doubleExpression1, + ) + + assertThat(actual).isEqualTo(expected) + } + @Test fun floor() { // when From cdcea0b238d0f092b010ef296bbff6c25771e427 Mon Sep 17 00:00:00 2001 From: Jake Son Date: Thu, 1 Feb 2024 06:54:11 +0900 Subject: [PATCH 050/169] feat: implement exp function serializer --- .../render/jpql/JpqlRenderContext.kt | 2 + .../jpql/serializer/impl/JpqlExpSerializer.kt | 26 +++++++++ .../serializer/impl/JpqlExpSerializerTest.kt | 55 +++++++++++++++++++ 3 files changed, 83 insertions(+) create mode 100644 render/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlExpSerializer.kt create mode 100644 render/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlExpSerializerTest.kt 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 094735378..d00405e24 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 @@ -37,6 +37,7 @@ import com.linecorp.kotlinjdsl.render.jpql.serializer.impl.JpqlEqualAllSerialize import com.linecorp.kotlinjdsl.render.jpql.serializer.impl.JpqlEqualAnySerializer import com.linecorp.kotlinjdsl.render.jpql.serializer.impl.JpqlEqualSerializer import com.linecorp.kotlinjdsl.render.jpql.serializer.impl.JpqlExistsSerializer +import com.linecorp.kotlinjdsl.render.jpql.serializer.impl.JpqlExpSerializer import com.linecorp.kotlinjdsl.render.jpql.serializer.impl.JpqlExpressionParenthesesSerializer import com.linecorp.kotlinjdsl.render.jpql.serializer.impl.JpqlExpressionSerializer import com.linecorp.kotlinjdsl.render.jpql.serializer.impl.JpqlFloorSerializer @@ -287,6 +288,7 @@ private class DefaultModule : JpqlRenderModule { JpqlEqualAnySerializer(), JpqlEqualSerializer(), JpqlExistsSerializer(), + JpqlExpSerializer(), JpqlExpressionParenthesesSerializer(), JpqlExpressionSerializer(), JpqlFloorSerializer(), diff --git a/render/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlExpSerializer.kt b/render/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlExpSerializer.kt new file mode 100644 index 000000000..ccafd08f7 --- /dev/null +++ b/render/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlExpSerializer.kt @@ -0,0 +1,26 @@ +package com.linecorp.kotlinjdsl.render.jpql.serializer.impl + +import com.linecorp.kotlinjdsl.Internal +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlExp +import com.linecorp.kotlinjdsl.render.RenderContext +import com.linecorp.kotlinjdsl.render.jpql.serializer.JpqlRenderSerializer +import com.linecorp.kotlinjdsl.render.jpql.serializer.JpqlSerializer +import com.linecorp.kotlinjdsl.render.jpql.writer.JpqlWriter +import kotlin.reflect.KClass + +@Internal +class JpqlExpSerializer : JpqlSerializer> { + override fun handledType(): KClass> { + return JpqlExp::class + } + + override fun serialize(part: JpqlExp<*>, writer: JpqlWriter, context: RenderContext) { + val delegate = context.getValue(JpqlRenderSerializer) + + writer.write("EXP") + + writer.writeParentheses { + delegate.serialize(part.value, writer, context) + } + } +} diff --git a/render/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlExpSerializerTest.kt b/render/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlExpSerializerTest.kt new file mode 100644 index 000000000..3317eba54 --- /dev/null +++ b/render/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlExpSerializerTest.kt @@ -0,0 +1,55 @@ +package com.linecorp.kotlinjdsl.render.jpql.serializer.impl + +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expressions +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlExp +import com.linecorp.kotlinjdsl.querymodel.jpql.path.Paths +import com.linecorp.kotlinjdsl.render.TestRenderContext +import com.linecorp.kotlinjdsl.render.jpql.entity.book.Book +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.WithAssertions +import org.junit.jupiter.api.Test + +@JpqlSerializerTest +class JpqlExpSerializerTest : WithAssertions { + private val sut = JpqlExpSerializer() + + @MockK + private lateinit var writer: JpqlWriter + + @MockK + private lateinit var serializer: JpqlRenderSerializer + + private val expression1 = Paths.path(Book::price) + + @Test + fun handledType() { + // when + val actual = sut.handledType() + + // then + assertThat(actual).isEqualTo(JpqlExp::class) + } + + @Test + fun serialize() { + // given + val part = Expressions.exp( + value = expression1, + ) + val context = TestRenderContext(serializer) + + // when + sut.serialize(part as JpqlExp<*>, writer, context) + + // then + verifySequence { + writer.write("EXP") + writer.writeParentheses(any()) + serializer.serialize(expression1, writer, context) + } + } +} From b385fa119fd422476659be5dfa67d635a5cbc0c8 Mon Sep 17 00:00:00 2001 From: Jake Son Date: Thu, 1 Feb 2024 06:55:37 +0900 Subject: [PATCH 051/169] docs: add exp function description --- docs/en/jpql-with-kotlin-jdsl/expressions.md | 4 +++- docs/ko/jpql-with-kotlin-jdsl/expressions.md | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/en/jpql-with-kotlin-jdsl/expressions.md b/docs/en/jpql-with-kotlin-jdsl/expressions.md index 287f4e195..7246176b5 100644 --- a/docs/en/jpql-with-kotlin-jdsl/expressions.md +++ b/docs/en/jpql-with-kotlin-jdsl/expressions.md @@ -225,6 +225,7 @@ Use the following functions to build arithmetic functions: * ABS (abs) * CEILING (ceiling) +* EXP (exp) * FLOOR (floor) * ROUND (round) * SQRT (sqrt) @@ -234,6 +235,8 @@ abs(path(Book::price)) ceiling(path(Book::price)) +exp(path(Book::price)) + floor(path(Book::price)) round(path(Book::price), 2) @@ -243,7 +246,6 @@ sqrt(path(Book::price)) | Function | DSL function | |----------|--------------| -| EXP | not yet | | FLOOR | not yet | | LN | not yet | | MOD | not yet | diff --git a/docs/ko/jpql-with-kotlin-jdsl/expressions.md b/docs/ko/jpql-with-kotlin-jdsl/expressions.md index 9c13e1c98..5313adc51 100644 --- a/docs/ko/jpql-with-kotlin-jdsl/expressions.md +++ b/docs/ko/jpql-with-kotlin-jdsl/expressions.md @@ -221,6 +221,7 @@ locate("Book", path(Book::title)) * ABS (abs) * CEILING (ceiling) +* EXP (exp) * FLOOR (floor) * ROUND (round) * SQRT (sqrt) @@ -230,6 +231,8 @@ abs(path(Book::price)) ceiling(path(Book::price)) +exp(path(Book::price)) + floor(path(Book::price)) round(path(Book::price), 2) @@ -239,7 +242,6 @@ sqrt(path(Book::price)) | Function | DSL function | |----------|--------------| -| EXP | not yet | | FLOOR | not yet | | LN | not yet | | MOD | not yet | From 61612ff5f525fa7ed5ad75b58dcf906654d1a33b Mon Sep 17 00:00:00 2001 From: Jake Son Date: Thu, 1 Feb 2024 07:06:13 +0900 Subject: [PATCH 052/169] feat: implement ln function --- .../com/linecorp/kotlinjdsl/dsl/jpql/Jpql.kt | 16 +++++++ .../dsl/jpql/expression/LnDslTest.kt | 47 +++++++++++++++++++ .../querymodel/jpql/expression/Expressions.kt | 9 ++++ .../querymodel/jpql/expression/impl/JpqlLn.kt | 12 +++++ .../jpql/expression/ExpressionsTest.kt | 14 ++++++ 5 files changed, 98 insertions(+) create mode 100644 dsl/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/expression/LnDslTest.kt create mode 100644 query-model/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/expression/impl/JpqlLn.kt 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 75b37025d..6dd8ed070 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 @@ -584,6 +584,22 @@ open class Jpql : JpqlDsl { return Expressions.floor(value.toExpression()) } + /** + * Creates an expression that represents the natural logarithm of value. + */ + @SinceJdsl("3.4.0") + fun ln(expr: KProperty1): Expression { + return Expressions.ln(Paths.path(expr)) + } + + /** + * Creates an expression that represents the natural logarithm of value. + */ + @SinceJdsl("3.4.0") + fun ln(value: Expressionable): Expression { + return Expressions.ln(value.toExpression()) + } + /** * Creates an expression that represents the rounding of the value to a specified scale. */ diff --git a/dsl/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/expression/LnDslTest.kt b/dsl/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/expression/LnDslTest.kt new file mode 100644 index 000000000..ad5ea8750 --- /dev/null +++ b/dsl/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/expression/LnDslTest.kt @@ -0,0 +1,47 @@ +package com.linecorp.kotlinjdsl.dsl.jpql.expression + +import com.linecorp.kotlinjdsl.dsl.jpql.entity.book.Book +import com.linecorp.kotlinjdsl.dsl.jpql.queryPart +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expression +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expressions +import com.linecorp.kotlinjdsl.querymodel.jpql.path.Paths +import org.assertj.core.api.WithAssertions +import org.junit.jupiter.api.Test + +class LnDslTest : WithAssertions { + private val expression1 = Paths.path(Book::salePrice) + + @Test + fun `ln() with a property`() { + // when + val expression = queryPart { + ln(Book::price) + }.toExpression() + + val actual: Expression = expression // for type check + + // then + val expected = Expressions.ln( + value = Paths.path(Book::price), + ) + + assertThat(actual).isEqualTo(expected) + } + + @Test + fun `ln() with a expression`() { + // when + val expression = queryPart { + ln(expression1) + }.toExpression() + + val actual: Expression = expression // for type check + + // then + val expected = Expressions.ln( + value = expression1, + ) + + 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 045d93ea7..590b914a4 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 @@ -20,6 +20,7 @@ import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlFloor 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.JpqlLn 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 @@ -235,6 +236,14 @@ object Expressions { return JpqlFloor(value) } + /** + * Creates an expression that represents the natural logarithm of the value. + */ + @SinceJdsl("3.4.0") + fun ln(value: Expression): Expression { + return JpqlLn(value) + } + /** * Creates an expression that represents the rounding of the specified value to a specified scale. */ diff --git a/query-model/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/expression/impl/JpqlLn.kt b/query-model/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/expression/impl/JpqlLn.kt new file mode 100644 index 000000000..36268c213 --- /dev/null +++ b/query-model/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/expression/impl/JpqlLn.kt @@ -0,0 +1,12 @@ +package com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl + +import com.linecorp.kotlinjdsl.Internal +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expression + +/** + * Expression that applies natural logarithm function to [value]. + */ +@Internal +data class JpqlLn internal constructor( + val value: Expression, +) : 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 9fb1f6b87..69ee10a8d 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 @@ -22,6 +22,7 @@ import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlFloor 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.JpqlLn 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 @@ -376,6 +377,19 @@ class ExpressionsTest : WithAssertions { assertThat(actual).isEqualTo(expected) } + @Test + fun ln() { + // when + val actual = Expressions.ln(doubleExpression1) + + // then + val expected = JpqlLn( + doubleExpression1, + ) + + assertThat(actual).isEqualTo(expected) + } + @Test fun round() { // when From 19aa609f03d7c6bffb6d91b373e7cf8dd8a61b98 Mon Sep 17 00:00:00 2001 From: Jake Son Date: Thu, 1 Feb 2024 07:08:34 +0900 Subject: [PATCH 053/169] feat: implement ln function serializer --- .../render/jpql/JpqlRenderContext.kt | 2 + .../jpql/serializer/impl/JpqlLnSerializer.kt | 26 +++++++++ .../serializer/impl/JpqlLnSerializerTest.kt | 55 +++++++++++++++++++ 3 files changed, 83 insertions(+) create mode 100644 render/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlLnSerializer.kt create mode 100644 render/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlLnSerializerTest.kt 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 094735378..e2a7df900 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 @@ -72,6 +72,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.JpqlLnSerializer 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 @@ -322,6 +323,7 @@ private class DefaultModule : JpqlRenderModule { JpqlLessThanSerializer(), JpqlLikeSerializer(), JpqlLiteralSerializer(), + JpqlLnSerializer(), JpqlLocateSerializer(), JpqlLowerSerializer(), JpqlMaxSerializer(), diff --git a/render/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlLnSerializer.kt b/render/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlLnSerializer.kt new file mode 100644 index 000000000..0c8ded7b4 --- /dev/null +++ b/render/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlLnSerializer.kt @@ -0,0 +1,26 @@ +package com.linecorp.kotlinjdsl.render.jpql.serializer.impl + +import com.linecorp.kotlinjdsl.Internal +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlLn +import com.linecorp.kotlinjdsl.render.RenderContext +import com.linecorp.kotlinjdsl.render.jpql.serializer.JpqlRenderSerializer +import com.linecorp.kotlinjdsl.render.jpql.serializer.JpqlSerializer +import com.linecorp.kotlinjdsl.render.jpql.writer.JpqlWriter +import kotlin.reflect.KClass + +@Internal +class JpqlLnSerializer : JpqlSerializer> { + override fun handledType(): KClass> { + return JpqlLn::class + } + + override fun serialize(part: JpqlLn<*>, writer: JpqlWriter, context: RenderContext) { + val delegate = context.getValue(JpqlRenderSerializer) + + writer.write("LN") + + writer.writeParentheses { + delegate.serialize(part.value, writer, context) + } + } +} diff --git a/render/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlLnSerializerTest.kt b/render/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlLnSerializerTest.kt new file mode 100644 index 000000000..61f489b33 --- /dev/null +++ b/render/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlLnSerializerTest.kt @@ -0,0 +1,55 @@ +package com.linecorp.kotlinjdsl.render.jpql.serializer.impl + +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expressions +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlLn +import com.linecorp.kotlinjdsl.querymodel.jpql.path.Paths +import com.linecorp.kotlinjdsl.render.TestRenderContext +import com.linecorp.kotlinjdsl.render.jpql.entity.book.Book +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.WithAssertions +import org.junit.jupiter.api.Test + +@JpqlSerializerTest +class JpqlLnSerializerTest : WithAssertions { + private val sut = JpqlLnSerializer() + + @MockK + private lateinit var writer: JpqlWriter + + @MockK + private lateinit var serializer: JpqlRenderSerializer + + private val expression1 = Paths.path(Book::price) + + @Test + fun handledType() { + // when + val actual = sut.handledType() + + // then + assertThat(actual).isEqualTo(JpqlLn::class) + } + + @Test + fun serialize() { + // given + val part = Expressions.ln( + value = expression1, + ) + val context = TestRenderContext(serializer) + + // when + sut.serialize(part as JpqlLn<*>, writer, context) + + // then + verifySequence { + writer.write("LN") + writer.writeParentheses(any()) + serializer.serialize(expression1, writer, context) + } + } +} From 3f049da2d86de34eddfa3dad19cb956d1c1716fa Mon Sep 17 00:00:00 2001 From: Jake Son Date: Thu, 1 Feb 2024 07:10:02 +0900 Subject: [PATCH 054/169] docs: add ln function description --- docs/en/jpql-with-kotlin-jdsl/expressions.md | 5 +++-- docs/ko/jpql-with-kotlin-jdsl/expressions.md | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/docs/en/jpql-with-kotlin-jdsl/expressions.md b/docs/en/jpql-with-kotlin-jdsl/expressions.md index 287f4e195..e6f510b16 100644 --- a/docs/en/jpql-with-kotlin-jdsl/expressions.md +++ b/docs/en/jpql-with-kotlin-jdsl/expressions.md @@ -226,6 +226,7 @@ Use the following functions to build arithmetic functions: * ABS (abs) * CEILING (ceiling) * FLOOR (floor) +* LN (ln) * ROUND (round) * SQRT (sqrt) @@ -236,6 +237,8 @@ ceiling(path(Book::price)) floor(path(Book::price)) +ln(path(Book::price)) + round(path(Book::price), 2) sqrt(path(Book::price)) @@ -244,8 +247,6 @@ sqrt(path(Book::price)) | Function | DSL function | |----------|--------------| | EXP | not yet | -| FLOOR | not yet | -| LN | not yet | | MOD | not yet | | POWER | not yet | | SIGN | not yet | diff --git a/docs/ko/jpql-with-kotlin-jdsl/expressions.md b/docs/ko/jpql-with-kotlin-jdsl/expressions.md index 9c13e1c98..332568c5a 100644 --- a/docs/ko/jpql-with-kotlin-jdsl/expressions.md +++ b/docs/ko/jpql-with-kotlin-jdsl/expressions.md @@ -222,6 +222,7 @@ locate("Book", path(Book::title)) * ABS (abs) * CEILING (ceiling) * FLOOR (floor) +* LN (ln) * ROUND (round) * SQRT (sqrt) @@ -232,6 +233,8 @@ ceiling(path(Book::price)) floor(path(Book::price)) +ln(path(Book::price)) + round(path(Book::price), 2) sqrt(path(Book::price)) @@ -240,8 +243,6 @@ sqrt(path(Book::price)) | Function | DSL function | |----------|--------------| | EXP | not yet | -| FLOOR | not yet | -| LN | not yet | | MOD | not yet | | POWER | not yet | | SIGN | not yet | From fe5b40f617b53571c2249748656d518b78c78635 Mon Sep 17 00:00:00 2001 From: Jake Son Date: Thu, 1 Feb 2024 07:35:20 +0900 Subject: [PATCH 055/169] feat: implement sign function --- .../com/linecorp/kotlinjdsl/dsl/jpql/Jpql.kt | 24 ++++++++++ .../dsl/jpql/expression/SignDslTest.kt | 47 +++++++++++++++++++ .../querymodel/jpql/expression/Expressions.kt | 9 ++++ .../jpql/expression/impl/JpqlSign.kt | 12 +++++ .../jpql/expression/ExpressionsTest.kt | 14 ++++++ 5 files changed, 106 insertions(+) create mode 100644 dsl/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/expression/SignDslTest.kt create mode 100644 query-model/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/expression/impl/JpqlSign.kt 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 75b37025d..dcfbfd111 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 @@ -616,6 +616,30 @@ open class Jpql : JpqlDsl { return Expressions.round(value.toExpression(), scale.toExpression()) } + /** + * Creates an expression that represents the sign of value. + * + * - If value is positive, it returns 1. + * - If value is negative, it returns -1. + * - If value is zero, it returns 0. + */ + @SinceJdsl("3.4.0") + fun sign(expr: KProperty1): Expression { + return Expressions.sign(Paths.path(expr)) + } + + /** + * Creates an expression that represents the sign of value. + * + * - If value is positive, it returns 1. + * - If value is negative, it returns -1. + * - If value is zero, it returns 0. + */ + @SinceJdsl("3.4.0") + fun sign(value: Expressionable): Expression { + return Expressions.sign(value.toExpression()) + } + /** * Creates an expression that represents the square root of value. */ diff --git a/dsl/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/expression/SignDslTest.kt b/dsl/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/expression/SignDslTest.kt new file mode 100644 index 000000000..0e3ad933c --- /dev/null +++ b/dsl/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/expression/SignDslTest.kt @@ -0,0 +1,47 @@ +package com.linecorp.kotlinjdsl.dsl.jpql.expression + +import com.linecorp.kotlinjdsl.dsl.jpql.entity.book.Book +import com.linecorp.kotlinjdsl.dsl.jpql.queryPart +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expression +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expressions +import com.linecorp.kotlinjdsl.querymodel.jpql.path.Paths +import org.assertj.core.api.WithAssertions +import org.junit.jupiter.api.Test + +class SignDslTest : WithAssertions { + private val expression1 = Paths.path(Book::salePrice) + + @Test + fun `sign() with a property`() { + // when + val expression = queryPart { + sign(Book::price) + }.toExpression() + + val actual: Expression = expression // for type check + + // then + val expected = Expressions.sign( + value = Paths.path(Book::price), + ) + + assertThat(actual).isEqualTo(expected) + } + + @Test + fun `sign() with a expression`() { + // when + val expression = queryPart { + sign(expression1) + }.toExpression() + + val actual: Expression = expression // for type check + + // then + val expected = Expressions.sign( + value = expression1, + ) + + 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 045d93ea7..b443d073b 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 @@ -32,6 +32,7 @@ import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlParam import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlPathType import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlPlus import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlRound +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlSign import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlSqrt import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlSubquery import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlSubstring @@ -243,6 +244,14 @@ object Expressions { return JpqlRound(value, scale) } + /** + * Creates an expression that represents the sign of a numeric value. + */ + @SinceJdsl("3.4.0") + fun sign(value: Expression): Expression { + return JpqlSign(value) + } + /** * Creates an expression that represents the square root of the value. */ diff --git a/query-model/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/expression/impl/JpqlSign.kt b/query-model/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/expression/impl/JpqlSign.kt new file mode 100644 index 000000000..25160d693 --- /dev/null +++ b/query-model/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/expression/impl/JpqlSign.kt @@ -0,0 +1,12 @@ +package com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl + +import com.linecorp.kotlinjdsl.Internal +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expression + +/** + * Expression that calculates the sign of a numeric [value]. + */ +@Internal +data class JpqlSign internal constructor( + val value: Expression, +) : 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 9fb1f6b87..6b0246d44 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 @@ -34,6 +34,7 @@ import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlParam import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlPathType import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlPlus import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlRound +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlSign import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlSqrt import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlSubquery import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlSubstring @@ -390,6 +391,19 @@ class ExpressionsTest : WithAssertions { assertThat(actual).isEqualTo(expected) } + @Test + fun sign() { + // when + val actual = Expressions.sign(intExpression1) + + // then + val expected = JpqlSign( + intExpression1, + ) + + assertThat(actual).isEqualTo(expected) + } + @Test fun sqrt() { // when From 7963b71c44065b414107aee33eccca4cabb41639 Mon Sep 17 00:00:00 2001 From: Jake Son Date: Thu, 1 Feb 2024 07:38:18 +0900 Subject: [PATCH 056/169] feat: implement sign function serializer --- .../render/jpql/JpqlRenderContext.kt | 2 + .../serializer/impl/JpqlSignSerializer.kt | 26 +++++++++ .../serializer/impl/JpqlSignSerializerTest.kt | 55 +++++++++++++++++++ 3 files changed, 83 insertions(+) create mode 100644 render/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlSignSerializer.kt create mode 100644 render/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlSignSerializerTest.kt 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 094735378..3872d5ee9 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 @@ -98,6 +98,7 @@ import com.linecorp.kotlinjdsl.render.jpql.serializer.impl.JpqlPlusSerializer import com.linecorp.kotlinjdsl.render.jpql.serializer.impl.JpqlPredicateParenthesesSerializer import com.linecorp.kotlinjdsl.render.jpql.serializer.impl.JpqlRoundSerializer import com.linecorp.kotlinjdsl.render.jpql.serializer.impl.JpqlSelectQuerySerializer +import com.linecorp.kotlinjdsl.render.jpql.serializer.impl.JpqlSignSerializer import com.linecorp.kotlinjdsl.render.jpql.serializer.impl.JpqlSortSerializer import com.linecorp.kotlinjdsl.render.jpql.serializer.impl.JpqlSqrtSerializer import com.linecorp.kotlinjdsl.render.jpql.serializer.impl.JpqlSubquerySerializer @@ -348,6 +349,7 @@ private class DefaultModule : JpqlRenderModule { JpqlPredicateParenthesesSerializer(), JpqlRoundSerializer(), JpqlSelectQuerySerializer(), + JpqlSignSerializer(), JpqlSortSerializer(), JpqlSqrtSerializer(), JpqlSubquerySerializer(), diff --git a/render/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlSignSerializer.kt b/render/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlSignSerializer.kt new file mode 100644 index 000000000..bc88ba206 --- /dev/null +++ b/render/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlSignSerializer.kt @@ -0,0 +1,26 @@ +package com.linecorp.kotlinjdsl.render.jpql.serializer.impl + +import com.linecorp.kotlinjdsl.Internal +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlSign +import com.linecorp.kotlinjdsl.render.RenderContext +import com.linecorp.kotlinjdsl.render.jpql.serializer.JpqlRenderSerializer +import com.linecorp.kotlinjdsl.render.jpql.serializer.JpqlSerializer +import com.linecorp.kotlinjdsl.render.jpql.writer.JpqlWriter +import kotlin.reflect.KClass + +@Internal +class JpqlSignSerializer : JpqlSerializer> { + override fun handledType(): KClass> { + return JpqlSign::class + } + + override fun serialize(part: JpqlSign<*>, writer: JpqlWriter, context: RenderContext) { + val delegate = context.getValue(JpqlRenderSerializer) + + writer.write("SIGN") + + writer.writeParentheses { + delegate.serialize(part.value, writer, context) + } + } +} diff --git a/render/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlSignSerializerTest.kt b/render/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlSignSerializerTest.kt new file mode 100644 index 000000000..c8b56251c --- /dev/null +++ b/render/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlSignSerializerTest.kt @@ -0,0 +1,55 @@ +package com.linecorp.kotlinjdsl.render.jpql.serializer.impl + +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expressions +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlSign +import com.linecorp.kotlinjdsl.querymodel.jpql.path.Paths +import com.linecorp.kotlinjdsl.render.TestRenderContext +import com.linecorp.kotlinjdsl.render.jpql.entity.book.Book +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.WithAssertions +import org.junit.jupiter.api.Test + +@JpqlSerializerTest +class JpqlSignSerializerTest : WithAssertions { + private val sut = JpqlSignSerializer() + + @MockK + private lateinit var writer: JpqlWriter + + @MockK + private lateinit var serializer: JpqlRenderSerializer + + private val expression1 = Paths.path(Book::price) + + @Test + fun handledType() { + // when + val actual = sut.handledType() + + // then + assertThat(actual).isEqualTo(JpqlSign::class) + } + + @Test + fun serialize() { + // given + val part = Expressions.sign( + value = expression1, + ) + val context = TestRenderContext(serializer) + + // when + sut.serialize(part as JpqlSign<*>, writer, context) + + // then + verifySequence { + writer.write("SIGN") + writer.writeParentheses(any()) + serializer.serialize(expression1, writer, context) + } + } +} From 1a4187c9f5c1b3f32e9d7d53671bbef887ced127 Mon Sep 17 00:00:00 2001 From: Jake Son Date: Thu, 1 Feb 2024 07:39:18 +0900 Subject: [PATCH 057/169] docs: add sign function description --- docs/en/jpql-with-kotlin-jdsl/expressions.md | 4 +++- docs/ko/jpql-with-kotlin-jdsl/expressions.md | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/en/jpql-with-kotlin-jdsl/expressions.md b/docs/en/jpql-with-kotlin-jdsl/expressions.md index 287f4e195..4ff982357 100644 --- a/docs/en/jpql-with-kotlin-jdsl/expressions.md +++ b/docs/en/jpql-with-kotlin-jdsl/expressions.md @@ -227,6 +227,7 @@ Use the following functions to build arithmetic functions: * CEILING (ceiling) * FLOOR (floor) * ROUND (round) +* SIGN (sign) * SQRT (sqrt) ```kotlin @@ -238,6 +239,8 @@ floor(path(Book::price)) round(path(Book::price), 2) +sign(path(Book::price)) + sqrt(path(Book::price)) ``` @@ -248,7 +251,6 @@ sqrt(path(Book::price)) | LN | not yet | | MOD | not yet | | POWER | not yet | -| SIGN | not yet | | SIZE | not yet | | INDEX | not yet | diff --git a/docs/ko/jpql-with-kotlin-jdsl/expressions.md b/docs/ko/jpql-with-kotlin-jdsl/expressions.md index 9c13e1c98..fef9616ba 100644 --- a/docs/ko/jpql-with-kotlin-jdsl/expressions.md +++ b/docs/ko/jpql-with-kotlin-jdsl/expressions.md @@ -223,6 +223,7 @@ locate("Book", path(Book::title)) * CEILING (ceiling) * FLOOR (floor) * ROUND (round) +* SIGN (sign) * SQRT (sqrt) ```kotlin @@ -234,6 +235,8 @@ floor(path(Book::price)) round(path(Book::price), 2) +sign(path(Book::price)) + sqrt(path(Book::price)) ``` @@ -244,7 +247,6 @@ sqrt(path(Book::price)) | LN | not yet | | MOD | not yet | | POWER | not yet | -| SIGN | not yet | | SIZE | not yet | | INDEX | not yet | From d2af51455070ae4a7f47b4c92ed5b8abbbdd8d89 Mon Sep 17 00:00:00 2001 From: Jake Son Date: Thu, 1 Feb 2024 21:48:24 +0900 Subject: [PATCH 058/169] style: reorder code --- .../com/linecorp/kotlinjdsl/render/jpql/JpqlRenderContext.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 d00405e24..a64860996 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 @@ -288,9 +288,9 @@ private class DefaultModule : JpqlRenderModule { JpqlEqualAnySerializer(), JpqlEqualSerializer(), JpqlExistsSerializer(), - JpqlExpSerializer(), JpqlExpressionParenthesesSerializer(), JpqlExpressionSerializer(), + JpqlExpSerializer(), JpqlFloorSerializer(), JpqlFunctionExpressionSerializer(), JpqlFunctionPredicateSerializer(), From 61bbed70560c9412bd3e1d3ebdf4794d4441dbbc Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 2 Feb 2024 20:17:43 +0000 Subject: [PATCH 059/169] chore(deps): update dependency gradle to v8.6 --- gradle/wrapper/gradle-wrapper.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 1af9e0930..a80b22ce5 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME From c1219b43e03cc97b6c35125c1c15e9987fefabc0 Mon Sep 17 00:00:00 2001 From: meengi Date: Sat, 3 Feb 2024 02:10:54 +0900 Subject: [PATCH 060/169] feat: implement current date & time function --- .../com/linecorp/kotlinjdsl/dsl/jpql/Jpql.kt | 22 ++++++++ .../dsl/jpql/expression/CurrentDateDslTest.kt | 40 ++++++++++++++ .../dsl/jpql/expression/CurrentTimeDslTest.kt | 40 ++++++++++++++ .../querymodel/jpql/expression/Expressions.kt | 19 +++++++ .../jpql/expression/impl/JpqlCurrent.kt | 17 ++++++ .../jpql/expression/ExpressionsTest.kt | 23 ++++++++ .../render/jpql/JpqlRenderContext.kt | 4 ++ .../impl/JpqlCurrentDateSerializer.kt | 26 ++++++++++ .../impl/JpqlCurrentTimeSerializer.kt | 26 ++++++++++ .../impl/JpqlCurrentDateSerializerTest.kt | 52 +++++++++++++++++++ .../impl/JpqlCurrentTimeSerializerTest.kt | 52 +++++++++++++++++++ 11 files changed, 321 insertions(+) create mode 100644 dsl/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/expression/CurrentDateDslTest.kt create mode 100644 dsl/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/expression/CurrentTimeDslTest.kt create mode 100644 query-model/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/expression/impl/JpqlCurrent.kt create mode 100644 render/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlCurrentDateSerializer.kt create mode 100644 render/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlCurrentTimeSerializer.kt create mode 100644 render/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlCurrentDateSerializerTest.kt create mode 100644 render/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlCurrentTimeSerializerTest.kt 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..19313d70d 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,8 @@ 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 java.time.LocalTime import kotlin.internal.Exact import kotlin.internal.LowPriorityInOverloadResolution import kotlin.reflect.KClass @@ -486,6 +488,26 @@ open class Jpql : JpqlDsl { return Expressions.times(this.toExpression(), value.toExpression()) } + /** + * Creates an expression that represents the current date. + * + * This is the same as ```CURRENT_DATE```. + */ + @SinceJdsl("3.4.0") + fun currentDate(): Expression { + return Expressions.currentDate() + } + + /** + * Creates an expression that represents the current time. + * + * This is the same as ```CURRENT_TIME```. + */ + @SinceJdsl("3.4.0") + fun currentTime(): Expression { + return Expressions.currentTime() + } + /** * Creates an expression that represents the divide of values. * The values are each enclosed in parentheses. diff --git a/dsl/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/expression/CurrentDateDslTest.kt b/dsl/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/expression/CurrentDateDslTest.kt new file mode 100644 index 000000000..507ca5479 --- /dev/null +++ b/dsl/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/expression/CurrentDateDslTest.kt @@ -0,0 +1,40 @@ +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.WithAssertions +import org.junit.jupiter.api.Test +import java.time.LocalDate + +class CurrentDateDslTest : WithAssertions { + @Test + fun `currentDate() with a property`() { + // when + val expression = queryPart { + currentDate() + }.toExpression() + + val actual: Expression = expression // for type check + + // then + val expected = Expressions.currentDate() + + assertThat(actual).isEqualTo(expected) + } + + @Test + fun `currentDate() with a expression`() { + // when + val expression = queryPart { + currentDate() + }.toExpression() + + val actual: Expression = expression // for type check + + // then + val expected = Expressions.currentDate() + + assertThat(actual).isEqualTo(expected) + } +} diff --git a/dsl/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/expression/CurrentTimeDslTest.kt b/dsl/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/expression/CurrentTimeDslTest.kt new file mode 100644 index 000000000..7d357954d --- /dev/null +++ b/dsl/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/expression/CurrentTimeDslTest.kt @@ -0,0 +1,40 @@ +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.WithAssertions +import org.junit.jupiter.api.Test +import java.time.LocalTime + +class CurrentTimeDslTest : WithAssertions { + @Test + fun `currentDate() with a property`() { + // when + val expression = queryPart { + currentTime() + }.toExpression() + + val actual: Expression = expression // for type check + + // then + val expected = Expressions.currentTime() + + assertThat(actual).isEqualTo(expected) + } + + @Test + fun `currentDate() with a expression`() { + // when + val expression = queryPart { + currentTime() + }.toExpression() + + val actual: Expression = expression // for type check + + // then + val expected = Expressions.currentTime() + + 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..1309ffc7c 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 @@ -9,6 +9,7 @@ import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlCaseWhen import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlCoalesce import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlConcat import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlCount +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlCurrent import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlCustomExpression import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlDivide import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlEntityType @@ -44,6 +45,8 @@ 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 java.time.LocalTime import kotlin.internal.Exact import kotlin.reflect.KClass @@ -633,4 +636,20 @@ object Expressions { fun parentheses(expr: Expression): Expression { return JpqlExpressionParentheses(expr) } + + /** + * Creates an expression that represents the current date. + */ + @SinceJdsl("3.4.0") + fun currentDate(): Expression { + return JpqlCurrent.CurrentDate + } + + /** + * Creates an expression that represents the current time. + */ + @SinceJdsl("3.4.0") + fun currentTime(): Expression { + return JpqlCurrent.CurrentTime + } } diff --git a/query-model/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/expression/impl/JpqlCurrent.kt b/query-model/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/expression/impl/JpqlCurrent.kt new file mode 100644 index 000000000..7486fb302 --- /dev/null +++ b/query-model/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/expression/impl/JpqlCurrent.kt @@ -0,0 +1,17 @@ +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 +import java.time.LocalTime + +/** + * Expression that represents the current date & time. + */ +@Internal +sealed interface JpqlCurrent : Expression { + + object CurrentDate : JpqlCurrent + + object CurrentTime : JpqlCurrent +} 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..c22eef5e0 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 @@ -11,6 +11,7 @@ import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlCaseWhen import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlCoalesce import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlConcat import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlCount +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlCurrent import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlCustomExpression import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlDivide import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlEntityType @@ -318,6 +319,28 @@ class ExpressionsTest : WithAssertions { assertThat(actual).isEqualTo(expected) } + @Test + fun currentDate() { + // when + val actual = Expressions.currentDate() + + // then + val expected = JpqlCurrent.CurrentDate + + assertThat(actual).isEqualTo(expected) + } + + @Test + fun currentTime() { + // when + val actual = Expressions.currentTime() + + // then + val expected = JpqlCurrent.CurrentTime + + assertThat(actual).isEqualTo(expected) + } + @Test fun div() { // 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..38fa531b9 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 @@ -22,6 +22,8 @@ import com.linecorp.kotlinjdsl.render.jpql.serializer.impl.JpqlCaseWhenSerialize import com.linecorp.kotlinjdsl.render.jpql.serializer.impl.JpqlCoalesceSerializer import com.linecorp.kotlinjdsl.render.jpql.serializer.impl.JpqlConcatSerializer import com.linecorp.kotlinjdsl.render.jpql.serializer.impl.JpqlCountSerializer +import com.linecorp.kotlinjdsl.render.jpql.serializer.impl.JpqlCurrentDateSerializer +import com.linecorp.kotlinjdsl.render.jpql.serializer.impl.JpqlCurrentTimeSerializer import com.linecorp.kotlinjdsl.render.jpql.serializer.impl.JpqlCustomExpressionSerializer import com.linecorp.kotlinjdsl.render.jpql.serializer.impl.JpqlCustomPredicateSerializer import com.linecorp.kotlinjdsl.render.jpql.serializer.impl.JpqlDeleteQuerySerializer @@ -267,6 +269,8 @@ private class DefaultModule : JpqlRenderModule { JpqlCoalesceSerializer(), JpqlConcatSerializer(), JpqlCountSerializer(), + JpqlCurrentDateSerializer(), + JpqlCurrentTimeSerializer(), JpqlCustomExpressionSerializer(), JpqlCustomPredicateSerializer(), JpqlDeleteQuerySerializer(), diff --git a/render/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlCurrentDateSerializer.kt b/render/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlCurrentDateSerializer.kt new file mode 100644 index 000000000..962812fc1 --- /dev/null +++ b/render/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlCurrentDateSerializer.kt @@ -0,0 +1,26 @@ +package com.linecorp.kotlinjdsl.render.jpql.serializer.impl + +import com.linecorp.kotlinjdsl.Internal +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlCurrent +import com.linecorp.kotlinjdsl.render.RenderContext +import com.linecorp.kotlinjdsl.render.jpql.serializer.JpqlRenderSerializer +import com.linecorp.kotlinjdsl.render.jpql.serializer.JpqlSerializer +import com.linecorp.kotlinjdsl.render.jpql.writer.JpqlWriter +import kotlin.reflect.KClass + +@Internal +class JpqlCurrentDateSerializer : JpqlSerializer { + override fun handledType(): KClass { + return JpqlCurrent.CurrentDate::class + } + + override fun serialize(part: JpqlCurrent.CurrentDate, writer: JpqlWriter, context: RenderContext) { + val delegate = context.getValue(JpqlRenderSerializer) + + writer.write("CURRENT_DATE") + + writer.writeParentheses { + delegate.serialize(part, writer, context) + } + } +} diff --git a/render/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlCurrentTimeSerializer.kt b/render/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlCurrentTimeSerializer.kt new file mode 100644 index 000000000..5956f77fc --- /dev/null +++ b/render/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlCurrentTimeSerializer.kt @@ -0,0 +1,26 @@ +package com.linecorp.kotlinjdsl.render.jpql.serializer.impl + +import com.linecorp.kotlinjdsl.Internal +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlCurrent +import com.linecorp.kotlinjdsl.render.RenderContext +import com.linecorp.kotlinjdsl.render.jpql.serializer.JpqlRenderSerializer +import com.linecorp.kotlinjdsl.render.jpql.serializer.JpqlSerializer +import com.linecorp.kotlinjdsl.render.jpql.writer.JpqlWriter +import kotlin.reflect.KClass + +@Internal +class JpqlCurrentTimeSerializer : JpqlSerializer { + override fun handledType(): KClass { + return JpqlCurrent.CurrentTime::class + } + + override fun serialize(part: JpqlCurrent.CurrentTime, writer: JpqlWriter, context: RenderContext) { + val delegate = context.getValue(JpqlRenderSerializer) + + writer.write("CURRENT_TIME") + + writer.writeParentheses { + delegate.serialize(part, writer, context) + } + } +} diff --git a/render/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlCurrentDateSerializerTest.kt b/render/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlCurrentDateSerializerTest.kt new file mode 100644 index 000000000..7226ebd7c --- /dev/null +++ b/render/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlCurrentDateSerializerTest.kt @@ -0,0 +1,52 @@ +package com.linecorp.kotlinjdsl.render.jpql.serializer.impl + +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expressions +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expressions.currentDate +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlCurrent +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.WithAssertions +import org.junit.jupiter.api.Test + +@JpqlSerializerTest +class JpqlCurrentDateSerializerTest : WithAssertions { + + private val sut = JpqlCurrentDateSerializer() + + @MockK + private lateinit var writer: JpqlWriter + + @MockK + private lateinit var serializer: JpqlRenderSerializer + + private val expression = currentDate() + + @Test + fun handledType() { // when + val actual = sut.handledType() + + // then + assertThat(actual).isEqualTo(JpqlCurrent.CurrentDate::class) + } + + @Test + fun serialize() { + // given + val part = Expressions.currentDate() + val context = TestRenderContext(serializer) + + // when + sut.serialize(part as JpqlCurrent.CurrentDate, writer, context) + + // then + verifySequence { + writer.write("CURRENT_DATE") + writer.writeParentheses(any()) + serializer.serialize(expression, writer, context) + } + } +} diff --git a/render/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlCurrentTimeSerializerTest.kt b/render/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlCurrentTimeSerializerTest.kt new file mode 100644 index 000000000..f88cc0079 --- /dev/null +++ b/render/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/render/jpql/serializer/impl/JpqlCurrentTimeSerializerTest.kt @@ -0,0 +1,52 @@ +package com.linecorp.kotlinjdsl.render.jpql.serializer.impl + +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expressions +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expressions.currentTime +import com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlCurrent +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.WithAssertions +import org.junit.jupiter.api.Test + +@JpqlSerializerTest +class JpqlCurrentTimeSerializerTest : WithAssertions { + + private val sut = JpqlCurrentTimeSerializer() + + @MockK + private lateinit var writer: JpqlWriter + + @MockK + private lateinit var serializer: JpqlRenderSerializer + + private val expression = currentTime() + + @Test + fun handledType() { // when + val actual = sut.handledType() + + // then + assertThat(actual).isEqualTo(JpqlCurrent.CurrentTime::class) + } + + @Test + fun serialize() { + // given + val part = Expressions.currentTime() + val context = TestRenderContext(serializer) + + // when + sut.serialize(part as JpqlCurrent.CurrentTime, writer, context) + + // then + verifySequence { + writer.write("CURRENT_TIME") + writer.writeParentheses(any()) + serializer.serialize(expression, writer, context) + } + } +} From c963cc76ffc42cd6a012f3b8c865b5bd56c48b93 Mon Sep 17 00:00:00 2001 From: meengi Date: Sat, 3 Feb 2024 02:11:44 +0900 Subject: [PATCH 061/169] docs: add currentDate, currentTime function description --- docs/en/jpql-with-kotlin-jdsl/expressions.md | 4 ++-- docs/ko/jpql-with-kotlin-jdsl/expressions.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/en/jpql-with-kotlin-jdsl/expressions.md b/docs/en/jpql-with-kotlin-jdsl/expressions.md index ec118d430..9a5fd976f 100644 --- a/docs/en/jpql-with-kotlin-jdsl/expressions.md +++ b/docs/en/jpql-with-kotlin-jdsl/expressions.md @@ -223,8 +223,8 @@ Kotlin JDSL provides a series of functions to support built-in functions in JPA. | Function | DSL function | |--------------------|--------------| -| CURRENT\_DATE | not yet | -| CURRENT\_TIME | not yet | +| CURRENT\_DATE | support | +| CURRENT\_TIME | support | | CURRENT\_TIMESTAMP | not yet | | LOCAL DATE | not yet | | LOCAL TIME | not yet | diff --git a/docs/ko/jpql-with-kotlin-jdsl/expressions.md b/docs/ko/jpql-with-kotlin-jdsl/expressions.md index e77eadfec..05958c291 100644 --- a/docs/ko/jpql-with-kotlin-jdsl/expressions.md +++ b/docs/ko/jpql-with-kotlin-jdsl/expressions.md @@ -221,8 +221,8 @@ Kotlin JDSL은 JPA에서 제공하는 여러 함수들을 지원하기 위함 | Function | DSL function | |--------------------|--------------| -| CURRENT\_DATE | not yet | -| CURRENT\_TIME | not yet | +| CURRENT\_DATE | support | +| CURRENT\_TIME | support | | CURRENT\_TIMESTAMP | not yet | | LOCAL DATE | not yet | | LOCAL TIME | not yet | From 3ff64490c05500bed4e24eb97e5d8be971adbe02 Mon Sep 17 00:00:00 2001 From: "jonghyon.s" Date: Mon, 5 Feb 2024 09:54:32 +0900 Subject: [PATCH 062/169] chore: hibernate-core v6.4.3 --- libs.example.versions.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs.example.versions.toml b/libs.example.versions.toml index b84f250b5..406c3230e 100644 --- a/libs.example.versions.toml +++ b/libs.example.versions.toml @@ -28,7 +28,7 @@ spring-batch4-test = { module = "org.springframework.batch:spring-batch-test", v # hibernate hibernate5-core = { module = "org.hibernate:hibernate-core", version = "5.6.15.Final" } -hibernate6-core = { module = "org.hibernate:hibernate-core", version = "6.4.2.Final" } +hibernate6-core = { module = "org.hibernate:hibernate-core", version = "6.4.3.Final" } # hibernate-reactive hibernate-reactive1-core = { module = "org.hibernate.reactive:hibernate-reactive-core", version = "1.1.9.Final" } From 8e2574d0715fdfec706d1ecf8b0560ffeeb6f440 Mon Sep 17 00:00:00 2001 From: meengi Date: Mon, 5 Feb 2024 22:00:17 +0900 Subject: [PATCH 063/169] fix: JpqlCurrent date,time separation and code clean up --- .../com/linecorp/kotlinjdsl/dsl/jpql/Jpql.kt | 12 +++++------ .../dsl/jpql/expression/CurrentDateDslTest.kt | 21 +++---------------- .../dsl/jpql/expression/CurrentTimeDslTest.kt | 21 +++---------------- .../querymodel/jpql/expression/Expressions.kt | 15 ++++++------- .../jpql/expression/impl/JpqlCurrent.kt | 17 --------------- .../jpql/expression/impl/JpqlCurrentDate.kt | 6 ++++++ .../jpql/expression/impl/JpqlCurrentTime.kt | 6 ++++++ .../jpql/expression/ExpressionsTest.kt | 7 ++++--- .../impl/JpqlCurrentDateSerializer.kt | 17 +++++---------- .../impl/JpqlCurrentTimeSerializer.kt | 17 +++++---------- .../impl/JpqlCurrentDateSerializerTest.kt | 14 ++++++------- .../impl/JpqlCurrentTimeSerializerTest.kt | 14 ++++++------- 12 files changed, 58 insertions(+), 109 deletions(-) delete mode 100644 query-model/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/expression/impl/JpqlCurrent.kt create mode 100644 query-model/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/expression/impl/JpqlCurrentDate.kt create mode 100644 query-model/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/expression/impl/JpqlCurrentTime.kt 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 19313d70d..e3d09dca6 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,8 +44,8 @@ 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 java.time.LocalTime +import java.sql.Date +import java.sql.Time import kotlin.internal.Exact import kotlin.internal.LowPriorityInOverloadResolution import kotlin.reflect.KClass @@ -489,22 +489,22 @@ open class Jpql : JpqlDsl { } /** - * Creates an expression that represents the current date. + * Creates an expression that represents the current date. * * This is the same as ```CURRENT_DATE```. */ @SinceJdsl("3.4.0") - fun currentDate(): Expression { + fun currentDate(): Expression { return Expressions.currentDate() } /** - * Creates an expression that represents the current time. + * Creates an expression that represents the current time. * * This is the same as ```CURRENT_TIME```. */ @SinceJdsl("3.4.0") - fun currentTime(): Expression { + fun currentTime(): Expression