File tree Expand file tree Collapse file tree 4 files changed +48
-1
lines changed
querydsl-examples/querydsl-example-ksp-codegen
main/kotlin/com/querydsl/example/ksp
querydsl-tooling/querydsl-ksp-codegen/src/main/kotlin/com/querydsl/ksp/codegen Expand file tree Collapse file tree 4 files changed +48
-1
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ dependencies {
2222 implementation(" io.github.openfeign.querydsl:querydsl-core:${querydslVersion} " )
2323 implementation(" org.hibernate.orm:hibernate-core:${hibernateVersion} " )
2424 ksp(" io.github.openfeign.querydsl:querydsl-ksp-codegen:${querydslVersion} " )
25+ implementation(" org.locationtech.jts:jts-core:1.19.0" )
2526 implementation(" com.fasterxml.jackson.module:jackson-module-kotlin:2.19.0" )
2627 testImplementation(" io.github.openfeign.querydsl:querydsl-jpa:${querydslVersion} " )
2728 testImplementation(" org.assertj:assertj-core:${assertjVersion} " )
Original file line number Diff line number Diff line change 1+ package com.querydsl.example.ksp
2+
3+ import jakarta.persistence.Column
4+ import jakarta.persistence.Entity
5+ import jakarta.persistence.Id
6+ import org.locationtech.jts.geom.Point
7+
8+ @Entity
9+ class Geolocation (
10+ @Id
11+ val id : Int ,
12+ @Column(columnDefinition = " geography(Point, 4326)" )
13+ var location : Point ? = null ,
14+ )
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ import com.querydsl.example.ksp.QBear
77import com.querydsl.example.ksp.QBearSimplifiedProjection
88import com.querydsl.example.ksp.QCat
99import com.querydsl.example.ksp.QDog
10+ import com.querydsl.example.ksp.QGeolocation
1011import com.querydsl.example.ksp.QPerson
1112import com.querydsl.example.ksp.QPersonClassDTO
1213import com.querydsl.example.ksp.QPersonClassConstructorDTO
@@ -248,6 +249,16 @@ class Tests {
248249 }
249250 }
250251
252+ @Test
253+ fun `is detecting comparable interface on unknown type` () {
254+ val locationTypeName = QGeolocation ::class
255+ .members
256+ .first { it.name == " location" }
257+ .returnType
258+ .toString()
259+ assertThat(locationTypeName).isEqualTo(" com.querydsl.core.types.dsl.ComparablePath<org.locationtech.jts.geom.Point>" )
260+ }
261+
251262 private fun initialize (): EntityManagerFactory {
252263 val configuration = Configuration ()
253264 .setProperty(AvailableSettings .JAKARTA_JDBC_DRIVER , org.h2.Driver ::class .qualifiedName!! )
Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ class TypeExtractor(
2424 ? : simpleType(type)
2525 ? : referenceType(type)
2626 ? : collectionType(type)
27- ? : throwError( " Type was not recognised, This may be an entity that has not been annotated with @Entity, or maybe you are using javax instead of jakarta. " )
27+ ? : fallbackType(type )
2828 }
2929 }
3030
@@ -45,6 +45,27 @@ class TypeExtractor(
4545 }
4646 }
4747
48+ private fun fallbackType (type : KSType ): QPropertyType .Simple {
49+ val declaration = type.declaration
50+ val isComparable = if (declaration is KSClassDeclaration ) {
51+ val comparableNames = listOfNotNull(
52+ Comparable ::class .java.canonicalName,
53+ java.lang.Comparable ::class .qualifiedName
54+ )
55+ declaration.getAllSuperTypes().any {
56+ comparableNames.contains(it.toClassName().canonicalName)
57+ }
58+ } else {
59+ false
60+ }
61+ val className = type.toClassNameSimple()
62+ if (isComparable) {
63+ return QPropertyType .Simple (SimpleType .Comparable (className))
64+ } else {
65+ return QPropertyType .Simple (SimpleType .Simple (className))
66+ }
67+ }
68+
4869 private fun simpleType (type : KSType ): QPropertyType .Simple ? {
4970 val className = type.toClassNameSimple()
5071 val simpleType = SimpleType .Mapper .get(className)
You can’t perform that action at this time.
0 commit comments