-
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 support for java getter #518
Conversation
private val classTableLookupCache: MutableMap<KClass<*>, JpqlEntityDescription> = ConcurrentHashMap() | ||
private val propertyTableLookupCache: MutableMap<KCallable<*>, JpqlPropertyDescription> = ConcurrentHashMap() |
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.
The table
prefix is a misnomer on my part - I named it table because I was planning to have native queries at that time, but now that it's JPQL-only, I think it's okay to name it entityLookupCache
and propertyLookupCache
.
override fun introspect(property: KCallable<*>): JpqlPropertyDescription? { | ||
return when (property) { | ||
is KProperty1<*, *> -> JpqlProperty(property.name) | ||
is KFunction1<*, *> -> JpqlProperty(resolvePropertyName(property)) | ||
else -> null | ||
} | ||
} | ||
|
||
private fun resolvePropertyName(getter: KFunction1<*, *>): String = | ||
if (getter.name.startsWith("is")) { | ||
getter.name | ||
} else { | ||
getter.name.removePrefix("get").replaceFirstChar { it.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.
I suppose the Property Introspector can be separated from Javax
and Jakarta
.
JpqlIntrospector
is designed to delegate to another Intropsector
if it cannot introspect itself. Therefore, I think we can reduce the duplication by creating a separate class that only introspects properties and adding it to the Context
together.
class JavaxJpqlEntityIntrospector : JpqlIntrospector {
override fun introspect(type: KClass<*>): JpqlEntityDescription? {
// ...
}
override fun introspect(property: KCallable<*>): JpqlPropertyDescription? {
return null
}
}
class JakartaJpqlEntityIntrospector : JpqlIntrospector {
override fun introspect(type: KClass<*>): JpqlEntityDescription? {
// ...
}
override fun introspect(property: KCallable<*>): JpqlPropertyDescription? {
return null
}
}
class KotlinStyleJpqlPropertyIntrospector : JpqlIntrospector {
override fun introspect(type: KClass<*>): JpqlEntityDescription? {
return null
}
override fun introspect(property: KCallable<*>): JpqlPropertyDescription? {
return when (property) {
is KProperty1<*, *> -> JpqlProperty(property.name)
is KFunction1<*, *> -> JpqlProperty(resolvePropertyName(property))
else -> null
}
}
// ...
}
private class DefaultModule : JpqlRenderModule {
override fun setupModule(context: JpqlRenderModule.SetupContext) {
// ...
context.appendIntrospector(KotlinStyleJpqlPropertyIntrospector())
// ...
}
}
I think also you could create two abstract classes, JpqlEntityIntrospector
and JpqlPropertyIntrospector
, that implement JpqlIntropsector.
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## develop #518 +/- ##
===========================================
- Coverage 92.14% 92.11% -0.04%
===========================================
Files 266 269 +3
Lines 2916 2942 +26
Branches 171 177 +6
===========================================
+ Hits 2687 2710 +23
- Misses 180 181 +1
- Partials 49 51 +2
☔ View full report in Codecov by Sentry. |
Thank you for your contributions! I will be releasing 3.1.0 on November the 24th, two weeks from now. Since it's a minor release, I'm hoping to include some of the string functions that I couldn't support, so I'll work on them and include them in the minor release. |
Ahh, this PR has already been merged. :) I'm wonder if the intention was to guide users to use the |
Aha, I thought you wanted me to implement JpqlDsl, so I tried to implement it. I'd appreciate it if you implemented JpqlDsl as well. If you make it a new PR, I'll review it. Have you thought about making a doc as well? |
I would like to make docs too :) |
Motivation
This pull request has not been completed yet.
It was created to receive a review to ensure that the work done so far has been implemented correctly.
Modifications
JpqlEntityProperty
andJpqlPathProperty
.KFunction1
Commit Convention Rule
commit type
please describe it on the Pull RequestResult
Path
.Closes