-
Notifications
You must be signed in to change notification settings - Fork 30
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
other types of comparisons for parameter based automatic query #892
Open
njr-11
wants to merge
3
commits into
jakartaee:main
Choose a base branch
from
njr-11:857-allow-other-comparisons-for-parameter-based-automatic-queries
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+229
−47
Open
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/* | ||
* Copyright (c) 2024 Contributors to the Eclipse Foundation | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package jakarta.data.repository; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* <p>Annotates a parameter of a repository {@link Find} or {@link Delete} method, | ||
* indicating how a persistent field is compared against the parameter's value. | ||
* The {@link By} annotation is used on the same parameter to identify the | ||
* persistent field.</p> | ||
* | ||
* <p>For example,</p> | ||
* | ||
* <pre> | ||
* @Repository | ||
* public interface Products extends CrudRepository<Product, Long> { | ||
* | ||
* // Find all Product entities where the price field is less than a maximum value. | ||
* @Find | ||
* List<Product> pricedBelow(@By(_Product.PRICE) @Is(LESS_THAN) float max); | ||
* | ||
* // Find a page of Product entities where the name field matches a pattern, ignoring case. | ||
* @Find | ||
* Page<Product> search(@By(_Product.NAME) @Is(LIKE_IGNORE_CASE) String pattern, | ||
* PageRequest pagination, | ||
* Order<Product> order); | ||
* | ||
* // Remove Product entities with any of the unique identifiers listed. | ||
* @Delete | ||
* void remove(@By(ID) @Is(IN) List<Long> productIds); | ||
* } | ||
* </pre> | ||
*/ | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.PARAMETER) | ||
public @interface Is { | ||
// TODO add JavaDoc with examples to these | ||
String EQUAL = "EQUAL"; | ||
String GREATER_THAN = "GREATER_THAN"; | ||
String GREATER_THAN_EQ = "GREATER_THAN_EQ"; | ||
String IGNORE_CASE = "IGNORE_CASE"; | ||
String IN = "IN"; | ||
String LESS_THAN = "LESS_THAN"; | ||
String LESS_THAN_EQ = "LESS_THAN_EQ"; | ||
String LIKE = "LIKE"; | ||
String LIKE_IGNORE_CASE = "LIKE_IGNORE_CASE"; | ||
String NOT = "NOT"; | ||
String NOT_IGNORE_CASE = "NOT_IGNORE_CASE"; | ||
String NOT_IN = "NOT_IN"; | ||
String NOT_LIKE = "NOT_LIKE"; | ||
String NOT_LIKE_IGNORE_CASE = "NOT_LIKE_IGNORE_CASE"; | ||
|
||
/** | ||
* <p>The type of comparison operation to use when comparing a persistent | ||
* field against a value that is supplied to a repository method. | ||
* For portable applications, the comparison operation must be one of the | ||
* constants defined within this class. Jakarta Data providers might choose | ||
* to provide their own constants as non-portable extensions.</p> | ||
* | ||
* <p>The following example compares the year a person was born against | ||
* a minimum and maximum year that are supplied as parameters to a repository | ||
* method:</p> | ||
* | ||
* <pre> | ||
* @Find | ||
* @OrderBy(_Person.YEAR_BORN) | ||
* List<Person> bornWithin(@By(_Person.YEAR_BORN) @Is(TREATER_THAN_EQ) float minYear, | ||
* @By(_Person.YEAR_BORN) @Is(LESS_THAN_EQ) float maxYear); | ||
* </pre> | ||
* | ||
* <p>The default comparison operation is the {@linkplain #EQUAL equality} | ||
* comparison.</p> | ||
* | ||
* <p>For concise code, it can be convenient for a repository interface to | ||
* statically import one or more constants from this class. For example:</p> | ||
* | ||
* <pre> | ||
* import static jakarta.data.repository.Is.*; | ||
* </pre> | ||
* | ||
* @return the type of comparison operation. | ||
*/ | ||
String value() default EQUAL; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand the power of flexibility of
String
; however, a typo can be a disaster; plus, the enum can show the available options by IDE.In this case, I still prefer the enum; if a vendor wants to externalize this behavior, it can easily create its annotation.
I like the Effective Java item 34 in this case, thus, Enum instead of constant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed this to make it more agreeable to Gavin. My own preference was for enum which I do still prefer, but I don't think it is a big deal one way or the other and would be happy with either. If we did leave it this way, I'm not at all worried about typos because the user doesn't write these, they use the constants we define in the spec (or that a vendor defines in their API). And yes, having a vendor extend behavior with an annotation of their seems perfectly reasonable to me, but I don't think Gavin is going to be on board with that and he was the one who brought up not being extensible as a drawback. In any case, if the two of you can agree on one way or the other (enum or String constant), I'll switch it to that because I really am fine with either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would vote to keep an enum or reuse the
By
annotation to give the provider more flexibility.#857 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's fine, I put the enum back for now. I was only anticipating that Gavin would prefer it with String constants to enable vendor extensions without an annotation, but I'm not actually sure of that. This is also now updated with the shorter
ANY_CASE
, and I added in the full list of possible enum constants, which I realize might need to be pared down later to gain agreement on getting this in.