Skip to content

Commit 1016770

Browse files
committed
Merge branch 'master' of github.com:OpenFeign/querydsl into querydsl-7.0
2 parents b417c0e + 590b0c1 commit 1016770

File tree

5 files changed

+86
-16
lines changed

5 files changed

+86
-16
lines changed

querydsl-examples/querydsl-example-ksp-codegen/build.gradle.kts

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,26 @@ val querydslVersion = findProperty("querydsl.version") as String
66
val assertjVersion = findProperty("assertj.version") as String
77

88
plugins {
9-
kotlin("jvm")
10-
id("com.google.devtools.ksp")
11-
kotlin("plugin.jpa")
12-
kotlin("plugin.serialization")
9+
kotlin("jvm")
10+
id("com.google.devtools.ksp")
11+
kotlin("plugin.jpa")
12+
kotlin("plugin.serialization")
1313
}
1414

1515
repositories {
16-
mavenCentral()
17-
mavenLocal()
16+
mavenCentral()
17+
mavenLocal()
1818
}
1919

2020
dependencies {
21-
implementation("jakarta.persistence:jakarta.persistence-api:${jpaVersion}")
22-
implementation("io.github.openfeign.querydsl:querydsl-core:${querydslVersion}")
23-
ksp("io.github.openfeign.querydsl:querydsl-ksp-codegen:${querydslVersion}")
24-
25-
testImplementation("io.github.openfeign.querydsl:querydsl-jpa:${querydslVersion}")
26-
testImplementation("org.assertj:assertj-core:${assertjVersion}")
27-
testImplementation("org.hibernate.orm:hibernate-core:${hibernateVersion}")
28-
testImplementation("com.h2database:h2:${h2Version}")
29-
testImplementation("org.jetbrains.kotlin:kotlin-test-junit:${kotlinVersion}")
21+
implementation("jakarta.persistence:jakarta.persistence-api:${jpaVersion}")
22+
implementation("io.github.openfeign.querydsl:querydsl-core:${querydslVersion}")
23+
implementation("org.hibernate.orm:hibernate-core:${hibernateVersion}")
24+
ksp("io.github.openfeign.querydsl:querydsl-ksp-codegen:${querydslVersion}")
25+
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.19.0")
26+
testImplementation("io.github.openfeign.querydsl:querydsl-jpa:${querydslVersion}")
27+
testImplementation("org.assertj:assertj-core:${assertjVersion}")
28+
testImplementation("org.hibernate.orm:hibernate-core:${hibernateVersion}")
29+
testImplementation("com.h2database:h2:${h2Version}")
30+
testImplementation("org.jetbrains.kotlin:kotlin-test-junit:${kotlinVersion}")
3031
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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.hibernate.annotations.JdbcTypeCode
7+
import org.hibernate.type.SqlTypes
8+
9+
@Entity
10+
class Dog(
11+
@Id
12+
val id: Int,
13+
val name: String,
14+
@JdbcTypeCode(SqlTypes.JSON)
15+
@Column(columnDefinition = "json")
16+
val tag: Tag
17+
)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.querydsl.example.ksp
2+
3+
class Tag(
4+
val id: Int,
5+
val name: String,
6+
)

querydsl-examples/querydsl-example-ksp-codegen/src/test/kotlin/Tests.kt

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import com.querydsl.example.ksp.Cat
22
import com.querydsl.example.ksp.CatType
3+
import com.querydsl.example.ksp.Dog
34
import com.querydsl.example.ksp.Person
45
import com.querydsl.example.ksp.QCat
6+
import com.querydsl.example.ksp.QDog
57
import com.querydsl.example.ksp.QPerson
68
import com.querydsl.example.ksp.QPersonClassDTO
79
import com.querydsl.example.ksp.QPersonClassConstructorDTO
10+
import com.querydsl.example.ksp.Tag
811
import com.querydsl.jpa.impl.JPAQueryFactory
912
import jakarta.persistence.EntityManagerFactory
1013
import org.hibernate.cfg.AvailableSettings
@@ -162,6 +165,47 @@ class Tests {
162165
}
163166
}
164167

168+
@Test
169+
fun `create and query dog with jsonb tag`() {
170+
val emf = initialize()
171+
172+
run {
173+
val em = emf.createEntityManager()
174+
em.transaction.begin()
175+
176+
val dogTag = Tag(
177+
id = 10,
178+
name = "Playful"
179+
)
180+
em.persist(Dog(300, "Buddy", dogTag))
181+
182+
em.transaction.commit()
183+
em.close()
184+
}
185+
186+
run {
187+
val em = emf.createEntityManager()
188+
val queryFactory = JPAQueryFactory(em)
189+
val q = QDog.dog
190+
191+
val dog = queryFactory
192+
.selectFrom(q)
193+
.where(q.name.eq("Buddy"))
194+
.fetchOne()
195+
196+
if (dog == null) {
197+
fail<Any>("No dog was returned")
198+
} else {
199+
assertThat(dog.id).isEqualTo(300)
200+
assertThat(dog.name).isEqualTo("Buddy")
201+
assertThat(dog.tag.id).isEqualTo(10)
202+
assertThat(dog.tag.name).isEqualTo("Playful")
203+
}
204+
205+
em.close()
206+
}
207+
}
208+
165209
private fun initialize(): EntityManagerFactory {
166210
val configuration = Configuration()
167211
.setProperty(AvailableSettings.JAKARTA_JDBC_DRIVER, org.h2.Driver::class.qualifiedName!!)
@@ -170,9 +214,10 @@ class Tests {
170214
.setProperty(AvailableSettings.SHOW_SQL, "true")
171215
.addAnnotatedClass(Person::class.java)
172216
.addAnnotatedClass(Cat::class.java)
217+
.addAnnotatedClass(Dog::class.java)
173218

174219
return configuration
175220
.buildSessionFactory()
176221
.unwrap(EntityManagerFactory::class.java)
177222
}
178-
}
223+
}

querydsl-tooling/querydsl-ksp-codegen/src/main/kotlin/com/querydsl/ksp/codegen/TypeExtractor.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ class TypeExtractor(
112112
private fun userType(type: KSType): QPropertyType.Unknown? {
113113
val userTypeAnnotations = listOf(
114114
ClassName("org.hibernate.annotations", "Type"),
115+
ClassName("org.hibernate.annotations", "JdbcTypeCode"),
115116
Convert::class.asClassName()
116117
)
117118
if (property.annotations.any { userTypeAnnotations.contains(it.annotationType.resolve().toClassName()) }) {

0 commit comments

Comments
 (0)