diff --git a/api/src/main/java/jakarta/persistence/ArgumentRecord.java b/api/src/main/java/jakarta/persistence/ArgumentRecord.java new file mode 100644 index 000000000..56e152122 --- /dev/null +++ b/api/src/main/java/jakarta/persistence/ArgumentRecord.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2026 Contributors to the Eclipse Foundation + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, + * or the Eclipse Distribution License v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ +package jakarta.persistence; + +import jakarta.annotation.Nonnull; + +import static java.util.Objects.requireNonNull; + +/** + * Internal implementation of {@link Parameter.Argument}. + * @param the type of the parameter + * @param parameter the parameter + * @param value the argument bound to the parameter + * @since 4.0 + */ +record ArgumentRecord(@Nonnull Parameter parameter, T value) + implements Parameter.Argument { + + ArgumentRecord { + requireNonNull(parameter, "parameter must not be null"); + } + + @Nonnull + @Override + public Parameter getParameter() { + return parameter; + } + + @Override + public T getValue() { + return value; + } +} diff --git a/api/src/main/java/jakarta/persistence/Parameter.java b/api/src/main/java/jakarta/persistence/Parameter.java index fb81db64b..235d85497 100644 --- a/api/src/main/java/jakarta/persistence/Parameter.java +++ b/api/src/main/java/jakarta/persistence/Parameter.java @@ -91,4 +91,54 @@ public interface Parameter { */ @Nonnull Class getParameterType(); + + /** + * Create a new instance with the given type, position, and name. + * @param type the Java type of the parameter + * @param position the position of the parameter, or null if the + * parameter is not a positional parameter + * @param name the name of the parameter, or null if the parameter + * is not a named parameter + * @return a new instance + * @param the type of the parameter + * @since 4.0 + */ + @Nonnull + static Parameter of(@Nonnull Class type, + @Nullable Integer position, + @Nullable String name) { + return new ParameterRecord<>(type, position, name); + } + + /** + * Packages a parameter with its argument. + * @param the type of the parameter + * @since 4.0 + */ + interface Argument { + /** + * The parameter. + * @return the parameter + */ + @Nonnull + Parameter getParameter(); + + /** + * The argument bound to the parameter. + * @return the argument value + */ + T getValue(); + } + + /** + * Return a new {@link Argument} binding this parameter + * to the given argument value. + * @param argument the argument bound to this parameter + * @return a tuple entry + * @since 4.0 + */ + @Nonnull + default Argument bind(T argument) { + return new ArgumentRecord<>(this, argument); + } } diff --git a/api/src/main/java/jakarta/persistence/ParameterRecord.java b/api/src/main/java/jakarta/persistence/ParameterRecord.java new file mode 100644 index 000000000..d7d845ae5 --- /dev/null +++ b/api/src/main/java/jakarta/persistence/ParameterRecord.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2026 Contributors to the Eclipse Foundation + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, + * or the Eclipse Distribution License v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ +package jakarta.persistence; + +import jakarta.annotation.Nonnull; +import jakarta.annotation.Nullable; + +/** + * Internal implementation of {@link Parameter}. + * @param type the Java type of the parameter + * @param position the position of the parameter, or null if the + * parameter is not a positional parameter + * @param name the name of the parameter, or null if the parameter + * is not a named parameter + * @param the type of the parameter + * @see Parameter#of(Class, Integer, String) + * @since 4.0 + */ +record ParameterRecord + (@Nonnull Class type, @Nullable Integer position, @Nullable String name) + implements Parameter { + @Nullable + @Override + public String getName() { + return name; + } + + @Nullable + @Override + public Integer getPosition() { + return position; + } + + @Nonnull + @Override + public Class getParameterType() { + return type; + } +} diff --git a/api/src/main/java/jakarta/persistence/Query.java b/api/src/main/java/jakarta/persistence/Query.java index 343115acf..2274e26ec 100644 --- a/api/src/main/java/jakarta/persistence/Query.java +++ b/api/src/main/java/jakarta/persistence/Query.java @@ -699,6 +699,31 @@ Query setParameter(int position, @Nullable Date value, @Nonnull Query setParameters(@Nonnull Object... arguments); + /** + * Bind an argument to a parameter of the query. + * @param argument The argument to bind + * @return the same query instance + * @throws IllegalArgumentException if one of arguments does + * not match a parameter of the query + * @since 4.0 + */ + @Nonnull + Query setArgument(@Nonnull Parameter.Argument argument); + + /** + * Bind arguments to the parameters of the query. + * @param arguments The arguments to bind + * @return the same query instance + * @throws IllegalArgumentException if the number of arguments + * is not exactly the same as the number of parameters, + * if one of arguments does not match a parameter of + * the query, or if multiple arguments are provided + * for the same parameter + * @since 4.0 + */ + @Nonnull + Query setArguments(@Nonnull List> arguments); + /** * Get the {@link Parameter} objects representing the declared * parameters of the query or an empty set if the query has no diff --git a/api/src/main/java/jakarta/persistence/Reference.java b/api/src/main/java/jakarta/persistence/Reference.java index c41d0b3dc..c08270113 100644 --- a/api/src/main/java/jakarta/persistence/Reference.java +++ b/api/src/main/java/jakarta/persistence/Reference.java @@ -59,8 +59,7 @@ public sealed interface Reference * to a statement or query declared using an annotation of a * method. *

- * Any mutation of the returned list results in an - * {@link UnsupportedOperationException}. + * Mutation of the returned list does not affect the reference. * * @since 4.0 */ @@ -77,8 +76,7 @@ public sealed interface Reference * interpreted as the parameter names. Otherwise, if the * query has positional parameters, they are ignored. *

- * Any mutation of the returned list results in an - * {@link UnsupportedOperationException}. + * Mutation of the returned list does not affect the reference. * * @since 4.0 */ @@ -100,8 +98,7 @@ public sealed interface Reference * obtain an assignment of arguments to parameters. * *

- * Any mutation of the returned list results in an - * {@link UnsupportedOperationException}. + * Mutation of the returned list does not affect the reference. * * @see Query#setParameter(int, Object) * @see Query#setParameter(String, Object) @@ -110,6 +107,33 @@ public sealed interface Reference @Nullable List getArguments(); + /** + * The parameters of the statement or query when arguments + * to the parameters were supplied, or {@code null} if no + * arguments were supplied. Arguments are present when this + * is a reference to a statement or query declared using an + * annotation of a method. + *

+ * Mutation of the returned list does not affect the reference. + * + * @since 4.0 + */ + @Nullable + List> getParameters(); + + /** + * The arguments supplied to the parameters of the statement + * or query, or {@code null} if no arguments were supplied. + * Arguments are present when this is a reference to a query + * declared using an annotation of a method. + * + * @see Query#setArgument(Parameter.Argument) + * + * @since 4.0 + */ + @Nullable + List> getParameterArguments(); + /** * A map keyed by hint name of all hints specified via * {@link NamedQuery#hints}, {@link NamedNativeQuery#hints}, @@ -117,8 +141,7 @@ public sealed interface Reference * {@link jakarta.persistence.query.QueryOptions#hints}, or * {@link jakarta.persistence.query.StatementOptions#hints}. *

- * Any attempted mutation of the returned map results in an - * {@link UnsupportedOperationException}. + * Mutation of the returned map does not affect the reference. */ @Nonnull Map getHints(); diff --git a/api/src/main/java/jakarta/persistence/Statement.java b/api/src/main/java/jakarta/persistence/Statement.java index c2abfc503..f44895540 100644 --- a/api/src/main/java/jakarta/persistence/Statement.java +++ b/api/src/main/java/jakarta/persistence/Statement.java @@ -21,6 +21,7 @@ import java.util.Calendar; import java.util.Date; +import java.util.List; import java.util.Set; /** @@ -494,6 +495,14 @@ Statement setParameter(int position, @Nullable Date value, @Override Statement setParameters(@Nonnull Object... arguments); + @Nonnull + @Override + Statement setArgument(@Nonnull Parameter.Argument argument); + + @Nonnull + @Override + Statement setArguments(@Nonnull List> arguments); + /** * Specify an {@linkplain Option option} influencing execution * of this statement, overwriting any existing option of the diff --git a/api/src/main/java/jakarta/persistence/StatementOrTypedQuery.java b/api/src/main/java/jakarta/persistence/StatementOrTypedQuery.java index 6cd72f440..06cc4c338 100644 --- a/api/src/main/java/jakarta/persistence/StatementOrTypedQuery.java +++ b/api/src/main/java/jakarta/persistence/StatementOrTypedQuery.java @@ -20,6 +20,8 @@ import jakarta.persistence.metamodel.Type; import jakarta.persistence.sql.ResultSetMapping; +import java.util.List; + /** * Declares operations allowing a {@link Statement} or {@link TypedQuery} * to be obtained when the type of a query or statement has not yet been @@ -184,6 +186,14 @@

StatementOrTypedQuery setConvertedParameter(int position, @Nullable P value, @Override StatementOrTypedQuery setParameters(@Nonnull Object... arguments); + @Nonnull + @Override + StatementOrTypedQuery setArgument(@Nonnull Parameter.Argument argument); + + @Nonnull + @Override + StatementOrTypedQuery setArguments(@Nonnull List> arguments); + @Nonnull @Override StatementOrTypedQuery setQueryFlushMode(@Nonnull QueryFlushMode flushMode); diff --git a/api/src/main/java/jakarta/persistence/StoredProcedureQuery.java b/api/src/main/java/jakarta/persistence/StoredProcedureQuery.java index 8f23e7941..48f4a715a 100644 --- a/api/src/main/java/jakarta/persistence/StoredProcedureQuery.java +++ b/api/src/main/java/jakarta/persistence/StoredProcedureQuery.java @@ -425,6 +425,14 @@

StoredProcedureQuery setConvertedParameter(int position, @Nullable P value, @Override StoredProcedureQuery setParameters(@Nonnull Object... arguments); + @Nonnull + @Override + StoredProcedureQuery setArgument(@Nonnull Parameter.Argument argument); + + @Nonnull + @Override + StoredProcedureQuery setArguments(@Nonnull List> arguments); + /** * Set the {@linkplain QueryFlushMode query flush mode} to be * used when the query is executed. This flush mode overrides diff --git a/api/src/main/java/jakarta/persistence/Tuple.java b/api/src/main/java/jakarta/persistence/Tuple.java index 630c68c00..8a87f4b64 100644 --- a/api/src/main/java/jakarta/persistence/Tuple.java +++ b/api/src/main/java/jakarta/persistence/Tuple.java @@ -20,13 +20,15 @@ import java.util.List; +import static java.util.Arrays.asList; + /** * Interface for extracting the elements of a query result tuple. * A {@code Tuple} may be used to represent a query result row * containing multiple projected values. *

* This example uses a criteria query to select the title and - * publication date of each book, and then reuses the projected + * publication date of each book and then reuses the projected * {@link TupleElement}s to extract the results: * {@snippet : * var builder = factory.getCriteriaBuilder(); @@ -117,8 +119,7 @@ public interface Tuple { Object get(int i); /** - * Return the values of the result tuple elements as - * an array. + * Return the tuple element values as an array. * @return tuple element values */ @Nonnull @@ -130,4 +131,53 @@ public interface Tuple { */ @Nonnull List> getElements(); + + /** + * Return the number of elements of this tuple. + * @return length of tuple + * @since 4.0 + */ + default int length() { + return getElements().size(); + } + + /** + * Return the tuple element values as a list. + * @return tuple element values + * @since 4.0 + */ + @Nonnull + default List getValues() { + return asList(toArray()); + } + + /** + * Return the tuple element types. + * @return tuple element types + * @since 4.0 + */ + @Nonnull + default List> getElementTypes() { + final var elements = getElements(); + final var types = new Class[elements.size()]; + for (int i = 0; i < elements.size(); i++) { + types[i] = elements.get(i).getJavaType(); + } + return asList(types); + } + + /** + * Return the tuple element aliases. + * @return tuple element aliases + * @since 4.0 + */ + @Nonnull + default List getAliases() { + final var elements = getElements(); + final var aliases = new String[elements.size()]; + for (int i = 0; i < elements.size(); i++) { + aliases[i] = elements.get(i).getAlias(); + } + return asList(aliases); + } } diff --git a/api/src/main/java/jakarta/persistence/TupleElement.java b/api/src/main/java/jakarta/persistence/TupleElement.java index 6553ac645..20ea0c87f 100644 --- a/api/src/main/java/jakarta/persistence/TupleElement.java +++ b/api/src/main/java/jakarta/persistence/TupleElement.java @@ -19,6 +19,8 @@ import jakarta.annotation.Nonnull; import jakarta.annotation.Nullable; +import static java.util.Objects.requireNonNull; + /** * The {@code TupleElement} interface defines an element that is * returned in a query result tuple. @@ -39,10 +41,26 @@ public interface TupleElement { Class getJavaType(); /** - * Return the alias assigned to the tuple element or null, - * if no alias has been assigned. + * Return the alias assigned to the tuple element + * or null if no alias has been assigned. * @return alias */ @Nullable String getAlias(); + + /** + * Determine whether the given alias has been + * assigned to this tuple element. + * @param alias an alias against which to compare the alias of the tuple element + * @return true if an alias has been assigned to + * this element, and it matches the given + * alias, or false otherwise + * @since 4.0 + */ + default boolean hasAlias(@Nonnull String alias) { + requireNonNull(alias, "given alias must not be null"); + final var assignedAlias = getAlias(); + return assignedAlias != null + && assignedAlias.equals(alias); + } } diff --git a/api/src/main/java/jakarta/persistence/TypedQuery.java b/api/src/main/java/jakarta/persistence/TypedQuery.java index a02dff5e2..30e187e7b 100644 --- a/api/src/main/java/jakarta/persistence/TypedQuery.java +++ b/api/src/main/java/jakarta/persistence/TypedQuery.java @@ -640,6 +640,14 @@ TypedQuery setParameter(int position, @Nullable Date value, @Override TypedQuery setParameters(@Nonnull Object... arguments); + @Nonnull + @Override + TypedQuery setArgument(@Nonnull Parameter.Argument argument); + + @Nonnull + @Override + TypedQuery setArguments(@Nonnull List> arguments); + /** * Set the {@linkplain QueryFlushMode query flush mode} to be * used when the query is executed. This flush mode overrides diff --git a/api/src/main/java/jakarta/persistence/query/StaticStatementReference.java b/api/src/main/java/jakarta/persistence/query/StaticStatementReference.java index e822c9410..076aae811 100644 --- a/api/src/main/java/jakarta/persistence/query/StaticStatementReference.java +++ b/api/src/main/java/jakarta/persistence/query/StaticStatementReference.java @@ -16,12 +16,19 @@ package jakarta.persistence.query; import jakarta.annotation.Nonnull; -import jakarta.persistence.Statement; -import jakarta.persistence.StatementReference; +import jakarta.persistence.*; +import jakarta.persistence.Parameter.Argument; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; import static java.util.Collections.emptyMap; +import static java.util.stream.Collectors.toCollection; /** * A reference to a statement declared using a {@link JakartaStatement} @@ -38,9 +45,7 @@ public class StaticStatementReference @Nonnull private final Class annotatedClass; @Nonnull private final String annotatedMemberName; @Nonnull private final String name; - @Nonnull private final List> parameterTypes; - @Nonnull private final List parameterNames; - @Nonnull private final List arguments; + @Nonnull private final List> arguments; @Nonnull private final Map hints; @Nonnull private final Set options; @@ -59,10 +64,6 @@ public class StaticStatementReference * separated by commas * @param annotatedClass The annotated class * @param annotatedMemberName The name of the annotated member - * @param parameterTypes The types of the parameters of the - * annotated member - * @param parameterNames The names of the parameters of the - * annotated member * @param arguments The arguments supplied to the parameters * at runtime * @param hints See {@link StatementOptions#hints} @@ -72,17 +73,13 @@ public StaticStatementReference( @Nonnull String statementName, @Nonnull Class annotatedClass, @Nonnull String annotatedMemberName, - @Nonnull List> parameterTypes, - @Nonnull List parameterNames, - @Nonnull List arguments, + @Nonnull List> arguments, @Nonnull Map hints, @Nonnull Statement.Option... options) { this.name = statementName; this.annotatedClass = annotatedClass; this.annotatedMemberName = annotatedMemberName; - this.parameterTypes = parameterTypes; - this.parameterNames = parameterNames; - this.arguments = arguments; + this.arguments = List.copyOf(arguments); this.hints = hints; this.options = Set.of(options); } @@ -102,10 +99,6 @@ public StaticStatementReference( * separated by commas * @param annotatedClass The annotated class * @param annotatedMemberName The name of the annotated member - * @param parameterTypes The types of the parameters of the - * annotated member - * @param parameterNames The names of the parameters of the - * annotated member * @param arguments The arguments supplied to the parameters * at runtime */ @@ -113,12 +106,9 @@ public StaticStatementReference( @Nonnull String statementName, @Nonnull Class annotatedClass, @Nonnull String annotatedMemberName, - @Nonnull List> parameterTypes, - @Nonnull List parameterNames, - @Nonnull List arguments) { + @Nonnull List> arguments) { this(statementName, annotatedClass, annotatedMemberName, - parameterTypes, parameterNames, arguments, - emptyMap()); + arguments, emptyMap()); } @Override @@ -130,25 +120,50 @@ public String getName() { @Override @Nonnull public Map getHints() { - return hints; + return new HashMap<>(hints); } @Override @Nonnull public List> getParameterTypes() { - return parameterTypes; + List> list = new ArrayList<>(); + for (var arg : arguments) { + list.add( arg.getParameter().getParameterType() ); + } + return list; } @Override @Nonnull public List getParameterNames() { - return parameterNames; + List list = new ArrayList<>(); + for (var arg : arguments) { + list.add( arg.getParameter().getName() ); + } + return list; } @Override @Nonnull public List getArguments() { - return arguments; + List list = new ArrayList<>(); + for (var arg : arguments) { + list.add( arg.getValue() ); + } + return list; + } + + @Override + @Nonnull + public List> getParameterArguments() { + return new ArrayList<>(arguments); + } + + @Override + @Nonnull + public List> getParameters() { + return arguments.stream().map(Argument::getParameter) + .collect(toCollection(ArrayList::new)); } @Nonnull @@ -177,8 +192,6 @@ else if ((!(obj instanceof StaticStatementReference that))) { } else { return Objects.equals(this.name, that.name) - && Objects.equals(this.parameterTypes, that.parameterTypes) - && Objects.equals(this.parameterNames, that.parameterNames) && Objects.equals(this.arguments, that.arguments) && Objects.equals(this.options, that.options) && Objects.equals(this.hints, that.hints); @@ -187,14 +200,13 @@ else if ((!(obj instanceof StaticStatementReference that))) { @Override public int hashCode() { - return Objects.hash(name, parameterTypes, parameterNames, arguments); + return Objects.hash(name, arguments); } @Override public String toString() { return "StaticStatementReference[" + "name=" + name + ", " - + "parameterNames=" + parameterNames + ", " + "arguments=" + arguments + ", " + "options=" + options + ", " + "hints=" + hints diff --git a/api/src/main/java/jakarta/persistence/query/StaticTypedQueryReference.java b/api/src/main/java/jakarta/persistence/query/StaticTypedQueryReference.java index fa22b7aaa..7530339a3 100644 --- a/api/src/main/java/jakarta/persistence/query/StaticTypedQueryReference.java +++ b/api/src/main/java/jakarta/persistence/query/StaticTypedQueryReference.java @@ -17,9 +17,13 @@ import jakarta.annotation.Nonnull; import jakarta.annotation.Nullable; +import jakarta.persistence.Parameter; +import jakarta.persistence.Parameter.Argument; import jakarta.persistence.TypedQuery; import jakarta.persistence.TypedQueryReference; +import java.util.ArrayList; +import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -27,6 +31,7 @@ import java.util.Set; import static java.util.Collections.emptyMap; +import static java.util.stream.Collectors.toCollection; /** * A reference to a query declared using a {@link JakartaQuery} @@ -46,9 +51,7 @@ public class StaticTypedQueryReference @Nonnull private final String annotatedMemberName; @Nullable private final Class resultType; @Nonnull private final String name; - @Nonnull private final List> parameterTypes; - @Nonnull private final List parameterNames; - @Nonnull private final List arguments; + @Nonnull private final List> arguments; @Nullable private final String entityGraphName; @Nonnull private final Map hints; @Nonnull private final Set options; @@ -69,10 +72,6 @@ public class StaticTypedQueryReference * @param annotatedMemberName The name of the annotated member * @param resultType The result type of the query, the type of * the annotated member - * @param parameterTypes The types of the parameters of the - * annotated member - * @param parameterNames The names of the parameters of the - * annotated member * @param arguments The arguments supplied to the parameters * at runtime * @param entityGraphName See {@link QueryOptions#entityGraph} @@ -84,9 +83,7 @@ public StaticTypedQueryReference( @Nonnull Class annotatedClass, @Nonnull String annotatedMemberName, @Nullable Class resultType, - @Nonnull List> parameterTypes, - @Nonnull List parameterNames, - @Nonnull List arguments, + @Nonnull List> arguments, @Nullable String entityGraphName, @Nonnull Map hints, @Nonnull TypedQuery.Option... options) { @@ -94,9 +91,7 @@ public StaticTypedQueryReference( this.annotatedClass = annotatedClass; this.annotatedMemberName = annotatedMemberName; this.resultType = resultType; - this.parameterTypes = parameterTypes; - this.parameterNames = parameterNames; - this.arguments = arguments; + this.arguments = List.copyOf(arguments); this.entityGraphName = entityGraphName; this.hints = hints; this.options = Set.of(options); @@ -118,10 +113,6 @@ public StaticTypedQueryReference( * @param annotatedMemberName The name of the annotated member * @param resultType The result type of the query, the type of * the annotated member - * @param parameterTypes The types of the parameters of the - * annotated member - * @param parameterNames The names of the parameters of the - * annotated member * @param arguments The arguments supplied to the parameters * at runtime */ @@ -130,12 +121,9 @@ public StaticTypedQueryReference( @Nonnull Class annotatedClass, @Nonnull String annotatedMemberName, @Nonnull Class resultType, - @Nonnull List> parameterTypes, - @Nonnull List parameterNames, - @Nonnull List arguments) { + @Nonnull List> arguments) { this(queryName, annotatedClass, annotatedMemberName, resultType, - parameterTypes, parameterNames, arguments, - null, emptyMap()); + arguments, null, emptyMap()); } @Override @@ -153,25 +141,50 @@ public Class getResultType() { @Override @Nonnull public Map getHints() { - return hints; + return new HashMap<>(hints); } @Override @Nonnull public List> getParameterTypes() { - return parameterTypes; + List> list = new ArrayList<>(); + for (var arg : arguments) { + list.add( arg.getParameter().getParameterType() ); + } + return list; } @Override @Nonnull public List getParameterNames() { - return parameterNames; + List list = new ArrayList<>(); + for (var arg : arguments) { + list.add( arg.getParameter().getName() ); + } + return list; } @Override @Nonnull public List getArguments() { - return arguments; + List list = new ArrayList<>(); + for (var arg : arguments) { + list.add( arg.getValue() ); + } + return list; + } + + @Override + @Nonnull + public List> getParameterArguments() { + return new ArrayList<>(arguments); + } + + @Override + @Nonnull + public List> getParameters() { + return arguments.stream().map(Argument::getParameter) + .collect(toCollection(ArrayList::new)); } @Nonnull @@ -207,8 +220,6 @@ else if ((!(obj instanceof StaticTypedQueryReference that))) { else { return Objects.equals(this.resultType, that.resultType) && Objects.equals(this.name, that.name) - && Objects.equals(this.parameterTypes, that.parameterTypes) - && Objects.equals(this.parameterNames, that.parameterNames) && Objects.equals(this.arguments, that.arguments) && Objects.equals(this.options, that.options) && Objects.equals(this.hints, that.hints); @@ -217,7 +228,7 @@ else if ((!(obj instanceof StaticTypedQueryReference that))) { @Override public int hashCode() { - return Objects.hash(resultType, name, parameterTypes, parameterNames, arguments); + return Objects.hash(resultType, name, arguments); } @Override @@ -225,9 +236,8 @@ public String toString() { return "StaticTypedQueryReference[" + "resultType=" + resultType + ", " + "name=" + name + ", " - + "parameterNames=" + parameterNames + ", " + "arguments=" + arguments + ", " - + "options=" + options + + "options=" + options + ", " + "hints=" + hints + ']'; } diff --git a/spec/src/main/asciidoc/ch05-metamodel-api.adoc b/spec/src/main/asciidoc/ch05-metamodel-api.adoc index 3b25eae08..b600844c1 100644 --- a/spec/src/main/asciidoc/ch05-metamodel-api.adoc +++ b/spec/src/main/asciidoc/ch05-metamodel-api.adoc @@ -238,14 +238,13 @@ or `@NativeQuery`, the metamodel class must contain a declaration as follows: [source,java] ---- public static TypedQueryReference m(T1 p1, T2 p2, ...) { - return new StaticTypedQueryReference( + return new StaticTypedQueryReference<>( "X#m(T1,T2,...)", X.class, "m", R.class, - List.of(T1.class, T2.class, ... ), - List.of("p1", "p2", ... ), - List.of(p1, p2, ... ), + List.of(Parameter.of(T1.class, 1, "p1").bind(p1), + Parameter.of(T2.class, 2, "p2").bind(p2), ...), g, Map.of("h1", v1, "h2", v2, ...), o1, o2, o3, ... @@ -277,9 +276,8 @@ public static StatementReference m(T1 p1, T2 p2, ...) { "X#m(T1,T2,...)", X.class, "m", - List.of(T1.class, T2.class, ... ), - List.of("p1", "p2", ... ), - List.of(p1, p2, ... ), + List.of(Parameter.of(T1.class, 1, "p1").bind(p1), + Parameter.of(T2.class, 2, "p2").bind(p2), ...), Map.of("h1", v1, "h2", v2, ...), o1, o2, o3, ... ); diff --git a/tck/common/src/main/java/ee/jakarta/tck/persistence/common/pluggability/altprovider/implementation/QueryImpl.java b/tck/common/src/main/java/ee/jakarta/tck/persistence/common/pluggability/altprovider/implementation/QueryImpl.java index 5cdec1fb9..0a330ffa0 100755 --- a/tck/common/src/main/java/ee/jakarta/tck/persistence/common/pluggability/altprovider/implementation/QueryImpl.java +++ b/tck/common/src/main/java/ee/jakarta/tck/persistence/common/pluggability/altprovider/implementation/QueryImpl.java @@ -33,8 +33,8 @@ import jakarta.persistence.Parameter; import jakarta.persistence.PessimisticLockScope; import jakarta.persistence.QueryFlushMode; -import jakarta.persistence.StatementOrTypedQuery; import jakarta.persistence.Statement; +import jakarta.persistence.StatementOrTypedQuery; import jakarta.persistence.TemporalType; import jakarta.persistence.Timeout; import jakarta.persistence.TypedQuery; @@ -383,6 +383,18 @@ public TypedQuery setParameter(@Nonnull Parameter arg0, Date arg1, @Non return this; } + @Override + @Nonnull + public QueryImpl setArgument(@Nonnull Parameter.Argument argument) { + return this; + } + + @Override + @Nonnull + public QueryImpl setArguments(@Nonnull List> arguments) { + return this; + } + @Override @Nonnull public TypedQuery addOption(@Nonnull Option option) { diff --git a/tck/spec-tests/src/main/resources/ee/jakarta/tck/persistence/signaturetest/jakarta.persistence.sig_4.0 b/tck/spec-tests/src/main/resources/ee/jakarta/tck/persistence/signaturetest/jakarta.persistence.sig_4.0 index abf1947a5..e5827678f 100644 --- a/tck/spec-tests/src/main/resources/ee/jakarta/tck/persistence/signaturetest/jakarta.persistence.sig_4.0 +++ b/tck/spec-tests/src/main/resources/ee/jakarta/tck/persistence/signaturetest/jakarta.persistence.sig_4.0 @@ -1346,12 +1346,26 @@ meth public abstract !hasdefault java.lang.String name() meth public abstract !hasdefault java.lang.String options() CLSS public abstract interface jakarta.persistence.Parameter<%0 extends java.lang.Object> +innr public abstract interface static Argument meth public abstract java.lang.Class<{jakarta.persistence.Parameter%0}> getParameterType() anno 0 jakarta.annotation.Nonnull() meth public abstract java.lang.Integer getPosition() anno 0 jakarta.annotation.Nullable() meth public abstract java.lang.String getName() anno 0 jakarta.annotation.Nullable() +meth public jakarta.persistence.Parameter$Argument<{jakarta.persistence.Parameter%0}> bind({jakarta.persistence.Parameter%0}) + anno 0 jakarta.annotation.Nonnull() +meth public static <%0 extends java.lang.Object> jakarta.persistence.Parameter<{%%0}> of(java.lang.Class<{%%0}>,java.lang.Integer,java.lang.String) + anno 0 jakarta.annotation.Nonnull() + anno 1 jakarta.annotation.Nonnull() + anno 2 jakarta.annotation.Nullable() + anno 3 jakarta.annotation.Nullable() + +CLSS public abstract interface static jakarta.persistence.Parameter$Argument<%0 extends java.lang.Object> + outer jakarta.persistence.Parameter +meth public abstract jakarta.persistence.Parameter<{jakarta.persistence.Parameter$Argument%0}> getParameter() + anno 0 jakarta.annotation.Nonnull() +meth public abstract {jakarta.persistence.Parameter$Argument%0} getValue() CLSS public final !enum jakarta.persistence.ParameterMode fld public final static jakarta.persistence.ParameterMode IN @@ -1855,6 +1869,12 @@ meth public abstract jakarta.persistence.Parameter getParameter(int) meth public abstract jakarta.persistence.Parameter getParameter(java.lang.String) anno 0 jakarta.annotation.Nonnull() anno 1 jakarta.annotation.Nonnull() +meth public abstract jakarta.persistence.Query setArgument(jakarta.persistence.Parameter$Argument) + anno 0 jakarta.annotation.Nonnull() + anno 1 jakarta.annotation.Nonnull() +meth public abstract jakarta.persistence.Query setArguments(java.util.List>) + anno 0 jakarta.annotation.Nonnull() + anno 1 jakarta.annotation.Nonnull() meth public abstract jakarta.persistence.Query setCacheRetrieveMode(jakarta.persistence.CacheRetrieveMode) anno 0 jakarta.annotation.Nonnull() anno 0 java.lang.Deprecated(boolean forRemoval=true, java.lang.String since="4.0") @@ -1988,6 +2008,10 @@ hfds query CLSS public abstract interface jakarta.persistence.Reference meth public abstract java.lang.String getName() anno 0 jakarta.annotation.Nullable() +meth public abstract java.util.List> getParameterArguments() + anno 0 jakarta.annotation.Nullable() +meth public abstract java.util.List> getParameters() + anno 0 jakarta.annotation.Nullable() meth public abstract java.util.List> getParameterTypes() anno 0 jakarta.annotation.Nullable() meth public abstract java.util.List getArguments() @@ -2139,6 +2163,12 @@ meth public abstract int execute() meth public abstract jakarta.persistence.Statement addOption(jakarta.persistence.Statement$Option) anno 0 jakarta.annotation.Nonnull() anno 1 jakarta.annotation.Nonnull() +meth public abstract jakarta.persistence.Statement setArgument(jakarta.persistence.Parameter$Argument) + anno 0 jakarta.annotation.Nonnull() + anno 1 jakarta.annotation.Nonnull() +meth public abstract jakarta.persistence.Statement setArguments(java.util.List>) + anno 0 jakarta.annotation.Nonnull() + anno 1 jakarta.annotation.Nonnull() meth public abstract jakarta.persistence.Statement setFlushMode(jakarta.persistence.FlushModeType) anno 0 jakarta.annotation.Nonnull() anno 0 java.lang.Deprecated(boolean forRemoval=false, java.lang.String since="") @@ -2250,6 +2280,12 @@ meth public abstract <%0 extends java.lang.Object> jakarta.persistence.TypedQuer anno 1 jakarta.annotation.Nonnull() meth public abstract jakarta.persistence.Statement asStatement() anno 0 jakarta.annotation.Nonnull() +meth public abstract jakarta.persistence.StatementOrTypedQuery setArgument(jakarta.persistence.Parameter$Argument) + anno 0 jakarta.annotation.Nonnull() + anno 1 jakarta.annotation.Nonnull() +meth public abstract jakarta.persistence.StatementOrTypedQuery setArguments(java.util.List>) + anno 0 jakarta.annotation.Nonnull() + anno 1 jakarta.annotation.Nonnull() meth public abstract jakarta.persistence.StatementOrTypedQuery setHint(java.lang.String,java.lang.Object) anno 0 jakarta.annotation.Nonnull() anno 1 jakarta.annotation.Nonnull() @@ -2379,6 +2415,12 @@ meth public abstract jakarta.persistence.StoredProcedureQuery registerStoredProc anno 1 jakarta.annotation.Nonnull() anno 2 jakarta.annotation.Nonnull() anno 3 jakarta.annotation.Nonnull() +meth public abstract jakarta.persistence.StoredProcedureQuery setArgument(jakarta.persistence.Parameter$Argument) + anno 0 jakarta.annotation.Nonnull() + anno 1 jakarta.annotation.Nonnull() +meth public abstract jakarta.persistence.StoredProcedureQuery setArguments(java.util.List>) + anno 0 jakarta.annotation.Nonnull() + anno 1 jakarta.annotation.Nonnull() meth public abstract jakarta.persistence.StoredProcedureQuery setCacheRetrieveMode(jakarta.persistence.CacheRetrieveMode) anno 0 jakarta.annotation.Nonnull() anno 1 jakarta.annotation.Nonnull() @@ -2576,12 +2618,21 @@ meth public abstract java.lang.Object[] toArray() anno 0 jakarta.annotation.Nonnull() meth public abstract java.util.List> getElements() anno 0 jakarta.annotation.Nonnull() +meth public int length() +meth public java.util.List> getElementTypes() + anno 0 jakarta.annotation.Nonnull() +meth public java.util.List getValues() + anno 0 jakarta.annotation.Nonnull() +meth public java.util.List getAliases() + anno 0 jakarta.annotation.Nonnull() CLSS public abstract interface jakarta.persistence.TupleElement<%0 extends java.lang.Object> meth public abstract java.lang.Class getJavaType() anno 0 jakarta.annotation.Nonnull() meth public abstract java.lang.String getAlias() anno 0 jakarta.annotation.Nullable() +meth public boolean hasAlias(java.lang.String) + anno 1 jakarta.annotation.Nonnull() CLSS public abstract interface jakarta.persistence.TypedQuery<%0 extends java.lang.Object> innr public abstract interface static Option @@ -2635,6 +2686,12 @@ meth public abstract jakarta.persistence.PessimisticLockScope getLockScope() meth public abstract jakarta.persistence.TypedQuery<{jakarta.persistence.TypedQuery%0}> addOption(jakarta.persistence.TypedQuery$Option) anno 0 jakarta.annotation.Nonnull() anno 1 jakarta.annotation.Nonnull() +meth public abstract jakarta.persistence.TypedQuery<{jakarta.persistence.TypedQuery%0}> setArgument(jakarta.persistence.Parameter$Argument) + anno 0 jakarta.annotation.Nonnull() + anno 1 jakarta.annotation.Nonnull() +meth public abstract jakarta.persistence.TypedQuery<{jakarta.persistence.TypedQuery%0}> setArguments(java.util.List>) + anno 0 jakarta.annotation.Nonnull() + anno 1 jakarta.annotation.Nonnull() meth public abstract jakarta.persistence.TypedQuery<{jakarta.persistence.TypedQuery%0}> setCacheRetrieveMode(jakarta.persistence.CacheRetrieveMode) anno 0 jakarta.annotation.Nonnull() anno 1 jakarta.annotation.Nonnull() @@ -4914,22 +4971,18 @@ meth public abstract !hasdefault jakarta.persistence.QueryFlushMode flush() meth public abstract !hasdefault jakarta.persistence.QueryHint[] hints() CLSS public jakarta.persistence.query.StaticStatementReference -cons public !varargs init(java.lang.String,java.lang.Class,java.lang.String,java.util.List>,java.util.List,java.util.List,java.util.Map,jakarta.persistence.Statement$Option[]) +cons public !varargs init(java.lang.String,java.lang.Class,java.lang.String,java.util.List>,java.util.Map,jakarta.persistence.Statement$Option[]) anno 1 jakarta.annotation.Nonnull() anno 2 jakarta.annotation.Nonnull() anno 3 jakarta.annotation.Nonnull() anno 4 jakarta.annotation.Nonnull() anno 5 jakarta.annotation.Nonnull() anno 6 jakarta.annotation.Nonnull() - anno 7 jakarta.annotation.Nonnull() - anno 8 jakarta.annotation.Nonnull() -cons public init(java.lang.String,java.lang.Class,java.lang.String,java.util.List>,java.util.List,java.util.List) +cons public init(java.lang.String,java.lang.Class,java.lang.String,java.util.List>) anno 1 jakarta.annotation.Nonnull() anno 2 jakarta.annotation.Nonnull() anno 3 jakarta.annotation.Nonnull() anno 4 jakarta.annotation.Nonnull() - anno 5 jakarta.annotation.Nonnull() - anno 6 jakarta.annotation.Nonnull() intf jakarta.persistence.StatementReference meth public boolean equals(java.lang.Object) meth public int hashCode() @@ -4940,6 +4993,10 @@ meth public java.lang.String getAnnotatedMemberName() meth public java.lang.String getName() anno 0 jakarta.annotation.Nonnull() meth public java.lang.String toString() +meth public java.util.List> getParameterArguments() + anno 0 jakarta.annotation.Nonnull() +meth public java.util.List> getParameters() + anno 0 jakarta.annotation.Nonnull() meth public java.util.List> getParameterTypes() anno 0 jakarta.annotation.Nonnull() meth public java.util.List getArguments() @@ -4951,28 +5008,24 @@ meth public java.util.Map getHints() meth public java.util.Set getOptions() anno 0 jakarta.annotation.Nonnull() supr java.lang.Object -hfds annotatedClass,annotatedMemberName,arguments,hints,name,options,parameterNames,parameterTypes +hfds annotatedClass,annotatedMemberName,arguments,hints,name,options CLSS public jakarta.persistence.query.StaticTypedQueryReference<%0 extends java.lang.Object> -cons public !varargs init(java.lang.String,java.lang.Class,java.lang.String,java.lang.Class<{jakarta.persistence.query.StaticTypedQueryReference%0}>,java.util.List>,java.util.List,java.util.List,java.lang.String,java.util.Map,jakarta.persistence.TypedQuery$Option[]) +cons public !varargs init(java.lang.String,java.lang.Class,java.lang.String,java.lang.Class<{jakarta.persistence.query.StaticTypedQueryReference%0}>,java.util.List>,java.lang.String,java.util.Map,jakarta.persistence.TypedQuery$Option[]) anno 1 jakarta.annotation.Nonnull() - anno 10 jakarta.annotation.Nonnull() anno 2 jakarta.annotation.Nonnull() anno 3 jakarta.annotation.Nonnull() anno 4 jakarta.annotation.Nullable() anno 5 jakarta.annotation.Nonnull() - anno 6 jakarta.annotation.Nonnull() + anno 6 jakarta.annotation.Nullable() anno 7 jakarta.annotation.Nonnull() - anno 8 jakarta.annotation.Nullable() - anno 9 jakarta.annotation.Nonnull() -cons public init(java.lang.String,java.lang.Class,java.lang.String,java.lang.Class<{jakarta.persistence.query.StaticTypedQueryReference%0}>,java.util.List>,java.util.List,java.util.List) + anno 8 jakarta.annotation.Nonnull() +cons public init(java.lang.String,java.lang.Class,java.lang.String,java.lang.Class<{jakarta.persistence.query.StaticTypedQueryReference%0}>,java.util.List>) anno 1 jakarta.annotation.Nonnull() anno 2 jakarta.annotation.Nonnull() anno 3 jakarta.annotation.Nonnull() anno 4 jakarta.annotation.Nonnull() anno 5 jakarta.annotation.Nonnull() - anno 6 jakarta.annotation.Nonnull() - anno 7 jakarta.annotation.Nonnull() intf jakarta.persistence.TypedQueryReference<{jakarta.persistence.query.StaticTypedQueryReference%0}> meth public boolean equals(java.lang.Object) meth public int hashCode() @@ -4987,6 +5040,10 @@ meth public java.lang.String getEntityGraphName() meth public java.lang.String getName() anno 0 jakarta.annotation.Nonnull() meth public java.lang.String toString() +meth public java.util.List> getParameterArguments() + anno 0 jakarta.annotation.Nonnull() +meth public java.util.List> getParameters() + anno 0 jakarta.annotation.Nonnull() meth public java.util.List> getParameterTypes() anno 0 jakarta.annotation.Nonnull() meth public java.util.List getArguments() @@ -4998,7 +5055,7 @@ meth public java.util.Map getHints() meth public java.util.Set getOptions() anno 0 jakarta.annotation.Nonnull() supr java.lang.Object -hfds annotatedClass,annotatedMemberName,arguments,entityGraphName,hints,name,options,parameterNames,parameterTypes,resultType +hfds annotatedClass,annotatedMemberName,arguments,entityGraphName,hints,name,options,resultType CLSS abstract interface jakarta.persistence.query.package-info