Skip to content

Commit 31ece15

Browse files
committed
Merge remote-tracking branch 'origin/master' into querydsl-7.0
2 parents 975ff44 + 35a2729 commit 31ece15

File tree

15 files changed

+222
-54
lines changed

15 files changed

+222
-54
lines changed

pom.xml

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,11 @@
104104

105105
<git-code-format-maven-plugin.version>5.3</git-code-format-maven-plugin.version>
106106

107-
<junit.version>5.12.0</junit.version>
107+
<junit.version>5.12.1</junit.version>
108108
<ecj.version>3.40.0</ecj.version>
109109
<jdo.version>3.2.1</jdo.version>
110-
<springboot.version>3.4.3</springboot.version>
111-
<spring.version>6.2.3</spring.version>
110+
<springboot.version>3.4.4</springboot.version>
111+
<spring.version>6.2.5</spring.version>
112112

113113
<!-- SQL deps -->
114114
<db2.version>12.1.0.0</db2.version>
@@ -118,7 +118,7 @@
118118
<postgresql.version>42.7.5</postgresql.version>
119119
<oracle.version>23.7.0.25.01</oracle.version>
120120
<mysql.version>9.2.0</mysql.version>
121-
<mssql.version>12.9.0.jre8-preview</mssql.version>
121+
<mssql.version>12.10.0.jre8</mssql.version>
122122
<cubrid.version>9.3.9.0002</cubrid.version>
123123
<sqlite.version>3.49.1.0</sqlite.version>
124124
<teradata.version>13.10.00.35</teradata.version>
@@ -136,21 +136,21 @@
136136

137137
<assertj.version>3.27.3</assertj.version>
138138
<mvn.version>3.9.9</mvn.version>
139-
<guava.version>33.4.0-jre</guava.version>
139+
<guava.version>33.4.6-jre</guava.version>
140140
<codegen.version>0.6.8</codegen.version>
141-
<byte-buddy.version>1.17.2</byte-buddy.version>
141+
<byte-buddy.version>1.17.5</byte-buddy.version>
142142
<slf4j.version>2.0.17</slf4j.version>
143-
<surefire.version>3.5.2</surefire.version>
143+
<surefire.version>3.5.3</surefire.version>
144144
<animal-sniffer.version>1.24</animal-sniffer.version>
145145
<h2gis.version>2.2.3</h2gis.version>
146146
<morphia.version>1.3.2</morphia.version>
147147
<jmh.version>1.37</jmh.version>
148-
<kotlin.version>2.1.10</kotlin.version>
149-
<ksp.version>2.1.10-1.0.31</ksp.version>
148+
<kotlin.version>2.1.20</kotlin.version>
149+
<ksp.version>2.1.20-1.0.32</ksp.version>
150150
<kotlinpoet.version>2.1.0</kotlinpoet.version>
151151
<dokka.version>2.0.0</dokka.version>
152152
<scala.version>2.11.12</scala.version>
153-
<asm.version>9.7.1</asm.version>
153+
<asm.version>9.8</asm.version>
154154
<querydsl.version>${project.version}</querydsl.version>
155155

156156
<!-- Import-Package definitions for maven-bundle-plugin -->
@@ -224,7 +224,7 @@
224224
<dependency>
225225
<groupId>org.geolatte</groupId>
226226
<artifactId>geolatte-geom</artifactId>
227-
<version>1.9.1</version>
227+
<version>1.10</version>
228228
</dependency>
229229
<dependency>
230230
<groupId>org.jetbrains.kotlin</groupId>
@@ -489,7 +489,7 @@
489489
<plugin>
490490
<groupId>org.jacoco</groupId>
491491
<artifactId>jacoco-maven-plugin</artifactId>
492-
<version>0.8.12</version>
492+
<version>0.8.13</version>
493493
<executions>
494494
<execution>
495495
<id>prepare-agent</id>
@@ -1011,18 +1011,18 @@
10111011
<plugin>
10121012
<groupId>org.openrewrite.maven</groupId>
10131013
<artifactId>rewrite-maven-plugin</artifactId>
1014-
<version>6.3.0</version>
1014+
<version>6.4.0</version>
10151015

