Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ dependencies {
implementation("io.github.openfeign.querydsl:querydsl-core:${querydslVersion}")
implementation("org.hibernate.orm:hibernate-core:${hibernateVersion}")
ksp("io.github.openfeign.querydsl:querydsl-ksp-codegen:${querydslVersion}")
implementation("org.locationtech.jts:jts-core:1.19.0")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.19.0")
testImplementation("io.github.openfeign.querydsl:querydsl-jpa:${querydslVersion}")
testImplementation("org.assertj:assertj-core:${assertjVersion}")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.querydsl.example.ksp

import jakarta.persistence.Column
import jakarta.persistence.Entity
import jakarta.persistence.Id
import org.locationtech.jts.geom.Point

@Entity
class Geolocation(
@Id
val id: Int,
@Column(columnDefinition = "geography(Point, 4326)")
var location: Point? = null,
)
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.querydsl.example.ksp.QBear
import com.querydsl.example.ksp.QBearSimplifiedProjection
import com.querydsl.example.ksp.QCat
import com.querydsl.example.ksp.QDog
import com.querydsl.example.ksp.QGeolocation
import com.querydsl.example.ksp.QPerson
import com.querydsl.example.ksp.QPersonClassDTO
import com.querydsl.example.ksp.QPersonClassConstructorDTO
Expand Down Expand Up @@ -248,6 +249,16 @@ class Tests {
}
}

@Test
fun `is detecting comparable interface on unknown type`() {
val locationTypeName = QGeolocation::class
.members
.first { it.name == "location" }
.returnType
.toString()
assertThat(locationTypeName).isEqualTo("com.querydsl.core.types.dsl.ComparablePath<org.locationtech.jts.geom.Point>")
}

private fun initialize(): EntityManagerFactory {
val configuration = Configuration()
.setProperty(AvailableSettings.JAKARTA_JDBC_DRIVER, org.h2.Driver::class.qualifiedName!!)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class TypeExtractor(
?: simpleType(type)
?: referenceType(type)
?: collectionType(type)
?: 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.")
?: fallbackType(type)
}
}

Expand All @@ -45,6 +45,27 @@ class TypeExtractor(
}
}

private fun fallbackType(type: KSType): QPropertyType.Simple {
val declaration = type.declaration
val isComparable = if (declaration is KSClassDeclaration) {
val comparableNames = listOfNotNull(
Comparable::class.java.canonicalName,
java.lang.Comparable::class.qualifiedName
)
declaration.getAllSuperTypes().any {
comparableNames.contains(it.toClassName().canonicalName)
}
} else {
false
}
val className = type.toClassNameSimple()
if (isComparable) {
return QPropertyType.Simple(SimpleType.Comparable(className))
} else {
return QPropertyType.Simple(SimpleType.Simple(className))
}
}

private fun simpleType(type: KSType): QPropertyType.Simple? {
val className = type.toClassNameSimple()
val simpleType = SimpleType.Mapper.get(className)
Expand Down