From 287ca1f92e723a0f56b60d90edba676e798383c3 Mon Sep 17 00:00:00 2001 From: Gavin King Date: Tue, 19 Mar 2024 15:42:10 +0100 Subject: [PATCH 1/3] sync spec with javdoc of @Find that is, mention arrays as return types for automatic query methods --- spec/src/main/asciidoc/repository.asciidoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/src/main/asciidoc/repository.asciidoc b/spec/src/main/asciidoc/repository.asciidoc index a4ac3c43b..752528bb6 100644 --- a/spec/src/main/asciidoc/repository.asciidoc +++ b/spec/src/main/asciidoc/repository.asciidoc @@ -826,7 +826,7 @@ A _parameter-based automatic query method_ is an abstract method annotated with Each automatic query method must be assigned an entity type. The rules for inferring the entity type depend on the semantics of the automatic query annotation. Typically: -- If the automatic query method returns an entity type, the method return type identifies the entity. For example, the return type might be `E`, `Optional`, `Page`, or `List`, where `E` is an entity class. Then the automatic query method would be assigned the entity type `E`. +- If the automatic query method returns an entity type, the method return type identifies the entity. For example, the return type might be `E`, `Optional`, `E[]`, `Page`, or `List`, where `E` is an entity class. Then the automatic query method would be assigned the entity type `E`. - If the query does not return an entity type, the entity assigned to the automatic query method is the primary entity type of the repository. Jakarta Data infers a query based on the parameters of the method. Each parameter must either: From 5d7db8e376d69a79c332ebb36f9aba3c06d8f6cc Mon Sep 17 00:00:00 2001 From: Gavin King Date: Tue, 19 Mar 2024 15:44:43 +0100 Subject: [PATCH 2/3] use @Find/@Delete and @By(ID) in BasicRepository --- .../java/jakarta/data/repository/BasicRepository.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/api/src/main/java/jakarta/data/repository/BasicRepository.java b/api/src/main/java/jakarta/data/repository/BasicRepository.java index a61093627..d826e7af3 100644 --- a/api/src/main/java/jakarta/data/repository/BasicRepository.java +++ b/api/src/main/java/jakarta/data/repository/BasicRepository.java @@ -25,6 +25,8 @@ import java.util.Optional; import java.util.stream.Stream; +import static jakarta.data.repository.By.ID; + /** *

A built-in repository supertype for performing basic operations on entities.

* @@ -141,7 +143,8 @@ public interface BasicRepository extends DataRepository { * @return the entity with the given Id or {@link Optional#empty()} if none is found. * @throws NullPointerException when the Id is {@code null}. */ - Optional findById(K id); + @Find + Optional findById(@By(ID) K id); /** * Returns whether an entity with the given Id exists. @@ -197,7 +200,8 @@ public interface BasicRepository extends DataRepository { * @param id must not be {@code null}. * @throws NullPointerException when the Id is {@code null}. */ - void deleteById(K id); + @Delete + void deleteById(@By(ID) K id); /** * Deletes a given entity. Deletion is performed by matching the Id, and if the entity is From 8269f3bb4e303aad8f0e772a698151fea3e2013b Mon Sep 17 00:00:00 2001 From: Gavin King Date: Tue, 19 Mar 2024 15:47:08 +0100 Subject: [PATCH 3/3] "run time" -> runtime, "life cycle" -> lifecycle --- api/src/main/java/jakarta/data/repository/By.java | 2 +- api/src/main/java/jakarta/data/repository/Param.java | 2 +- api/src/main/java/jakarta/data/repository/Query.java | 2 +- api/src/main/java/jakarta/data/repository/package-info.java | 2 +- api/src/main/java/module-info.java | 4 ++-- spec/src/main/asciidoc/repository.asciidoc | 2 +- .../tck/data/framework/read/only/CustomRepository.java | 2 +- .../ee/jakarta/tck/data/standalone/entity/EntityTests.java | 2 +- 8 files changed, 9 insertions(+), 9 deletions(-) diff --git a/api/src/main/java/jakarta/data/repository/By.java b/api/src/main/java/jakarta/data/repository/By.java index 85299e049..c99d0ad26 100644 --- a/api/src/main/java/jakarta/data/repository/By.java +++ b/api/src/main/java/jakarta/data/repository/By.java @@ -58,7 +58,7 @@ *

The {@code By} annotation is unnecessary when the method parameter name * matches the entity attribute name and the application is compiled with the * {@code -parameters} compiler option that makes parameter names available - * at run time.

+ * at runtime.

* *

Thus, when this compiler option is enabled, the previous example may be * written without the use of {@code By}:

diff --git a/api/src/main/java/jakarta/data/repository/Param.java b/api/src/main/java/jakarta/data/repository/Param.java index d4f5faef8..70405445e 100644 --- a/api/src/main/java/jakarta/data/repository/Param.java +++ b/api/src/main/java/jakarta/data/repository/Param.java @@ -43,7 +43,7 @@ *

The {@code Param} annotation is unnecessary when the method parameter name * matches the query language named parameter name and the application is compiled with the * {@code -parameters} compiler option that makes parameter names available - * at run time.

+ * at runtime.

* * @see Query */ diff --git a/api/src/main/java/jakarta/data/repository/Query.java b/api/src/main/java/jakarta/data/repository/Query.java index c57aad1d3..6131e9aac 100644 --- a/api/src/main/java/jakarta/data/repository/Query.java +++ b/api/src/main/java/jakarta/data/repository/Query.java @@ -42,7 +42,7 @@ * The {@code Param} annotation is unnecessary for named parameters when the method parameter name * matches the query language named parameter name and the application is compiled with the * {@code -parameters} compiler option that makes parameter names available - * at run time. When the {@code Param} annotation is not used, the Jakarta Data provider must + * at runtime. When the {@code Param} annotation is not used, the Jakarta Data provider must * interpret the query by scanning for the delimiter that is used for positional parameters. * If the delimiter appears for another purpose in a query that requires named parameters, * it might be necessary for the application to explicitly define the {@code Param} in order to diff --git a/api/src/main/java/jakarta/data/repository/package-info.java b/api/src/main/java/jakarta/data/repository/package-info.java index 0a63f0267..141fd2607 100644 --- a/api/src/main/java/jakarta/data/repository/package-info.java +++ b/api/src/main/java/jakarta/data/repository/package-info.java @@ -30,7 +30,7 @@ * and {@link jakarta.data.repository.CrudRepository#update(java.lang.Object)} operations. * * - *

Repository interfaces can also define their own life cycle methods using the + *

Repository interfaces can also define their own lifecycle methods using the * {@link jakarta.data.repository.Insert}, {@link jakarta.data.repository.Update}, {@link jakarta.data.repository.Save}, and {@link jakarta.data.repository.Delete} annotations, * as well as a variety of other methods following the Query by Method Name pattern, * the Parameter-based Conditions pattern, and the {@link jakarta.data.repository.Query} annotation.

diff --git a/api/src/main/java/module-info.java b/api/src/main/java/module-info.java index 464ed0cde..1978d9e23 100644 --- a/api/src/main/java/module-info.java +++ b/api/src/main/java/module-info.java @@ -236,7 +236,7 @@ *

Repository methods following the Query by Method Name pattern * must include the {@code By} keyword in the method name and must not include * the {@code @Find} annotation, {@code @Query} annotation, or - * any life cycle annotations on the method or any data access related annotations + * any lifecycle annotations on the method or any data access related annotations * on the method parameters. Query conditions * are determined by the portion of the method name following the {@code By} keyword.

* @@ -572,7 +572,7 @@ * If the {@link By} annotation is missing, the method parameter name must * match the name of an entity attribute and the repository must be compiled * with the {@code -parameters} compiler option so that parameter names are - * available at run time. The {@code _} character may be used in a method + * available at runtime. The {@code _} character may be used in a method * parameter name to reference embedded attributes. All conditions are * considered to be the equality condition. All conditions must match in * order to retrieve an entity.

diff --git a/spec/src/main/asciidoc/repository.asciidoc b/spec/src/main/asciidoc/repository.asciidoc index 752528bb6..136ae221b 100644 --- a/spec/src/main/asciidoc/repository.asciidoc +++ b/spec/src/main/asciidoc/repository.asciidoc @@ -1677,5 +1677,5 @@ The following order, with the lower number having higher precedence, is used whe 4. If the method is annotated with an <>, such as `@Find`, or with a <> declaring the type of operation, for example, with `@Insert`, `@Update`, `@Save`, or `@Delete`, and the provider recognizes the annotation, then the annotation determines how the method is implemented, possibly with the help of other annotations present on the method parameters, for example, any `@By` annotations of the parameters. 5. If the method is named according to the conventions of _Query by Method Name_, then the implementation follows the <> pattern. -A repository method that does not fit any of the above patterns and is not handled as a vendor-specific extension to the specification must either result in an error at build time or raise `UnsupportedOperationException` at run time. +A repository method that does not fit any of the above patterns and is not handled as a vendor-specific extension to the specification must either result in an error at build time or raise `UnsupportedOperationException` at runtime. diff --git a/tck/src/main/java/ee/jakarta/tck/data/framework/read/only/CustomRepository.java b/tck/src/main/java/ee/jakarta/tck/data/framework/read/only/CustomRepository.java index 1a8bae5d4..7ae8ff13f 100644 --- a/tck/src/main/java/ee/jakarta/tck/data/framework/read/only/CustomRepository.java +++ b/tck/src/main/java/ee/jakarta/tck/data/framework/read/only/CustomRepository.java @@ -25,7 +25,7 @@ /** * Do not add methods or inheritance to this interface. * Its purpose is to test that without inheriting from a built-in repository, - * the life cycle methods with the same entity class are what identifies the + * the lifecycle methods with the same entity class are what identifies the * primary entity class to use for the count and exist methods. */ @Repository diff --git a/tck/src/main/java/ee/jakarta/tck/data/standalone/entity/EntityTests.java b/tck/src/main/java/ee/jakarta/tck/data/standalone/entity/EntityTests.java index 694d3fc91..c6f8b4558 100644 --- a/tck/src/main/java/ee/jakarta/tck/data/standalone/entity/EntityTests.java +++ b/tck/src/main/java/ee/jakarta/tck/data/standalone/entity/EntityTests.java @@ -1348,7 +1348,7 @@ public void testPageOfNothing() { assertEquals(0L, page.totalPages()); } - @Assertion(id = "133", strategy = "Use count and exists methods where the primary entity class is inferred from the life cycle methods.") + @Assertion(id = "133", strategy = "Use count and exists methods where the primary entity class is inferred from the lifecycle methods.") public void testPrimaryEntityClassDeterminedByLifeCycleMethods() { assertEquals(4, customRepo.countByIdIn(Set.of(2L, 15L, 37L, -5L, 60L)));