Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow multi-valued parameters to @Find & @Delete methods #553

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ public interface BasicRepository<T, K> extends DataRepository<T, K> {
* ids.
* @throws NullPointerException in case the given {@link Iterable ids} or one of its items is {@code null}.
*/
Stream<T> findByIdIn(Iterable<K> ids);
@Find
Stream<T> findByIdIn(@By(ID) List<K> ids);

/**
* Deletes the entity with the given Id.
Expand Down Expand Up @@ -224,7 +225,8 @@ public interface BasicRepository<T, K> extends DataRepository<T, K> {
* @param ids must not be {@code null}. Must not contain {@code null} elements.
* @throws NullPointerException when the iterable is {@code null} or contains {@code null} elements.
*/
void deleteByIdIn(Iterable<K> ids);
@Delete
void deleteByIdIn(@By(ID) List<K> ids);

/**
* Deletes the given entities. Deletion of each entity is performed by matching the unique identifier,
Expand Down
11 changes: 6 additions & 5 deletions api/src/main/java/jakarta/data/repository/Delete.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,10 @@
* <p>Alternatively, the {@code Delete} annotation may be used to annotate a repository method with no parameter of
* entity type. Then the repository method is interpreted as a parameter-based automatic query method. The entity type
* to be deleted is the primary entity type of the repository. The method return type must be {@code void}, {@code int},
* or {@code long}. Every parameter of the annotated method must have exactly the same type and name (the parameter name
* in the Java source, or a name assigned by {@link By @By}) as a persistent field or property of the entity class.
* Parameters of type {@code Sort}, {@code Order}, {@code Limit}, and {@code PageRequest} are prohibited.
* or {@code long}. Every parameter of the annotated method must have exactly the same name (the parameter name in the
* Java source, or a name assigned by {@link By @By}) as a persistent field or property of the entity class and be of
* type {@code T}, {@code T[]}, or {@code List<T>} where {@code T} is the type of the field or property. Parameters
* of type {@code Sort}, {@code Order}, {@code Limit}, and {@code PageRequest} are prohibited.
* </p>
* <p>For example, consider an interface representing a garage:</p>
* <pre>
Expand All @@ -76,10 +77,10 @@
* void unparkAll();
*
* {@code @Delete}
* void unpark(String registration);
* void unpark(String[] registration);
* }
* </pre>
* <p>Here,{@code unparkAll()} deletes every {@code Car}, while {@code unpark(String)} deletes any {@code Car} with a
* <p>Here,{@code unparkAll()} deletes every {@code Car}, while {@code unpark(String)} deletes every {@code Car} with a
* matching value of its {@code registration} field.
* </p>
* <p>An automatic query method annotated {@code Delete} removes every record which satisfies the parameter-based
Expand Down
11 changes: 8 additions & 3 deletions api/src/main/java/jakarta/data/repository/Find.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@
* type returned by the query. Each parameter of the annotated method must either:
* </p>
* <ul>
* <li>have exactly the same type and name (the parameter name in the Java source, or a name assigned by {@link By @By})
* as a persistent field or property of the entity class, or</li>
* <li>have exactly the name (the parameter name in the Java source, or a name assigned by {@link By @By}) as a
* persistent field or property of the entity class and be of type {@code T}, {@code T[]}, or {@code List<T>} where
* {@code T} is the type of the field or property, or</li>
* <li>be of type {@link jakarta.data.Limit}, {@link jakarta.data.Sort}, {@link jakarta.data.Order}, or
* {@link jakarta.data.page.PageRequest}.</li>
* </ul>
Expand All @@ -49,10 +50,14 @@
* interface Garage {
* {@code @Find}
* {@code List<Car>} getCarsWithModel(@By("model") String model);
*
* {@code @Find}
* {@code List<Car>} getCarsWithYearIn(@By("modelYear") int[] years);
* }
* </pre>
* <p>The {@code @Find} annotation indicates that the {@code getCarsWithModel(model)} method retrieves {@code Car}
* instances with the given value of the {@code model} field.
* instances with the given value of the {@code model} field, and that the {@code getCarsWithYearIn(years)} method
* retrieves cars with any one of the given values of the {@code modelYear} field.
* </p>
*
* <p>A method annotated with {@code @Find} must return one of the following types:</p>
Expand Down
5 changes: 4 additions & 1 deletion spec/src/main/asciidoc/repository.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ Each automatic query method must be assigned an entity type. The rules for infer

Jakarta Data infers a query based on the parameters of the method. Each parameter must either:

- have exactly the same type and name as a persistent field or property of the entity class, or
- have exactly the same name as a persistent field or property of the entity class and be of type `T`, `T[]`, or `List<T>` where `T` is the type of the field or property, or
- be of type `Limit`, `Order`, `PageRequest`, or `Sort`.

Parameter names map parameters to persistent fields. A repository with parameter-based automatic query methods must either:
Expand All @@ -851,6 +851,9 @@ For example:
@Find
Book bookByIsbn(String isbn);

@Find
List<Book> booksByIsbn(@By("isbn") String[] isbns);

@Find
List<Book> booksByYear(Year year, Sort order, Limit limit);

Expand Down