-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add path method for KFunction1
#521
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## develop #521 +/- ##
===========================================
- Coverage 92.11% 91.90% -0.21%
===========================================
Files 269 269
Lines 2942 2966 +24
Branches 177 177
===========================================
+ Hits 2710 2726 +16
- Misses 181 189 +8
Partials 51 51
☔ View full report in Codecov by Sentry. |
* Creates a path expression with the entity and property. | ||
*/ | ||
@SinceJdsl("3.1.0") | ||
fun <T : Any, V> Entityable<T>.path(getter: KFunction1<T, @Exact V>): Path<V & Any> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to put in
in the T generic type? I want to include in
in something like KProperty1<in T, @Eact V>
because an user might want to create a path with the parent type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It works in the test, but it's probably because the receiver's T is cast to a supertype. This causes the type to be broken when chaining occurs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when i first put in
keyword. IDE show me the following warning.
It might that KFunction1
has in
variance unlike KProperty1
.
Projection is redundant: the corresponding type parameter of KFunction1 has the same variance
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aha, I see. Thank you for the confirmation.
@@ -7,4 +7,6 @@ abstract class Employee( | |||
val phone: String, | |||
val address: EmployeeAddress, | |||
val departments: MutableSet<EmployeeDepartment>, | |||
) | |||
) { | |||
fun getLowerName(): String = name.lowercase() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is a test entity, it doesn't matter what methods it has, but how about making it a little more meaningful? Could we write code like fun getNickname() = nickname ?: name
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is compile error when we have method named getNickname
.
so i rename getDisplayName
Platform declaration clash: The following declarations have the same JVM signature (getNickname()Ljava/lang/String;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
displayName sounds really good.
@@ -17,4 +17,6 @@ class FullTimeEmployee( | |||
phone = phone, | |||
address = address, | |||
departments = departments, | |||
) | |||
) { | |||
fun getUpperName(): String = name.uppercase() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we could make a method like fun getMonthlySalary(): EmployeeSalary = EmployeeSalary(annualSalary.value.div(BigDecimal.valueOf(12)))
.
@@ -33,6 +33,22 @@ class PathsTest : WithAssertions { | |||
assertThat(actual).isEqualTo(expected) | |||
} | |||
|
|||
@Test | |||
fun pathGetter() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that path
can take two parameters, we can rename the path
method to path with a property
and rename it to path with a getter
.
@@ -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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about replacing take
with can take
?
path(Book::getTitle) | ||
``` | ||
|
||
Kotlin JDSL follows the following rules to infer property name from getter name. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to change the sentence to something like this: Kotlin JDSL infers the property name from the getter with the following rules:
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`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to change you need to implement
to you can implement
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to leave a guide and link to the Custom DSL for more details, and to Spring Support if the user is using Spring.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also it would be nice to add Spring AutoConfigure, since there is no Spring Support for JpqlIntrospector
. This forces the user to modify the JpqlRenderContext
by themselves, which I think will be inconvenient for the user.
open class KotlinJdslAutoConfiguration {
@Bean
@ConditionalOnMissingBean
@SinceJdsl("3.0.0")
open fun jpqlRenderContext(
serializers: List<JpqlSerializer<*>>,
introspectors: List<JpqlIntrospector>,
): JpqlRenderContext {
val userDefinedSerializers = object : JpqlRenderModule {
override fun setupModule(context: JpqlRenderModule.SetupContext) {
context.addAllSerializer(serializers.reversed())
introspectors.reversed().forEach {
context.prependIntrospector(it)
}
}
}
return JpqlRenderContext()
.registerModules(userDefinedSerializers)
}
// ...
}
@@ -13,6 +13,75 @@ entity(Book::class, "b").path(Book::isbn).path(Isbn::value) | |||
entity(Book::class, "b")(Book::isbn)(Isbn::value) | |||
``` | |||
|
|||
## Java entity |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
한국어까지 같이 작성해주셔서 정말 감사합니다. ❤️
query-model/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/querymodel/jpql/path/PathsTest.kt
Outdated
Show resolved
Hide resolved
89e79c6
to
74ab44d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your contribution!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the help! I'll rename some of the tests.
Motivation
Modifications
KFunction1
Commit Convention Rule
commit type
please describe it on the Pull RequestResult
KFunction1
topath
methodCloses