10161016
<dependencies>
10171017
<dependency>
10181018
<groupId>org.openrewrite.recipe</groupId>
10191019
<artifactId>rewrite-testing-frameworks</artifactId>
1020-
<version>3.4.0</version>
1020+
<version>3.5.1</version>
10211021
</dependency>
10221022
<dependency>
10231023
<groupId>org.openrewrite.recipe</groupId>
10241024
<artifactId>rewrite-migrate-java</artifactId>
1025-
<version>3.4.0</version>
1025+
<version>3.5.0</version>
10261026
</dependency>
10271027
</dependencies>
10281028

querydsl-examples/querydsl-example-jpa-quarkus/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<name>Querydsl example - JPA Quarkus</name>
1313

1414
<properties>
15-
<quarkus.version>3.19.2</quarkus.version>
15+
<quarkus.version>3.21.1</quarkus.version>
1616
</properties>
1717

1818
<dependencyManagement>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.querydsl.example.ksp
2+
3+
import com.querydsl.core.annotations.QueryProjection
4+
5+
data class PersonClassConstructorDTO @QueryProjection constructor(
6+
val id: Int,
7+
val name: String,
8+
)
9+
10+
@QueryProjection
11+
data class PersonClassDTO (val id: Int, val name: String)

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

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import com.querydsl.example.ksp.CatType
33
import com.querydsl.example.ksp.Person
44
import com.querydsl.example.ksp.QCat
55
import com.querydsl.example.ksp.QPerson
6+
import com.querydsl.example.ksp.QPersonClassDTO
7+
import com.querydsl.example.ksp.QPersonClassConstructorDTO
68
import com.querydsl.jpa.impl.JPAQueryFactory
79
import jakarta.persistence.EntityManagerFactory
810
import org.hibernate.cfg.AvailableSettings
@@ -111,6 +113,55 @@ class Tests {
111113
}
112114
}
113115

116+
@Test
117+
fun `select dto`() {
118+
val emf = initialize()
119+
120+
run {
121+
val em = emf.createEntityManager()
122+
em.transaction.begin()
123+
em.persist(Person(424, "John Smith"))
124+
em.transaction.commit()
125+
em.close()
126+
}
127+
128+
run {
129+
val em = emf.createEntityManager()
130+
val queryFactory = JPAQueryFactory(em)
131+
val q = QPerson.person
132+
val personDTO = queryFactory
133+
.select(QPersonClassConstructorDTO(q.id, q.name))
134+
.from(q)
135+
.where(q.name.eq("John Smith"))
136+
.fetchOne()
137+
if (personDTO == null) {
138+
fail<Any>("No personDTO was returned")
139+
} else {
140+
assertThat(personDTO.id).isEqualTo(424)
141+
assertThat(personDTO.name).isEqualTo("John Smith")
142+
}
143+
em.close()
144+
}
145+
146+
run {
147+
val em = emf.createEntityManager()
148+
val queryFactory = JPAQueryFactory(em)
149+
val q = QPerson.person
150+
val personDTO = queryFactory
151+
.select(QPersonClassDTO(q.id, q.name))
152+
.from(q)
153+
.where(q.name.eq("John Smith"))
154+
.fetchOne()
155+
if (personDTO == null) {
156+
fail<Any>("No personDTO was returned")
157+
} else {
158+
assertThat(personDTO.id).isEqualTo(424)
159+
assertThat(personDTO.name).isEqualTo("John Smith")
160+
}
161+
em.close()
162+
}
163+
}
164+
114165
private fun initialize(): EntityManagerFactory {
115166
val configuration = Configuration()
116167
.setProperty(AvailableSettings.JAKARTA_JDBC_DRIVER, org.h2.Driver::class.qualifiedName!!)

querydsl-examples/querydsl-example-sql-spring/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
<dependency>
3333
<groupId>org.projectlombok</groupId>
3434
<artifactId>lombok</artifactId>
35-
<version>1.18.36</version>
35+
<version>1.18.38</version>
3636
<scope>provided</scope>
3737
</dependency>
3838

querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/JPQLSerializer.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public class JPQLSerializer extends SerializerBase<JPQLSerializer> {
6565
Ops.ADD, Ops.SUB, Ops.MULT, Ops.DIV, Ops.LT, Ops.LOE, Ops.GT, Ops.GOE, Ops.BETWEEN));
6666

