From 341ddfc2ec71db2714919d02a78fe80f242a07fa Mon Sep 17 00:00:00 2001 From: Jake Son Date: Fri, 10 Nov 2023 09:00:02 +0900 Subject: [PATCH 1/9] feat(query-model): add path methods for getter --- .../kotlinjdsl/querymodel/jpql/path/Paths.kt | 27 ++++++ .../querymodel/jpql/path/PathsTest.kt | 84 +++++++++++++++++++ .../jpql/entity/employee/Employee.kt | 4 +- .../kotlinjdsl/property/PropertyUtils.kt | 6 ++ 4 files changed, 120 insertions(+), 1 deletion(-) diff --git a/query-model/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/path/Paths.kt b/query-model/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/path/Paths.kt index b97a13840..90d5d6b81 100644 --- a/query-model/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/path/Paths.kt +++ b/query-model/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/path/Paths.kt @@ -9,6 +9,7 @@ import com.linecorp.kotlinjdsl.querymodel.jpql.path.impl.JpqlPathProperty import com.linecorp.kotlinjdsl.querymodel.jpql.path.impl.JpqlPathTreat import kotlin.internal.Exact import kotlin.reflect.KClass +import kotlin.reflect.KFunction1 import kotlin.reflect.KProperty1 /** @@ -26,6 +27,16 @@ object Paths { return JpqlEntityProperty(Entities.entity(owner), property) } + /** + * Creates a path with the property. + */ + @SinceJdsl("3.1.0") + fun path(getter: KFunction1): Path { + val owner = PropertyUtils.getOwner(getter) + + return JpqlEntityProperty(Entities.entity(owner), getter) + } + /** * Creates a path with the entity and property. */ @@ -34,6 +45,14 @@ object Paths { return JpqlEntityProperty(entity, property) } + /** + * Creates a path with the entity and property. + */ + @SinceJdsl("3.1.0") + fun path(entity: Entity, getter: KFunction1): Path { + return JpqlEntityProperty(entity, getter) + } + /** * Creates a path with the path and property. */ @@ -42,6 +61,14 @@ object Paths { return JpqlPathProperty(path, property) } + /** + * Creates a path with the path and property. + */ + @SinceJdsl("3.1.0") + fun path(path: Path, getter: KFunction1): Path { + return JpqlPathProperty(path, getter) + } + /** * Creates a path with downcasting. */ diff --git a/query-model/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/path/PathsTest.kt b/query-model/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/path/PathsTest.kt index d68e002bc..d0cd8bffa 100644 --- a/query-model/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/path/PathsTest.kt +++ b/query-model/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/path/PathsTest.kt @@ -33,6 +33,22 @@ class PathsTest : WithAssertions { assertThat(actual).isEqualTo(expected) } + @Test + fun pathGetter() { + // when + val actual = Paths.path( + FullTimeEmployee::getUpperName, + ) + + // then + val expected = JpqlEntityProperty( + entity = Entities.entity(FullTimeEmployee::class), + property = FullTimeEmployee::getUpperName, + ) + + assertThat(actual).isEqualTo(expected) + } + @Test fun `path() with an entity`() { // when @@ -50,6 +66,23 @@ class PathsTest : WithAssertions { assertThat(actual).isEqualTo(expected) } + @Test + fun `path() with an entity and a getter`() { + // when + val actual = Paths.path( + entity1, + Employee::getUpperName, + ) + + // then + val expected = JpqlEntityProperty( + entity = entity1, + property = Employee::getUpperName, + ) + + assertThat(actual).isEqualTo(expected) + } + @Test fun `path() with a path`() { // when @@ -67,6 +100,23 @@ class PathsTest : WithAssertions { assertThat(actual).isEqualTo(expected) } + @Test + fun `path() with a path and a getter`() { + // when + val actual = Paths.path( + path1, + getter = Employee::getUpperName, + ) + + // then + val expected = JpqlPathProperty( + path = path1, + property = Employee::getUpperName, + ) + + assertThat(actual).isEqualTo(expected) + } + @Test fun `path() with an entity and a property of super class`() { // when @@ -84,6 +134,23 @@ class PathsTest : WithAssertions { assertThat(actual).isEqualTo(expected) } + @Test + fun `path() with an entity and a getter of super class`() { + // when + val actual = Paths.path( + entity2, + Employee::getUpperName, + ) + + // then + val expected = JpqlEntityProperty( + entity = entity2, + property = Employee::getUpperName, + ) + + assertThat(actual).isEqualTo(expected) + } + @Test fun `path() with a path and a property of super class`() { // when @@ -101,6 +168,23 @@ class PathsTest : WithAssertions { assertThat(actual).isEqualTo(expected) } + @Test + fun `path() with a path and a getter of super class`() { + // when + val actual = Paths.path( + path2, + getter = Employee::getUpperName, + ) + + // then + val expected = JpqlPathProperty( + path = path2, + property = Employee::getUpperName, + ) + + assertThat(actual).isEqualTo(expected) + } + @Test fun treat() { // when diff --git a/query-model/jpql/src/testFixtures/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/entity/employee/Employee.kt b/query-model/jpql/src/testFixtures/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/entity/employee/Employee.kt index 534c41239..12100b5c7 100644 --- a/query-model/jpql/src/testFixtures/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/entity/employee/Employee.kt +++ b/query-model/jpql/src/testFixtures/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/entity/employee/Employee.kt @@ -9,4 +9,6 @@ abstract class Employee( val phone: String, val address: EmployeeAddress, val departments: MutableSet, -) +) { + fun getUpperName(): String = name.uppercase() +} diff --git a/src/main/kotlin/com/linecorp/kotlinjdsl/property/PropertyUtils.kt b/src/main/kotlin/com/linecorp/kotlinjdsl/property/PropertyUtils.kt index ccbe84052..461adee71 100644 --- a/src/main/kotlin/com/linecorp/kotlinjdsl/property/PropertyUtils.kt +++ b/src/main/kotlin/com/linecorp/kotlinjdsl/property/PropertyUtils.kt @@ -2,6 +2,7 @@ package com.linecorp.kotlinjdsl.property import kotlin.jvm.internal.CallableReference import kotlin.reflect.KClass +import kotlin.reflect.KFunction1 import kotlin.reflect.KProperty1 object PropertyUtils { @@ -9,4 +10,9 @@ object PropertyUtils { @Suppress("UNCHECKED_CAST") return (property as CallableReference).owner as KClass } + + fun getOwner(property: KFunction1): KClass { + @Suppress("UNCHECKED_CAST") + return (property as CallableReference).owner as KClass + } } From e5e3a001d8c6cf03bfca5a34e31a3f82de381d97 Mon Sep 17 00:00:00 2001 From: Jake Son Date: Sun, 12 Nov 2023 09:08:29 +0900 Subject: [PATCH 2/9] feat(dsl): add path method for KFunction1 --- .../com/linecorp/kotlinjdsl/dsl/jpql/Jpql.kt | 42 +++++ .../kotlinjdsl/dsl/jpql/path/PathDslTest.kt | 161 ++++++++++++++++++ .../dsl/jpql/entity/employee/Employee.kt | 4 +- .../jpql/entity/employee/FullTimeEmployee.kt | 4 +- 4 files changed, 209 insertions(+), 2 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 af755fd75..e680ff6f5 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 @@ -41,6 +41,7 @@ import java.math.BigDecimal import java.math.BigInteger import kotlin.internal.Exact import kotlin.reflect.KClass +import kotlin.reflect.KFunction1 import kotlin.reflect.KProperty1 /** @@ -194,6 +195,15 @@ open class Jpql : JpqlDsl { return Paths.path(property) } + /** + * Creates a path expression with the property. + * The path starts from the entity which is the owner of the property. + */ + @SinceJdsl("3.1.0") + fun path(getter: KFunction1): Path { + return Paths.path(getter) + } + /** * Creates a path expression with the entity and property. */ @@ -202,6 +212,14 @@ open class Jpql : JpqlDsl { return Paths.path(this.toEntity(), property) } + /** + * Creates a path expression with the entity and property. + */ + @SinceJdsl("3.1.0") + fun Entityable.path(getter: KFunction1): Path { + return Paths.path(this.toEntity(), getter) + } + /** * Creates a path expression with the path and property. */ @@ -210,6 +228,14 @@ open class Jpql : JpqlDsl { return Paths.path(this.toPath(), property) } + /** + * Creates a path expression with the path and property. + */ + @SinceJdsl("3.1.0") + fun Pathable.path(getter: KFunction1): Path { + return Paths.path(this.toPath(), getter) + } + /** * Creates a path expression with the entity and property. */ @@ -218,6 +244,14 @@ open class Jpql : JpqlDsl { return Paths.path(this.toEntity(), property) } + /** + * Creates a path expression with the entity and property. + */ + @SinceJdsl("3.1.0") + operator fun Entityable.invoke(getter: KFunction1): Path { + return Paths.path(this.toEntity(), getter) + } + /** * Creates a path expression with the path and property. */ @@ -226,6 +260,14 @@ open class Jpql : JpqlDsl { return Paths.path(this.toPath(), property) } + /** + * Creates a path expression with the path and property. + */ + @SinceJdsl("3.1.0") + operator fun Pathable.invoke(getter: KFunction1): Path { + return Paths.path(this.toPath(), getter) + } + /** * Creates an aliased expression with the alias expression. * The aliased expression can be referenced by the alias expression. diff --git a/dsl/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/path/PathDslTest.kt b/dsl/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/path/PathDslTest.kt index bb9d6e9e7..c0c315408 100644 --- a/dsl/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/path/PathDslTest.kt +++ b/dsl/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/path/PathDslTest.kt @@ -33,6 +33,23 @@ class PathDslTest : WithAssertions { assertThat(actual).isEqualTo(excepted) } + @Test + fun `path() with a getter`() { + // when + val path = queryPart { + path(FullTimeEmployee::getUpperName) + } + + val actual: Path = path // for type check + + // then + val excepted = Paths.path( + FullTimeEmployee::getUpperName, + ) + + assertThat(actual).isEqualTo(excepted) + } + @Test fun `path() with a entity and a property`() { // when @@ -51,6 +68,24 @@ class PathDslTest : WithAssertions { assertThat(actual).isEqualTo(excepted) } + @Test + fun `path() with a entity and a getter`() { + // when + val path = queryPart { + entity1.path(FullTimeEmployee::getUpperName) + } + + val actual: Path = path // for type check + + // then + val excepted = Paths.path( + entity1, + FullTimeEmployee::getUpperName, + ) + + assertThat(actual).isEqualTo(excepted) + } + @Test fun `path() with a path and a property`() { // when @@ -69,6 +104,24 @@ class PathDslTest : WithAssertions { assertThat(actual).isEqualTo(excepted) } + @Test + fun `path() with a path and a getter`() { + // when + val path = queryPart { + path1.path(FullTimeEmployee::getUpperName) + } + + val actual: Path = path // for type check + + // then + val excepted = Paths.path( + path1, + FullTimeEmployee::getUpperName, + ) + + assertThat(actual).isEqualTo(excepted) + } + @Test fun `path() with a entity and a property of super class`() { // when @@ -87,6 +140,24 @@ class PathDslTest : WithAssertions { assertThat(actual).isEqualTo(excepted) } + @Test + fun `path() with a entity and a getter of super class`() { + // when + val path = queryPart { + entity1.path(Employee::getLowerName) + } + + val actual: Path = path // for type check + + // then + val excepted = Paths.path( + entity1, + Employee::getLowerName, + ) + + assertThat(actual).isEqualTo(excepted) + } + @Test fun `path() with a path and a property of super class`() { // when @@ -105,6 +176,24 @@ class PathDslTest : WithAssertions { assertThat(actual).isEqualTo(excepted) } + @Test + fun `path() with a path and a getter of super class`() { + // when + val path = queryPart { + path1.path(Employee::getLowerName) + } + + val actual: Path = path // for type check + + // then + val excepted = Paths.path( + path1, + Employee::getLowerName, + ) + + assertThat(actual).isEqualTo(excepted) + } + @Test fun `invoke() with a entity and a property`() { // when @@ -123,6 +212,24 @@ class PathDslTest : WithAssertions { assertThat(actual).isEqualTo(excepted) } + @Test + fun `invoke() with a entity and a getter`() { + // when + val path = queryPart { + entity1(FullTimeEmployee::getUpperName) + } + + val actual: Path = path // for type check + + // then + val excepted = Paths.path( + entity1, + FullTimeEmployee::getUpperName, + ) + + assertThat(actual).isEqualTo(excepted) + } + @Test fun `invoke() with a path and a property`() { // when @@ -141,6 +248,24 @@ class PathDslTest : WithAssertions { assertThat(actual).isEqualTo(excepted) } + @Test + fun `invoke() with a path and a getter`() { + // when + val path = queryPart { + path1(FullTimeEmployee::getUpperName) + } + + val actual: Path = path // for type check + + // then + val excepted = Paths.path( + path1, + FullTimeEmployee::getUpperName, + ) + + assertThat(actual).isEqualTo(excepted) + } + @Test fun `invoke() with a entity and a property of super class`() { // when @@ -159,6 +284,24 @@ class PathDslTest : WithAssertions { assertThat(actual).isEqualTo(excepted) } + @Test + fun `invoke() with a entity and a getter of super class`() { + // when + val path = queryPart { + entity1(Employee::getLowerName) + } + + val actual: Path = path // for type check + + // then + val excepted = Paths.path( + entity1, + Employee::getLowerName, + ) + + assertThat(actual).isEqualTo(excepted) + } + @Test fun `invoke() with a path and a property of super class`() { // when @@ -176,4 +319,22 @@ class PathDslTest : WithAssertions { assertThat(actual).isEqualTo(excepted) } + + @Test + fun `invoke() with a path and a getter of super class`() { + // when + val path = queryPart { + path1(Employee::getLowerName) + } + + val actual: Path = path // for type check + + // then + val excepted = Paths.path( + path1, + Employee::getLowerName, + ) + + assertThat(actual).isEqualTo(excepted) + } } diff --git a/dsl/jpql/src/testFixtures/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/entity/employee/Employee.kt b/dsl/jpql/src/testFixtures/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/entity/employee/Employee.kt index 3d1c808c3..111e911f3 100644 --- a/dsl/jpql/src/testFixtures/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/entity/employee/Employee.kt +++ b/dsl/jpql/src/testFixtures/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/entity/employee/Employee.kt @@ -7,4 +7,6 @@ abstract class Employee( val phone: String, val address: EmployeeAddress, val departments: MutableSet, -) +) { + fun getLowerName(): String = name.lowercase() +} diff --git a/dsl/jpql/src/testFixtures/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/entity/employee/FullTimeEmployee.kt b/dsl/jpql/src/testFixtures/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/entity/employee/FullTimeEmployee.kt index 09bb8b9fc..abd1fde06 100644 --- a/dsl/jpql/src/testFixtures/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/entity/employee/FullTimeEmployee.kt +++ b/dsl/jpql/src/testFixtures/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/entity/employee/FullTimeEmployee.kt @@ -17,4 +17,6 @@ class FullTimeEmployee( phone = phone, address = address, departments = departments, -) +) { + fun getUpperName(): String = name.uppercase() +} From a8cd4637fcf3af8ab4ecbdb67caa1945579207f4 Mon Sep 17 00:00:00 2001 From: Jake Son Date: Sun, 12 Nov 2023 10:27:48 +0900 Subject: [PATCH 3/9] docs: path for java entity --- docs/en/jpql-with-kotlin-jdsl/paths.md | 69 ++++++++++++++++++++++++++ docs/ko/jpql-with-kotlin-jdsl/paths.md | 69 ++++++++++++++++++++++++++ 2 files changed, 138 insertions(+) diff --git a/docs/en/jpql-with-kotlin-jdsl/paths.md b/docs/en/jpql-with-kotlin-jdsl/paths.md index 8d1828479..b40c1c439 100644 --- a/docs/en/jpql-with-kotlin-jdsl/paths.md +++ b/docs/en/jpql-with-kotlin-jdsl/paths.md @@ -13,6 +13,75 @@ entity(Book::class, "b").path(Book::isbn).path(Isbn::value) entity(Book::class, "b")(Book::isbn)(Isbn::value) ``` +## Java entity + +`path()` and `invoke()` take `KProperty1` or `KFuction1` as an argument. +`KFunction1` is useful when you use Java entity with private property and public getter. + +```java +@Entity +public class Book { + @Id + private Long id; + + private String title; + + public String getTitle() { + return title; + } +} +``` + +```kotlin +// compile error +path(Book::title) + +// Book.title +path(Book::getTitle) +``` + +Kotlin JDSL follows the following rules to infer property name from getter name. + +- If the name starts with `is`, use the name as it is. +- If the name starts with `get`, remove `get` and change the first letter to lowercase. +- Otherwise, use the name as it is. + +```kotlin +// Book.isAvailable +path(Book::isAvailable) + +// Book.available +path(Book::getAvailable) +``` + +If you want to use your own rule instead of the above rules, you need to implement `JpqlPropertyIntrospector` and provide it to `RenderContext`. + +```kotlin +class MyIntrospector : JpqlPropertyIntrospector() { + override fun introspect(property: KCallable<*>): JpqlPropertyDescription? { + if (property is KFunction1<*, *>) { + // resolve a name with your own rule + val name = ... + return MyProperty(name) + } + + return null + } + + private data class MyProperty( + override val name: String, + ) : JpqlPropertyDescription +} + +val myModule = object : JpqlRenderModule { + override fun setupModule(context: JpqlRenderModule.SetupContext) { + context.prependIntrospector(MyIntrospector()) + } +} + +val myContext = JpqlRenderContext().registerModule(myModule) +``` + ## Expression `Path` can be used as [`Expression`](expressions.md), such as in a [select clause](statements.md#select-clause) or [predicate](predicates.md). diff --git a/docs/ko/jpql-with-kotlin-jdsl/paths.md b/docs/ko/jpql-with-kotlin-jdsl/paths.md index 53d651403..42eeb47fb 100644 --- a/docs/ko/jpql-with-kotlin-jdsl/paths.md +++ b/docs/ko/jpql-with-kotlin-jdsl/paths.md @@ -13,6 +13,75 @@ entity(Book::class, "b").path(Book::isbn).path(Isbn::value) entity(Book::class, "b")(Book::isbn)(Isbn::value) ``` +## Java entity + +`path()` 와 `invoke()`는 `KProperty1` 또는 `KFuction1`를 인자로 받습니다. +`KFunction1`의 경우, getter만 public인 Java로 선언한 entity를 사용할 때 유용합니다. + +```java +@Entity +public class Book { + @Id + private Long id; + + private String title; + + public String getTitle() { + return title; + } +} +``` + +```kotlin +// compile error +path(Book::title) + +// Book.title +path(Book::getTitle) +``` + +Kotlin JDSL은 getter 이름에서 프로퍼티 이름을 추론하기 위해 다음 규칙을 따릅니다. + +- `is`로 시작하는 경우 이름 그대로 사용합니다. +- `get`으로 시작하는 경우 `get`을 제거하고 이후 첫 글자를 소문자로 변경합니다. +- 그 외의 경우, 이름 그대로 사용합니다. + +```kotlin +// Book.isAvailable +path(Book::isAvailable) + +// Book.available +path(Book::getAvailable) +``` + +위 규칙 대신 나만의 규칙을 사용하고 싶다면, `JpqlPropertyIntrospector`를 구현하고 이를 이를 `RenderContext`에 추가해야 합니다. + +```kotlin +class MyIntrospector : JpqlPropertyIntrospector() { + override fun introspect(property: KCallable<*>): JpqlPropertyDescription? { + if (property is KFunction1<*, *>) { + // 나만의 규칙으로 이름을 추론합니다 + val name = ... + return MyProperty(name) + } + + return null + } + + private data class MyProperty( + override val name: String, + ) : JpqlPropertyDescription +} + +val myModule = object : JpqlRenderModule { + override fun setupModule(context: JpqlRenderModule.SetupContext) { + context.prependIntrospector(MyIntrospector()) + } +} + +val myContext = JpqlRenderContext().registerModule(myModule) +``` + ## Expression `Path`는 [select clause](statements.md#select-clause) 나 [predicate](predicates.md) 등에서 [`Expression`](expressions.md)으로 사용될 수 있습니다. From d0d35c44bee6c42da1a7796f8c7fd580982a56c1 Mon Sep 17 00:00:00 2001 From: Jake Son Date: Sun, 12 Nov 2023 18:10:05 +0900 Subject: [PATCH 4/9] test: rename methods more meaningful --- .../kotlinjdsl/dsl/jpql/path/PathDslTest.kt | 47 ++++++++++--------- .../dsl/jpql/entity/employee/Employee.kt | 2 +- .../jpql/entity/employee/FullTimeEmployee.kt | 2 +- .../querymodel/jpql/path/PathsTest.kt | 24 +++++----- .../jpql/entity/employee/Employee.kt | 2 +- 5 files changed, 39 insertions(+), 38 deletions(-) diff --git a/dsl/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/path/PathDslTest.kt b/dsl/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/path/PathDslTest.kt index c0c315408..4f4181793 100644 --- a/dsl/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/path/PathDslTest.kt +++ b/dsl/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/path/PathDslTest.kt @@ -10,6 +10,7 @@ import com.linecorp.kotlinjdsl.querymodel.jpql.path.Path 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 PathDslTest : WithAssertions { private val entity1 = Entities.entity(FullTimeEmployee::class) @@ -37,14 +38,14 @@ class PathDslTest : WithAssertions { fun `path() with a getter`() { // when val path = queryPart { - path(FullTimeEmployee::getUpperName) + path(FullTimeEmployee::getMonthlySalary) } - val actual: Path = path // for type check + val actual: Path = path // for type check // then val excepted = Paths.path( - FullTimeEmployee::getUpperName, + FullTimeEmployee::getMonthlySalary, ) assertThat(actual).isEqualTo(excepted) @@ -72,15 +73,15 @@ class PathDslTest : WithAssertions { fun `path() with a entity and a getter`() { // when val path = queryPart { - entity1.path(FullTimeEmployee::getUpperName) + entity1.path(FullTimeEmployee::getMonthlySalary) } - val actual: Path = path // for type check + val actual: Path = path // for type check // then val excepted = Paths.path( entity1, - FullTimeEmployee::getUpperName, + FullTimeEmployee::getMonthlySalary, ) assertThat(actual).isEqualTo(excepted) @@ -108,15 +109,15 @@ class PathDslTest : WithAssertions { fun `path() with a path and a getter`() { // when val path = queryPart { - path1.path(FullTimeEmployee::getUpperName) + path1.path(FullTimeEmployee::getMonthlySalary) } - val actual: Path = path // for type check + val actual: Path = path // for type check // then val excepted = Paths.path( path1, - FullTimeEmployee::getUpperName, + FullTimeEmployee::getMonthlySalary, ) assertThat(actual).isEqualTo(excepted) @@ -144,7 +145,7 @@ class PathDslTest : WithAssertions { fun `path() with a entity and a getter of super class`() { // when val path = queryPart { - entity1.path(Employee::getLowerName) + entity1.path(Employee::getDisplayName) } val actual: Path = path // for type check @@ -152,7 +153,7 @@ class PathDslTest : WithAssertions { // then val excepted = Paths.path( entity1, - Employee::getLowerName, + Employee::getDisplayName, ) assertThat(actual).isEqualTo(excepted) @@ -180,7 +181,7 @@ class PathDslTest : WithAssertions { fun `path() with a path and a getter of super class`() { // when val path = queryPart { - path1.path(Employee::getLowerName) + path1.path(Employee::getDisplayName) } val actual: Path = path // for type check @@ -188,7 +189,7 @@ class PathDslTest : WithAssertions { // then val excepted = Paths.path( path1, - Employee::getLowerName, + Employee::getDisplayName, ) assertThat(actual).isEqualTo(excepted) @@ -216,15 +217,15 @@ class PathDslTest : WithAssertions { fun `invoke() with a entity and a getter`() { // when val path = queryPart { - entity1(FullTimeEmployee::getUpperName) + entity1(FullTimeEmployee::getMonthlySalary) } - val actual: Path = path // for type check + val actual: Path = path // for type check // then val excepted = Paths.path( entity1, - FullTimeEmployee::getUpperName, + FullTimeEmployee::getMonthlySalary, ) assertThat(actual).isEqualTo(excepted) @@ -252,15 +253,15 @@ class PathDslTest : WithAssertions { fun `invoke() with a path and a getter`() { // when val path = queryPart { - path1(FullTimeEmployee::getUpperName) + path1(FullTimeEmployee::getMonthlySalary) } - val actual: Path = path // for type check + val actual: Path = path // for type check // then val excepted = Paths.path( path1, - FullTimeEmployee::getUpperName, + FullTimeEmployee::getMonthlySalary, ) assertThat(actual).isEqualTo(excepted) @@ -288,7 +289,7 @@ class PathDslTest : WithAssertions { fun `invoke() with a entity and a getter of super class`() { // when val path = queryPart { - entity1(Employee::getLowerName) + entity1(Employee::getDisplayName) } val actual: Path = path // for type check @@ -296,7 +297,7 @@ class PathDslTest : WithAssertions { // then val excepted = Paths.path( entity1, - Employee::getLowerName, + Employee::getDisplayName, ) assertThat(actual).isEqualTo(excepted) @@ -324,7 +325,7 @@ class PathDslTest : WithAssertions { fun `invoke() with a path and a getter of super class`() { // when val path = queryPart { - path1(Employee::getLowerName) + path1(Employee::getDisplayName) } val actual: Path = path // for type check @@ -332,7 +333,7 @@ class PathDslTest : WithAssertions { // then val excepted = Paths.path( path1, - Employee::getLowerName, + Employee::getDisplayName, ) assertThat(actual).isEqualTo(excepted) diff --git a/dsl/jpql/src/testFixtures/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/entity/employee/Employee.kt b/dsl/jpql/src/testFixtures/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/entity/employee/Employee.kt index 111e911f3..293ce31bb 100644 --- a/dsl/jpql/src/testFixtures/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/entity/employee/Employee.kt +++ b/dsl/jpql/src/testFixtures/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/entity/employee/Employee.kt @@ -8,5 +8,5 @@ abstract class Employee( val address: EmployeeAddress, val departments: MutableSet, ) { - fun getLowerName(): String = name.lowercase() + fun getDisplayName() = nickname ?: name } diff --git a/dsl/jpql/src/testFixtures/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/entity/employee/FullTimeEmployee.kt b/dsl/jpql/src/testFixtures/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/entity/employee/FullTimeEmployee.kt index abd1fde06..6eb177bb8 100644 --- a/dsl/jpql/src/testFixtures/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/entity/employee/FullTimeEmployee.kt +++ b/dsl/jpql/src/testFixtures/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/entity/employee/FullTimeEmployee.kt @@ -18,5 +18,5 @@ class FullTimeEmployee( address = address, departments = departments, ) { - fun getUpperName(): String = name.uppercase() + fun getMonthlySalary() = annualSalary.div(BigDecimal.valueOf(12)) } diff --git a/query-model/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/path/PathsTest.kt b/query-model/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/path/PathsTest.kt index d0cd8bffa..311041819 100644 --- a/query-model/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/path/PathsTest.kt +++ b/query-model/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/path/PathsTest.kt @@ -18,7 +18,7 @@ class PathsTest : WithAssertions { private val path2 = Paths.treat(Paths.path(EmployeeDepartment::employee), FullTimeEmployee::class) @Test - fun path() { + fun `path with a property`() { // when val actual = Paths.path( FullTimeEmployee::address, @@ -34,16 +34,16 @@ class PathsTest : WithAssertions { } @Test - fun pathGetter() { + fun `path with a getter`() { // when val actual = Paths.path( - FullTimeEmployee::getUpperName, + FullTimeEmployee::getDisplayName, ) // then val expected = JpqlEntityProperty( entity = Entities.entity(FullTimeEmployee::class), - property = FullTimeEmployee::getUpperName, + property = FullTimeEmployee::getDisplayName, ) assertThat(actual).isEqualTo(expected) @@ -71,13 +71,13 @@ class PathsTest : WithAssertions { // when val actual = Paths.path( entity1, - Employee::getUpperName, + Employee::getDisplayName, ) // then val expected = JpqlEntityProperty( entity = entity1, - property = Employee::getUpperName, + property = Employee::getDisplayName, ) assertThat(actual).isEqualTo(expected) @@ -105,13 +105,13 @@ class PathsTest : WithAssertions { // when val actual = Paths.path( path1, - getter = Employee::getUpperName, + getter = Employee::getDisplayName, ) // then val expected = JpqlPathProperty( path = path1, - property = Employee::getUpperName, + property = Employee::getDisplayName, ) assertThat(actual).isEqualTo(expected) @@ -139,13 +139,13 @@ class PathsTest : WithAssertions { // when val actual = Paths.path( entity2, - Employee::getUpperName, + Employee::getDisplayName, ) // then val expected = JpqlEntityProperty( entity = entity2, - property = Employee::getUpperName, + property = Employee::getDisplayName, ) assertThat(actual).isEqualTo(expected) @@ -173,13 +173,13 @@ class PathsTest : WithAssertions { // when val actual = Paths.path( path2, - getter = Employee::getUpperName, + getter = Employee::getDisplayName, ) // then val expected = JpqlPathProperty( path = path2, - property = Employee::getUpperName, + property = Employee::getDisplayName, ) assertThat(actual).isEqualTo(expected) diff --git a/query-model/jpql/src/testFixtures/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/entity/employee/Employee.kt b/query-model/jpql/src/testFixtures/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/entity/employee/Employee.kt index 12100b5c7..2eae684e0 100644 --- a/query-model/jpql/src/testFixtures/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/entity/employee/Employee.kt +++ b/query-model/jpql/src/testFixtures/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/entity/employee/Employee.kt @@ -10,5 +10,5 @@ abstract class Employee( val address: EmployeeAddress, val departments: MutableSet, ) { - fun getUpperName(): String = name.uppercase() + fun getDisplayName() = nickname ?: name } From 04cef12815409ec1476d225af685c864b53c03c7 Mon Sep 17 00:00:00 2001 From: Jake Son Date: Sun, 12 Nov 2023 18:22:53 +0900 Subject: [PATCH 5/9] docs: fix grammar --- docs/en/jpql-with-kotlin-jdsl/paths.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/en/jpql-with-kotlin-jdsl/paths.md b/docs/en/jpql-with-kotlin-jdsl/paths.md index b40c1c439..cd4661ba2 100644 --- a/docs/en/jpql-with-kotlin-jdsl/paths.md +++ b/docs/en/jpql-with-kotlin-jdsl/paths.md @@ -15,7 +15,7 @@ entity(Book::class, "b")(Book::isbn)(Isbn::value) ## Java entity -`path()` and `invoke()` take `KProperty1` or `KFuction1` as an argument. +`path()` and `invoke()` can take `KProperty1` or `KFuction1` as an argument. `KFunction1` is useful when you use Java entity with private property and public getter. ```java @@ -40,7 +40,7 @@ path(Book::title) path(Book::getTitle) ``` -Kotlin JDSL follows the following rules to infer property name from getter name. +Kotlin JDSL infers the property name from the getter with the following rules: - If the name starts with `is`, use the name as it is. - If the name starts with `get`, remove `get` and change the first letter to lowercase. @@ -54,7 +54,7 @@ path(Book::isAvailable) path(Book::getAvailable) ``` -If you want to use your own rule instead of the above rules, you need to implement `JpqlPropertyIntrospector` and provide it to `RenderContext`. +If you want to use your own rule instead of the above rules, you can implement `JpqlPropertyIntrospector` and provide it to `RenderContext`. ```kotlin class MyIntrospector : JpqlPropertyIntrospector() { From 581d5d3b531c2f1487c01a34b2301e3296508216 Mon Sep 17 00:00:00 2001 From: Jake Son Date: Sun, 12 Nov 2023 18:42:03 +0900 Subject: [PATCH 6/9] feat: add introspectors to spring auto configuration --- .../autoconfigure/KotlinJdslAutoConfiguration.kt | 14 +++++++++++--- .../autoconfigure/KotlinJdslAutoConfiguration.kt | 14 +++++++++++--- .../autoconfigure/KotlinJdslAutoConfiguration.kt | 15 +++++++++++---- .../autoconfigure/KotlinJdslAutoConfiguration.kt | 15 +++++++++++---- 4 files changed, 44 insertions(+), 14 deletions(-) diff --git a/support/spring-batch-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/batch/javax/autoconfigure/KotlinJdslAutoConfiguration.kt b/support/spring-batch-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/batch/javax/autoconfigure/KotlinJdslAutoConfiguration.kt index 860dc230d..034f5ecb0 100644 --- a/support/spring-batch-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/batch/javax/autoconfigure/KotlinJdslAutoConfiguration.kt +++ b/support/spring-batch-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/batch/javax/autoconfigure/KotlinJdslAutoConfiguration.kt @@ -3,6 +3,7 @@ package com.linecorp.kotlinjdsl.support.spring.batch.javax.autoconfigure import com.linecorp.kotlinjdsl.render.RenderContext import com.linecorp.kotlinjdsl.render.jpql.JpqlRenderContext import com.linecorp.kotlinjdsl.render.jpql.JpqlRenderModule +import com.linecorp.kotlinjdsl.render.jpql.introspector.JpqlIntrospector import com.linecorp.kotlinjdsl.render.jpql.serializer.JpqlSerializer import com.linecorp.kotlinjdsl.support.spring.batch.javax.item.database.orm.KotlinJdslQueryProviderFactory import org.springframework.boot.autoconfigure.AutoConfiguration @@ -15,14 +16,21 @@ import org.springframework.context.annotation.Bean open class KotlinJdslAutoConfiguration { @Bean @ConditionalOnMissingBean - open fun jpqlRenderContext(serializers: List>): JpqlRenderContext { - val userDefinedSerializers = object : JpqlRenderModule { + open fun jpqlRenderContext( + serializers: List>, + introspectors: List, + ): JpqlRenderContext { + val userDefinedModule = object : JpqlRenderModule { override fun setupModule(context: JpqlRenderModule.SetupContext) { context.addAllSerializer(serializers.reversed()) + + introspectors.reversed().forEach { + context.prependIntrospector(it) + } } } - return JpqlRenderContext().registerModules(userDefinedSerializers) + return JpqlRenderContext().registerModules(userDefinedModule) } @Bean diff --git a/support/spring-batch/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/batch/autoconfigure/KotlinJdslAutoConfiguration.kt b/support/spring-batch/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/batch/autoconfigure/KotlinJdslAutoConfiguration.kt index 7bf20121d..f4ffbf250 100644 --- a/support/spring-batch/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/batch/autoconfigure/KotlinJdslAutoConfiguration.kt +++ b/support/spring-batch/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/batch/autoconfigure/KotlinJdslAutoConfiguration.kt @@ -3,6 +3,7 @@ package com.linecorp.kotlinjdsl.support.spring.batch.autoconfigure import com.linecorp.kotlinjdsl.render.RenderContext import com.linecorp.kotlinjdsl.render.jpql.JpqlRenderContext import com.linecorp.kotlinjdsl.render.jpql.JpqlRenderModule +import com.linecorp.kotlinjdsl.render.jpql.introspector.JpqlIntrospector import com.linecorp.kotlinjdsl.render.jpql.serializer.JpqlSerializer import com.linecorp.kotlinjdsl.support.spring.batch.item.database.orm.KotlinJdslQueryProviderFactory import org.springframework.boot.autoconfigure.AutoConfiguration @@ -15,14 +16,21 @@ import org.springframework.context.annotation.Bean open class KotlinJdslAutoConfiguration { @Bean @ConditionalOnMissingBean - open fun jpqlRenderContext(serializers: List>): JpqlRenderContext { - val userDefinedSerializers = object : JpqlRenderModule { + open fun jpqlRenderContext( + serializers: List>, + introspectors: List, + ): JpqlRenderContext { + val userDefinedModule = object : JpqlRenderModule { override fun setupModule(context: JpqlRenderModule.SetupContext) { context.addAllSerializer(serializers.reversed()) + + introspectors.reversed().forEach { + context.prependIntrospector(it) + } } } - return JpqlRenderContext().registerModules(userDefinedSerializers) + return JpqlRenderContext().registerModules(userDefinedModule) } @Bean diff --git a/support/spring-data-jpa-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/javax/autoconfigure/KotlinJdslAutoConfiguration.kt b/support/spring-data-jpa-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/javax/autoconfigure/KotlinJdslAutoConfiguration.kt index 3840e882d..f3be9466e 100644 --- a/support/spring-data-jpa-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/javax/autoconfigure/KotlinJdslAutoConfiguration.kt +++ b/support/spring-data-jpa-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/javax/autoconfigure/KotlinJdslAutoConfiguration.kt @@ -4,6 +4,7 @@ import com.linecorp.kotlinjdsl.SinceJdsl import com.linecorp.kotlinjdsl.render.RenderContext import com.linecorp.kotlinjdsl.render.jpql.JpqlRenderContext import com.linecorp.kotlinjdsl.render.jpql.JpqlRenderModule +import com.linecorp.kotlinjdsl.render.jpql.introspector.JpqlIntrospector import com.linecorp.kotlinjdsl.render.jpql.serializer.JpqlSerializer import com.linecorp.kotlinjdsl.support.spring.data.jpa.javax.repository.KotlinJdslJpqlExecutor import com.linecorp.kotlinjdsl.support.spring.data.jpa.javax.repository.KotlinJdslJpqlExecutorImpl @@ -20,15 +21,21 @@ open class KotlinJdslAutoConfiguration { @Bean @ConditionalOnMissingBean @SinceJdsl("3.0.0") - open fun jpqlRenderContext(serializers: List>): JpqlRenderContext { - val userDefinedSerializers = object : JpqlRenderModule { + open fun jpqlRenderContext( + serializers: List>, + introspectors: List, + ): JpqlRenderContext { + val userDefinedModule = object : JpqlRenderModule { override fun setupModule(context: JpqlRenderModule.SetupContext) { context.addAllSerializer(serializers.reversed()) + + introspectors.reversed().forEach { + context.prependIntrospector(it) + } } } - return JpqlRenderContext() - .registerModules(userDefinedSerializers) + return JpqlRenderContext().registerModules(userDefinedModule) } @Bean diff --git a/support/spring-data-jpa/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/autoconfigure/KotlinJdslAutoConfiguration.kt b/support/spring-data-jpa/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/autoconfigure/KotlinJdslAutoConfiguration.kt index f5454b4cb..35f04720a 100644 --- a/support/spring-data-jpa/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/autoconfigure/KotlinJdslAutoConfiguration.kt +++ b/support/spring-data-jpa/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/autoconfigure/KotlinJdslAutoConfiguration.kt @@ -4,6 +4,7 @@ import com.linecorp.kotlinjdsl.SinceJdsl import com.linecorp.kotlinjdsl.render.RenderContext import com.linecorp.kotlinjdsl.render.jpql.JpqlRenderContext import com.linecorp.kotlinjdsl.render.jpql.JpqlRenderModule +import com.linecorp.kotlinjdsl.render.jpql.introspector.JpqlIntrospector import com.linecorp.kotlinjdsl.render.jpql.serializer.JpqlSerializer import com.linecorp.kotlinjdsl.support.spring.data.jpa.repository.KotlinJdslJpqlExecutor import com.linecorp.kotlinjdsl.support.spring.data.jpa.repository.KotlinJdslJpqlExecutorImpl @@ -20,15 +21,21 @@ open class KotlinJdslAutoConfiguration { @Bean @ConditionalOnMissingBean @SinceJdsl("3.0.0") - open fun jpqlRenderContext(serializers: List>): JpqlRenderContext { - val userDefinedSerializers = object : JpqlRenderModule { + open fun jpqlRenderContext( + serializers: List>, + introspectors: List, + ): JpqlRenderContext { + val userDefinedModule = object : JpqlRenderModule { override fun setupModule(context: JpqlRenderModule.SetupContext) { context.addAllSerializer(serializers.reversed()) + + introspectors.reversed().forEach { + context.prependIntrospector(it) + } } } - return JpqlRenderContext() - .registerModules(userDefinedSerializers) + return JpqlRenderContext().registerModules(userDefinedModule) } @Bean From 84fc35c0ab821eac9f2f77d8645f8bd771998f8c Mon Sep 17 00:00:00 2001 From: Jake Son Date: Sun, 12 Nov 2023 18:51:10 +0900 Subject: [PATCH 7/9] docs: add guides for spring --- docs/en/jpql-with-kotlin-jdsl/paths.md | 2 ++ docs/en/jpql-with-kotlin-jdsl/spring-supports.md | 2 +- docs/ko/jpql-with-kotlin-jdsl/paths.md | 2 ++ docs/ko/jpql-with-kotlin-jdsl/spring-supports.md | 2 +- 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/en/jpql-with-kotlin-jdsl/paths.md b/docs/en/jpql-with-kotlin-jdsl/paths.md index cd4661ba2..76e145985 100644 --- a/docs/en/jpql-with-kotlin-jdsl/paths.md +++ b/docs/en/jpql-with-kotlin-jdsl/paths.md @@ -55,6 +55,8 @@ path(Book::getAvailable) ``` If you want to use your own rule instead of the above rules, you can implement `JpqlPropertyIntrospector` and provide it to `RenderContext`. +See [Custom DSL](./custom-dsl.md) for more details. +If you are using Spring, see [Spring supports](./spring-supports.md) also. ```kotlin class MyIntrospector : JpqlPropertyIntrospector() { diff --git a/docs/en/jpql-with-kotlin-jdsl/spring-supports.md b/docs/en/jpql-with-kotlin-jdsl/spring-supports.md index 160bc3325..0ec5b7fb6 100644 --- a/docs/en/jpql-with-kotlin-jdsl/spring-supports.md +++ b/docs/en/jpql-with-kotlin-jdsl/spring-supports.md @@ -5,7 +5,7 @@ Kotlin JDSL supports Spring Boot AutoConfigure. If you have Spring Boot and `com.linecorp.kotlin-jdsl:spring-data-jpa-support` or `com.linecorp.kotlin-jdsl:spring-batch-support` dependency together, the `JpqlRenderContext` bean is created by AutoConfiguration. -If you declare your `JpqlSerializer` as a bean, it will be included with the `JpqlRenderContext` bean. +If you declare your `JpqlSerializer` or `JpqlIntrospector` as a bean, it will be included with the `JpqlRenderContext` bean. ## Spring Data Repository diff --git a/docs/ko/jpql-with-kotlin-jdsl/paths.md b/docs/ko/jpql-with-kotlin-jdsl/paths.md index 42eeb47fb..a55a7d1d7 100644 --- a/docs/ko/jpql-with-kotlin-jdsl/paths.md +++ b/docs/ko/jpql-with-kotlin-jdsl/paths.md @@ -55,6 +55,8 @@ path(Book::getAvailable) ``` 위 규칙 대신 나만의 규칙을 사용하고 싶다면, `JpqlPropertyIntrospector`를 구현하고 이를 이를 `RenderContext`에 추가해야 합니다. +더 자세한 내용은 [Custom DSL](./custom-dsl.md)을 참고하세요. +Spring을 사용하고 있다면 [Spring supports](./spring-supports.md)도 참고하세요. ```kotlin class MyIntrospector : JpqlPropertyIntrospector() { diff --git a/docs/ko/jpql-with-kotlin-jdsl/spring-supports.md b/docs/ko/jpql-with-kotlin-jdsl/spring-supports.md index 52f75c1ab..6eee9c598 100644 --- a/docs/ko/jpql-with-kotlin-jdsl/spring-supports.md +++ b/docs/ko/jpql-with-kotlin-jdsl/spring-supports.md @@ -5,7 +5,7 @@ Kotlin JDSL은 Spring Boot AutoConfigure를 지원합니다. 만약 프로젝트가 Spring Boot와 `com.linecorp.kotlin-jdsl:spring-data-jpa-support` dependency를 같이 포함하고 있다면, `JpqlRenderContext` bean이 `KotlinJdslAutoConfiguration`를 통해 자동 생성 됩니다. -만약 `JpqlSerializer`를 bean으로 선언했다면, 자동으로 `JpqlRenderContext`에 해당 bean이 포함됩니다. +만약 `JpqlSerializer` 또는 `JpqlIntrospector`를 bean으로 선언했다면, 자동으로 `JpqlRenderContext`에 해당 bean이 포함됩니다. ## Spring Data Repository From 6362262f09457eb3672b9df14f1643a6e580b156 Mon Sep 17 00:00:00 2001 From: Jake Son Date: Sun, 12 Nov 2023 18:53:41 +0900 Subject: [PATCH 8/9] style: revert code style --- .../batch/javax/autoconfigure/KotlinJdslAutoConfiguration.kt | 3 ++- .../spring/batch/autoconfigure/KotlinJdslAutoConfiguration.kt | 3 ++- .../jpa/javax/autoconfigure/KotlinJdslAutoConfiguration.kt | 3 ++- .../data/jpa/autoconfigure/KotlinJdslAutoConfiguration.kt | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/support/spring-batch-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/batch/javax/autoconfigure/KotlinJdslAutoConfiguration.kt b/support/spring-batch-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/batch/javax/autoconfigure/KotlinJdslAutoConfiguration.kt index 034f5ecb0..a11d7b2fc 100644 --- a/support/spring-batch-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/batch/javax/autoconfigure/KotlinJdslAutoConfiguration.kt +++ b/support/spring-batch-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/batch/javax/autoconfigure/KotlinJdslAutoConfiguration.kt @@ -30,7 +30,8 @@ open class KotlinJdslAutoConfiguration { } } - return JpqlRenderContext().registerModules(userDefinedModule) + return JpqlRenderContext() + .registerModules(userDefinedModule) } @Bean diff --git a/support/spring-batch/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/batch/autoconfigure/KotlinJdslAutoConfiguration.kt b/support/spring-batch/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/batch/autoconfigure/KotlinJdslAutoConfiguration.kt index f4ffbf250..bb15084bb 100644 --- a/support/spring-batch/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/batch/autoconfigure/KotlinJdslAutoConfiguration.kt +++ b/support/spring-batch/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/batch/autoconfigure/KotlinJdslAutoConfiguration.kt @@ -30,7 +30,8 @@ open class KotlinJdslAutoConfiguration { } } - return JpqlRenderContext().registerModules(userDefinedModule) + return JpqlRenderContext() + .registerModules(userDefinedModule) } @Bean diff --git a/support/spring-data-jpa-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/javax/autoconfigure/KotlinJdslAutoConfiguration.kt b/support/spring-data-jpa-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/javax/autoconfigure/KotlinJdslAutoConfiguration.kt index f3be9466e..144b98ad1 100644 --- a/support/spring-data-jpa-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/javax/autoconfigure/KotlinJdslAutoConfiguration.kt +++ b/support/spring-data-jpa-javax/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/javax/autoconfigure/KotlinJdslAutoConfiguration.kt @@ -35,7 +35,8 @@ open class KotlinJdslAutoConfiguration { } } - return JpqlRenderContext().registerModules(userDefinedModule) + return JpqlRenderContext() + .registerModules(userDefinedModule) } @Bean diff --git a/support/spring-data-jpa/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/autoconfigure/KotlinJdslAutoConfiguration.kt b/support/spring-data-jpa/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/autoconfigure/KotlinJdslAutoConfiguration.kt index 35f04720a..ee9415a7a 100644 --- a/support/spring-data-jpa/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/autoconfigure/KotlinJdslAutoConfiguration.kt +++ b/support/spring-data-jpa/src/main/kotlin/com/linecorp/kotlinjdsl/support/spring/data/jpa/autoconfigure/KotlinJdslAutoConfiguration.kt @@ -35,7 +35,8 @@ open class KotlinJdslAutoConfiguration { } } - return JpqlRenderContext().registerModules(userDefinedModule) + return JpqlRenderContext() + .registerModules(userDefinedModule) } @Bean From 74ab44d5ebeadfff9cf23a55d2a9224f1d8de4e0 Mon Sep 17 00:00:00 2001 From: Jake Son Date: Sun, 12 Nov 2023 21:44:52 +0900 Subject: [PATCH 9/9] test(query-model): rename test method --- .../com/linecorp/kotlinjdsl/querymodel/jpql/path/PathsTest.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/query-model/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/path/PathsTest.kt b/query-model/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/path/PathsTest.kt index 311041819..62a8bfeed 100644 --- a/query-model/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/path/PathsTest.kt +++ b/query-model/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/path/PathsTest.kt @@ -18,7 +18,7 @@ class PathsTest : WithAssertions { private val path2 = Paths.treat(Paths.path(EmployeeDepartment::employee), FullTimeEmployee::class) @Test - fun `path with a property`() { + fun `path() with a property`() { // when val actual = Paths.path( FullTimeEmployee::address, @@ -34,7 +34,7 @@ class PathsTest : WithAssertions { } @Test - fun `path with a getter`() { + fun `path() with a getter`() { // when val actual = Paths.path( FullTimeEmployee::getDisplayName,