Skip to content

Commit 94f4d1a

Browse files
authored
Merge branch 'master' into feature/execute-with-key-jpa-1692
2 parents da4215f + 3ad1e99 commit 94f4d1a

14 files changed

Lines changed: 317 additions & 34 deletions

File tree

pom.xml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
<junit.version>6.0.3</junit.version>
9797
<ecj.version>3.45.0</ecj.version>
9898
<jdo.version>3.2.1</jdo.version>
99-
<springboot.version>4.0.4</springboot.version>
99+
<springboot.version>4.0.5</springboot.version>
100100
<spring.version>7.0.6</spring.version>
101101

102102
<!-- SQL deps -->
@@ -109,15 +109,15 @@
109109
<mysql.version>9.6.0</mysql.version>
110110
<mssql.version>13.4.0.jre11</mssql.version>
111111
<cubrid.version>9.3.9.0002</cubrid.version>
112-
<sqlite.version>3.51.3.0</sqlite.version>
112+
<sqlite.version>3.53.0.0</sqlite.version>
113113
<teradata.version>13.10.00.35</teradata.version>
114-
<firebird.version>6.0.4</firebird.version>
115-
<mongodb.version>5.6.4</mongodb.version>
114+
<firebird.version>6.0.5</firebird.version>
115+
<mongodb.version>5.6.5</mongodb.version>
116116

117117
<r2dbc.version>1.0.0.RELEASE</r2dbc.version>
118118

119119
<!-- JPA deps -->
120-
<hibernate.version>7.2.6.Final</hibernate.version>
120+
<hibernate.version>7.3.1.Final</hibernate.version>
121121
<hibernate.validator.version>9.1.0.Final</hibernate.validator.version>
122122
<eclipselink.version>5.0.0-B13</eclipselink.version>
123123
<jpa.version>3.2.0</jpa.version>
@@ -127,7 +127,7 @@
127127
<mvn.version>3.9.14</mvn.version>
128128
<guava.version>33.5.0-jre</guava.version>
129129
<codegen.version>0.6.8</codegen.version>
130-
<byte-buddy.version>1.18.7</byte-buddy.version>
130+
<byte-buddy.version>1.18.8</byte-buddy.version>
131131
<slf4j.version>2.0.17</slf4j.version>
132132
<surefire.version>3.5.5</surefire.version>
133133
<animal-sniffer.version>1.27</animal-sniffer.version>
@@ -136,8 +136,8 @@
136136
<jmh.version>1.37</jmh.version>
137137
<kotlin.version>2.3.20</kotlin.version>
138138
<ksp.version>2.3.6</ksp.version>
139-
<kotlinpoet.version>2.2.0</kotlinpoet.version>
140-
<dokka.version>2.1.0</dokka.version>
139+
<kotlinpoet.version>2.3.0</kotlinpoet.version>
140+
<dokka.version>2.2.0</dokka.version>
141141
<scala.version>2.13.16</scala.version>
142142
<asm.version>9.9.1</asm.version>
143143
<querydsl.version>${project.version}</querydsl.version>
@@ -447,7 +447,7 @@
447447
<plugin>
448448
<groupId>com.github.siom79.japicmp</groupId>
449449
<artifactId>japicmp-maven-plugin</artifactId>
450-
<version>0.25.4</version>
450+
<version>0.25.5</version>
451451
<configuration>
452452
<parameter>
453453
<excludes>
@@ -586,7 +586,7 @@
586586
<plugin>
587587
<groupId>io.sundr</groupId>
588588
<artifactId>sundr-maven-plugin</artifactId>
589-
<version>0.230.2</version>
589+
<version>0.240.1</version>
590590
<inherited>false</inherited>
591591
<configuration>
592592
<boms>
@@ -1026,18 +1026,18 @@
10261026
<plugin>
10271027
<groupId>org.openrewrite.maven</groupId>
10281028
<artifactId>rewrite-maven-plugin</artifactId>
1029-
<version>6.34.0</version>
1029+
<version>6.36.0</version>
10301030

