From 7a1afca97f06678050438c7538c32094b69022e9 Mon Sep 17 00:00:00 2001 From: "jonghyon.s" Date: Wed, 11 Oct 2023 08:53:05 +0900 Subject: [PATCH] feat: deprecate return type in select functions --- .../com/linecorp/kotlinjdsl/dsl/jpql/Jpql.kt | 48 +++++++- .../dsl/jpql/select/SelectDslTest.kt | 114 ------------------ 2 files changed, 44 insertions(+), 118 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 0eaf15d5b..cc13dd2d2 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 @@ -2485,7 +2485,17 @@ open class Jpql : JpqlDsl { /** * Creates a select clause in a select query. */ - @SinceJdsl("3.0.0") + @Deprecated( + """ + The KClass parameter makes it confusing whether to specify the return type as generic or KClass + in the select function signature. + Therefore, Kotlin JDSL will remove select functions that accept the KClass parameter + to specify the return type as generic only. + Since these will be removed in the 3.0.0 release, + please use select functions that specify the return type via generic. + """, + ReplaceWith("select(expr, *exprs)"), + ) fun select( returnType: KClass, expr: Expressionable<*>, @@ -2530,7 +2540,17 @@ open class Jpql : JpqlDsl { /** * Creates a select clause in a select query. */ - @SinceJdsl("3.0.0") + @Deprecated( + """ + The KClass parameter makes it confusing whether to specify the return type as generic or KClass + in the select function signature. + Therefore, Kotlin JDSL will remove select functions that accept the KClass parameter + to specify the return type as generic only. + Since these will be removed in the 3.0.0 release, + please use select functions that specify the return type via generic. + """, + ReplaceWith("selectDistinct(expr, *exprs)"), + ) fun selectDistinct( returnType: KClass, expr: Expressionable<*>, @@ -2566,7 +2586,17 @@ open class Jpql : JpqlDsl { /** * Creates a select clause with the DTO projection in a select query. */ - @SinceJdsl("3.0.0") + @Deprecated( + """ + The KClass parameter makes it confusing whether to specify the return type as generic or KClass + in the select function signature. + Therefore, Kotlin JDSL will remove select functions that accept the KClass parameter + to specify the return type as generic only. + Since these will be removed in the 3.0.0 release, + please use select functions that specify the return type via generic. + """, + ReplaceWith("selectNew(expr, *exprs)"), + ) fun selectNew( returnType: KClass, expr: Expressionable<*>, @@ -2607,7 +2637,17 @@ open class Jpql : JpqlDsl { /** * Creates a select clause with the DTO projection in a select query. */ - @SinceJdsl("3.0.0") + @Deprecated( + """ + The KClass parameter makes it confusing whether to specify the return type as generic or KClass + in the select function signature. + Therefore, Kotlin JDSL will remove select functions that accept the KClass parameter + to specify the return type as generic only. + Since these will be removed in the 3.0.0 release, + please use select functions that specify the return type via generic. + """, + ReplaceWith("selectDistinctNew(expr, *exprs)"), + ) fun selectDistinctNew( returnType: KClass, expr: Expressionable<*>, diff --git a/dsl/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/select/SelectDslTest.kt b/dsl/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/select/SelectDslTest.kt index 44f6734c8..4d0bba4d8 100644 --- a/dsl/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/select/SelectDslTest.kt +++ b/dsl/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/select/SelectDslTest.kt @@ -69,32 +69,6 @@ class SelectDslTest : WithAssertions { assertThat(actual).isEqualTo(expected) } - @Test - fun `select() with a class and expressions`() { - // when - val select = queryPart { - select( - View::class, - expression1, - expression2, - ).from( - entity1, - ) - }.toQuery() - - val actual: SelectQuery = select // for type check - - // then - val expected = SelectQueries.selectQuery( - returnType = View::class, - distinct = false, - select = listOf(expression1, expression2), - from = listOf(entity1), - ) - - assertThat(actual).isEqualTo(expected) - } - @Test fun `selectDistinct() with an expression`() { // when @@ -144,32 +118,6 @@ class SelectDslTest : WithAssertions { assertThat(actual).isEqualTo(expected) } - @Test - fun `selectDistinct() with a class and expressions`() { - // when - val select = queryPart { - selectDistinct( - View::class, - expression1, - expression2, - ).from( - entity1, - ) - }.toQuery() - - val actual: SelectQuery = select // for type check - - // then - val expected = SelectQueries.selectQuery( - returnType = View::class, - distinct = true, - select = listOf(expression1, expression2), - from = listOf(entity1), - ) - - assertThat(actual).isEqualTo(expected) - } - @Test fun `selectNew() with a generic type and expressions`() { // when @@ -200,37 +148,6 @@ class SelectDslTest : WithAssertions { assertThat(actual).isEqualTo(expected) } - @Test - fun `selectNew() with a class and expressions`() { - // when - val select = queryPart { - selectNew( - Dto::class, - expression1, - expression2, - ).from( - entity1, - ) - }.toQuery() - - val actual: SelectQuery = select // for type check - - // then - val expected = SelectQueries.selectQuery( - returnType = Dto::class, - distinct = false, - select = listOf( - Expressions.new( - type = Dto::class, - args = listOf(expression1, expression2), - ), - ), - from = listOf(entity1), - ) - - assertThat(actual).isEqualTo(expected) - } - @Test fun `selectDistinctNew() with a generic type and expressions`() { // when @@ -260,35 +177,4 @@ class SelectDslTest : WithAssertions { assertThat(actual).isEqualTo(expected) } - - @Test - fun `selectDistinctNew() with a class and expressions`() { - // when - val select = queryPart { - selectDistinctNew( - Dto::class, - expression1, - expression2, - ).from( - entity1, - ) - }.toQuery() - - val actual: SelectQuery = select // for type check - - // then - val expected = SelectQueries.selectQuery( - returnType = Dto::class, - distinct = true, - select = listOf( - Expressions.new( - type = Dto::class, - args = listOf(expression1, expression2), - ), - ), - from = listOf(entity1), - ) - - assertThat(actual).isEqualTo(expected) - } }