6767
private static final Set<? extends Operator> CASE_OPS =
68-
Collections.unmodifiableSet(EnumSet.of(Ops.CASE_ELSE));
68+
Collections.unmodifiableSet(EnumSet.of(Ops.CASE_WHEN, Ops.CASE_ELSE));
6969

7070
private static final String COMMA = ", ";
7171

@@ -383,6 +383,10 @@ private void serializeSources(boolean forCountRow, List<JoinExpression> joins) {
383383

384384
@Override
385385
public void visitConstant(Object constant) {
386+
if (inCaseOperation && constant instanceof Enum) {
387+
visitLiteral(constant);
388+
return;
389+
}
386390
if (inCaseOperation && templates.isCaseWithLiterals()) {
387391
if (constant instanceof Collection<?> collection) {
388392
append("(");

querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/JPQLTemplates.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,8 @@ public String asLiteral(Object constant) {
212212
return constant.toString();
213213
} else if (constant instanceof String) {
214214
return "'" + escapeLiteral(constant.toString()) + "'";
215-
} else if (constant instanceof Enum<?> enum1) {
216-
return constant.getClass().getName() + "." + enum1.name();
215+
} else if (constant instanceof Enum enum1) {
216+
return "'" + enum1.name() + "'";
217217
} else {
218218
return "'" + constant.toString() + "'";
219219
}

querydsl-libraries/querydsl-jpa/src/test/java/com/querydsl/jpa/JPQLSerializerTest.java

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,13 @@
1919
import com.querydsl.core.DefaultQueryMetadata;
2020
import com.querydsl.core.JoinType;
2121
import com.querydsl.core.QueryMetadata;
22-
import com.querydsl.core.domain.QAnimal;
2322
import com.querydsl.core.domain.QCat;
2423
import com.querydsl.core.types.EntityPath;
2524
import com.querydsl.core.types.Expression;
2625
import com.querydsl.core.types.Path;
2726
import com.querydsl.core.types.Predicate;
28-
import com.querydsl.core.types.dsl.EntityPathBase;
29-
import com.querydsl.core.types.dsl.Expressions;
30-
import com.querydsl.core.types.dsl.NumberPath;
31-
import com.querydsl.jpa.domain.JobFunction;
32-
import com.querydsl.jpa.domain.Location;
33-
import com.querydsl.jpa.domain.QDomesticCat;
34-
import com.querydsl.jpa.domain.QEmployee;
27+
import com.querydsl.core.types.dsl.*;
28+
import com.querydsl.jpa.domain.*;
3529
import java.util.Arrays;
3630
import org.junit.Test;
3731

@@ -67,7 +61,7 @@ public void case1_hibernate() {
6761
Expressions.cases().when(cat.toes.eq(2)).then(2).when(cat.toes.eq(3)).then(3).otherwise(4);
6862
serializer.handle(expr);
6963
assertThat(serializer.toString())
70-
.isEqualTo("case when (cat.toes = ?1) then ?2 when (cat.toes = ?3) then ?4 else 4 end");
64+
.isEqualTo("case when (cat.toes = ?1) then 2 when (cat.toes = ?2) then 3 else 4 end");
7165
}
7266

7367
@Test
@@ -343,18 +337,38 @@ public void visitLiteral_string() {
343337
assertThat(serializer).hasToString("'abc''''def'");
344338
}
345339

346-
@Test
347-
public void visitLiteral_enum() {
348-
var serializer = new JPQLSerializer(HQLTemplates.DEFAULT);
349-
serializer.visitLiteral(JobFunction.MANAGER);
350-
assertThat(serializer).hasToString("com.querydsl.jpa.domain.JobFunction.MANAGER");
351-
}
352-
353340
@Test
354341
public void substring_indexOf() {
355342
var cat = QCat.cat;
356343
var serializer = new JPQLSerializer(HQLTemplates.DEFAULT);
357344
cat.name.substring(cat.name.indexOf("")).accept(serializer, null);
358345
assertThat(serializer).hasToString("substring(cat.name,locate(?1,cat.name)-1 + ?2)");
359346
}
347+
348+
@Test
349+
public void case_enumConversion() {
350+
var serializer = new JPQLSerializer(JPQLTemplates.DEFAULT);
351+
352+
Expression<?> expr =
353+
new CaseBuilder()
354+
.when(Expressions.TRUE)
355+
.then(JobFunction.MANAGER)
356+
.otherwise(JobFunction.CONSULTANT);
357+
358+
serializer.handle(expr);
359+
360+
assertThat(serializer.toString())
361+
.isEqualTo("case when true then 'MANAGER' else 'CONSULTANT' end");
362+
}
363+
364+
@Test
365+
public void inClause_enumCollection() {
366+
QAnimal animal = QAnimal.animal;
367+
Expression<?> predicate = animal.color.in(Arrays.asList(Color.BLACK, Color.TABBY));
368+
JPQLSerializer serializer = new JPQLSerializer(JPQLTemplates.DEFAULT);
369+
serializer.handle(predicate);
370+
assertThat(serializer.toString()).isEqualTo("animal.color in ?1");
371+
Object constant = serializer.getConstants().get(0);
372+
assertThat(constant.toString()).isEqualTo("[BLACK, TABBY]");
373+
}
360374
}

querydsl-libraries/querydsl-scala/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@
153153
<plugin>
154154
<groupId>net.alchim31.maven</groupId>
155155
<artifactId>scala-maven-plugin</artifactId>
156-
<version>4.9.2</version>
156+
<version>4.9.5</version>
157157
<configuration>
158158
<charset>${character.encoding}</charset>
159159
<scalaVersion>${scala.version}</scalaVersion>

querydsl-tooling/querydsl-apt/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
<dependency>
7676
<groupId>org.joda</groupId>
7777
<artifactId>joda-money</artifactId>
78-
<version>2.0.1</version>
78+
<version>2.0.2</version>
7979
<scope>test</scope>
8080
</dependency>
8181

querydsl-tooling/querydsl-codegen-utils/src/main/java/com/querydsl/codegen/utils/model/SimpleType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public SimpleType(
103103
this.fullName = fullName;
104104
this.packageName = packageName;
105105
this.simpleName = simpleName;
106-
if (packageName.length() > 0) {
106+
if (packageName.length() > 0 && fullName.length() > packageName.length()) {
107107
this.localName = fullName.substring(packageName.length() + 1);
108108
} else {
109109
this.localName = fullName;

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

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.querydsl.ksp.codegen
22

3+
import com.google.devtools.ksp.isConstructor
34
import com.google.devtools.ksp.processing.CodeGenerator
45
import com.google.devtools.ksp.processing.Resolver
56
import com.google.devtools.ksp.processing.SymbolProcessor
@@ -17,9 +18,32 @@ class QueryDslProcessor(
1718
if (settings.enable) {
1819
QueryModelType.entries.forEach { type ->
1920
resolver.getSymbolsWithAnnotation(type.associatedAnnotation)
20-
.map { it as KSClassDeclaration }
21-
.filter { isIncluded(it) }
22-
.forEach { declaration -> typeProcessor.add(declaration, type) }
21+
.map { declaration ->
22+
when {
23+
type == QueryModelType.QUERY_PROJECTION -> {
24+
val errorMessage = "${type.associatedAnnotation} annotation" +
25+
" must be declared on a constructor function or class"
26+
when (declaration) {
27+
is KSFunctionDeclaration -> {
28+
if (!declaration.isConstructor()) error(errorMessage)
29+
declaration.parent as? KSClassDeclaration
30+
?: error(errorMessage)
31+
}
32+
33+
is KSClassDeclaration -> declaration
34+
else -> error(errorMessage)
35+
}
36+
}
37+
38+
else -> declaration as KSClassDeclaration
39+
}
40+
}
41+
.filter {
42+
isIncluded(it)
43+
}
44+
.forEach { declaration ->
45+
typeProcessor.add(declaration, type)
46+
}
2347
}
2448
}
2549
return emptyList()

0 commit comments

Comments
 (0)