10311031
<dependencies>
10321032
<dependency>
10331033
<groupId>org.openrewrite.recipe</groupId>
10341034
<artifactId>rewrite-testing-frameworks</artifactId>
1035-
<version>3.30.0</version>
1035+
<version>3.34.0</version>
10361036
</dependency>
10371037
<dependency>
10381038
<groupId>org.openrewrite.recipe</groupId>
10391039
<artifactId>rewrite-migrate-java</artifactId>
1040-
<version>3.30.1</version>
1040+
<version>3.32.1</version>
10411041
</dependency>
10421042
</dependencies>
10431043

querydsl-examples/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
<dependency>
4444
<groupId>org.apache.logging.log4j</groupId>
4545
<artifactId>log4j-core</artifactId>
46-
<version>2.25.3</version>
46+
<version>2.25.4</version>
4747
</dependency>
4848
</dependencies>
4949
</dependencyManagement>

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.32.4</quarkus.version>
15+
<quarkus.version>3.34.3</quarkus.version>
1616
</properties>
1717

1818
<dependencyManagement>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,10 +427,10 @@ public Void visit(SubQueryExpression<?> query, Void context) {
427427
&& modifiers.isRestricting()
428428
&& templates.isSubQueryModifiersSupported()) {
429429
if (modifiers.getLimit() != null) {
430-
append(LIMIT).handle(modifiers.getLimit());
430+
append(LIMIT).handle(modifiers.getLimitAsInteger());
431431
}
432432
if (modifiers.getOffset() != null) {
433-
append(OFFSET).handle(modifiers.getOffset());
433+
append(OFFSET).handle(modifiers.getOffsetAsInteger());
434434
}
435435
}
436436

querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/hibernate/HibernateUtil.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,6 @@ private static void setValueWithNumberedLabel(
108108
query.setParameterList(key, collection);
109109
} else if (val instanceof Object[] objects && !BUILT_IN.contains(val.getClass())) {
110110
query.setParameterList(key, objects);
111-
} else if (val instanceof Number && TYPES.containsKey(val.getClass())) {
112-
query.setParameter(key, val, getType(val.getClass()));
113111
} else {
114112
query.setParameter(key, val);
115113
}

querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/impl/JPAUtil.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,20 @@
2929
*/
3030
public final class JPAUtil {
3131

32+
private static final Map<Class<?>, Class<?>> PRIMITIVE_TO_WRAPPER =
33+
Map.of(
34+
int.class, Integer.class,
35+
long.class, Long.class,
36+
double.class, Double.class,
37+
float.class, Float.class,
38+
short.class, Short.class,
39+
byte.class, Byte.class);
40+
41+
@SuppressWarnings("unchecked")
42+
private static <T extends Number> Class<T> primitiveToWrapper(Class<?> type) {
43+
return (Class<T>) PRIMITIVE_TO_WRAPPER.getOrDefault(type, type);
44+
}
45+
3246
private JPAUtil() {}
3347

3448
public static void setConstants(
@@ -50,8 +64,9 @@ public static void setConstants(
5064
Parameter parameter = query.getParameter(i + 1);
5165
var parameterType = parameter != null ? parameter.getParameterType() : null;
5266
if (parameterType != null && !parameterType.isInstance(val)) {
53-
if (val instanceof Number number && Number.class.isAssignableFrom(parameterType)) {
54-
val = MathUtils.cast(number, parameterType);
67+
var targetType = primitiveToWrapper(parameterType);
68+
if (val instanceof Number number && Number.class.isAssignableFrom(targetType)) {
69+
val = MathUtils.cast(number, targetType);
5570
}
5671
}
5772
}

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ public void visit_subQueryExpression_with_limit_hql() {
395395

396396
assertThat(serializer.toString()).isEqualTo("(select cat.id\nfrom Cat cat\nlimit ?1)");
397397
assertThat(serializer.getConstants()).hasSize(1);
398-
assertThat(serializer.getConstants().getFirst()).isEqualTo(5L);
398+
assertThat(serializer.getConstants().getFirst()).isEqualTo(5);
399399
}
400400

401401
@Test
@@ -418,7 +418,7 @@ public void visit_subQueryExpression_with_offset_hql() {
418418

419419
assertThat(serializer.toString()).isEqualTo("(select cat.id\nfrom Cat cat\noffset ?1)");
420420
assertThat(serializer.getConstants()).hasSize(1);
421-
assertThat(serializer.getConstants().getFirst()).isEqualTo(10L);
421+
assertThat(serializer.getConstants().getFirst()).isEqualTo(10);
422422
}
423423

424424
@Test
@@ -442,8 +442,8 @@ public void visit_subQueryExpression_with_limit_and_offset_hql() {
442442
assertThat(serializer.toString())
443443
.isEqualTo("(select cat.id\nfrom Cat cat\nlimit ?1\noffset ?2)");
444444
assertThat(serializer.getConstants()).hasSize(2);
445-
assertThat(serializer.getConstants().get(0)).isEqualTo(5L);
446-
assertThat(serializer.getConstants().get(1)).isEqualTo(10L);
445+
assertThat(serializer.getConstants().get(0)).isEqualTo(5);
446+
assertThat(serializer.getConstants().get(1)).isEqualTo(10);
447447
}
448448

449449
@Test
@@ -469,8 +469,8 @@ where cat.id in (select mate.id
469469
limit ?1)
470470
limit ?2)""");
471471
assertThat(serializer.getConstants()).hasSize(2);
472-
assertThat(serializer.getConstants().get(0)).isEqualTo(3L);
473-
assertThat(serializer.getConstants().get(1)).isEqualTo(5L);
472+
assertThat(serializer.getConstants().get(0)).isEqualTo(3);
473+
assertThat(serializer.getConstants().get(1)).isEqualTo(5);
474474
}
475475

476476
@Test
@@ -537,8 +537,8 @@ where cat.id in (select kitten.id
537537
limit ?1
538538
offset ?2)""");
539539
assertThat(hqlSerializer.getConstants()).hasSize(2);
540-
assertThat(hqlSerializer.getConstants().get(0)).isEqualTo(5L);
541-
assertThat(hqlSerializer.getConstants().get(1)).isEqualTo(10L);
540+
assertThat(hqlSerializer.getConstants().get(0)).isEqualTo(5);
541+
assertThat(hqlSerializer.getConstants().get(1)).isEqualTo(10);
542542
}
543543

544544
@Test
@@ -601,7 +601,7 @@ public void subquery_in_select_clause_with_modifiers_hql() {
601601
offset ?2)
602602
from Cat cat""");
603603
assertThat(hqlSerializer.getConstants()).hasSize(2);
604-
assertThat(hqlSerializer.getConstants().get(0)).isEqualTo(1L);
605-
assertThat(hqlSerializer.getConstants().get(1)).isEqualTo(2L);
604+
assertThat(hqlSerializer.getConstants().get(0)).isEqualTo(1);
605+
assertThat(hqlSerializer.getConstants().get(1)).isEqualTo(2);
606606
}
607607
}

querydsl-libraries/querydsl-sql/src/main/java/com/querydsl/sql/SQLExpressions.java

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,20 @@
2020
import com.querydsl.core.types.Ops;
2121
import com.querydsl.core.types.Path;
2222
import com.querydsl.core.types.SubQueryExpression;
23+
import com.querydsl.core.types.Template;
24+
import com.querydsl.core.types.TemplateFactory;
2325
import com.querydsl.core.types.dsl.BooleanExpression;
2426
import com.querydsl.core.types.dsl.DateExpression;
2527
import com.querydsl.core.types.dsl.DateTimeExpression;
2628
import com.querydsl.core.types.dsl.Expressions;
2729
import com.querydsl.core.types.dsl.NumberExpression;
30+
import com.querydsl.core.types.dsl.NumberTemplate;
2831
import com.querydsl.core.types.dsl.SimpleExpression;
32+
import com.querydsl.core.types.dsl.SimpleTemplate;
2933
import com.querydsl.core.types.dsl.StringExpression;
34+
import com.querydsl.core.types.dsl.StringTemplate;
3035
import com.querydsl.core.types.dsl.Wildcard;
36+
import java.util.Arrays;
3137
import java.util.EnumMap;
3238
import java.util.List;
3339
import java.util.Map;
@@ -278,6 +284,92 @@ public static <T> RelationalFunctionCall<T> relationalFunctionCall(
278284
return new RelationalFunctionCall<>(type, function, args);
279285
}
280286

287+
/**
288+
* Create a function call template string for the given function name and argument count.
289+
*
290+
* <p>The function name is inserted as-is, which allows fully qualified names such as {@code
291+
* schema.function}, {@code database.schema.function}, or {@code
292+
* linked_server.database.schema.function}.
293+
*
294+
* @param function function name (may contain dots for qualified names)
295+
* @param argCount number of arguments
296+
* @return template for the function call
297+
*/
298+
private static Template createFunctionCallTemplate(String function, int argCount) {
299+
var builder = new StringBuilder();
300+
builder.append(function);
301+
builder.append("(");
302+
for (var i = 0; i < argCount; i++) {
303+
if (i > 0) {
304+
builder.append(", ");
305+
}
306+
builder.append("{").append(i).append("}");
307+
}
308+
builder.append(")");
309+
return TemplateFactory.DEFAULT.create(builder.toString());
310+
}
311+
312+
/**
313+
* Create a scalar function call expression.
314+
*
315+
* <p>Unlike {@link #relationalFunctionCall(Class, String, Object...)}, this method creates a
316+
* scalar expression suitable for use in SELECT, WHERE, INSERT VALUES, and other non-FROM
317+
* contexts.
318+
*
319+
* <p>Supports fully qualified function names including cross-database calls:
320+
*
321+
* <ul>
322+
* <li>{@code function("my_function", arg)} &rarr; {@code my_function(?)}
323+
* <li>{@code function("dbo.my_function", arg1, arg2)} &rarr; {@code dbo.my_function(?, ?)}
324+
* <li>{@code function("other_db.dbo.my_function", arg)} &rarr; {@code
325+
* other_db.dbo.my_function(?)}
326+
* </ul>
327+
*
328+
* @param <T> return type
329+
* @param type return type class
330+
* @param function function name (may contain dots for schema-qualified names)
331+
* @param args function arguments
332+
* @return scalar function call expression
333+
*/
334+
public static <T> SimpleTemplate<T> function(
335+
Class<? extends T> type, String function, Object... args) {
336+
return Expressions.template(
337+
type, createFunctionCallTemplate(function, args.length), Arrays.asList(args));
338+
}
339+
340+
/**
341+
* Create a scalar function call expression that returns a String.
342+
*
343+
* <p>Supports fully qualified function names including cross-database calls.
344+
*
345+
* @param function function name (may contain dots for schema-qualified names)
346+
* @param args function arguments
347+
* @return string function call expression
348+
* @see #function(Class, String, Object...)
349+
*/
350+
public static StringTemplate stringFunction(String function, Object... args) {
351+
return Expressions.stringTemplate(
352+
createFunctionCallTemplate(function, args.length), Arrays.asList(args));
353+
}
354+
355+
/**
356+
* Create a scalar function call expression that returns a Number.
357+
*
358+
* <p>Supports fully qualified function names including cross-database calls.
359+
*
360+
* @param <T> number type
361+
* @param type return type class
362+
* @param function function name (may contain dots for schema-qualified names)
363+
* @param args function arguments
364+
* @return number function call expression
365+
* @see #function(Class, String, Object...)
366+
*/
367+
public static <T extends Number & Comparable<?>> NumberTemplate<T> numberFunction(
368+
Class<? extends T> type, String function, Object... args) {
369+
return Expressions.numberTemplate(
370+
type, createFunctionCallTemplate(function, args.length), Arrays.asList(args));
371+
}
372+
281373
/**
282374
* Create a nextval(sequence) expression
283375
*

0 commit comments

Comments
 (0)