-
Notifications
You must be signed in to change notification settings - Fork 31
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
Add Criteria-Based Filtering #894
Closed
Closed
Changes from all commits
Commits
Show all changes
57 commits
Select commit
Hold shift + click to select a range
bbe78ea
feat: create sample code
otaviojava e48ca60
feat: create filter and criteria
otaviojava a5bdaa3
feat: include header to CriteriaRepository
otaviojava 113d0c2
feat: rename core classes to Restriction and Operator
otaviojava 592a100
feat: include logical operator
otaviojava 4cb44d3
feat: create restriction proposal
otaviojava 8b8898f
feat: create and update queries at RestrictionRepository
otaviojava 8ceb3a5
style: inclulde header license
otaviojava ef4fd7b
feat: update structure based on the discussion on meeting today
otaviojava ee8b4fd
refact: convert restriction to interface
otaviojava 076062f
feat: update the implementation using record metamodel
otaviojava 7697efd
feat: move attribute to defult method
otaviojava 4be722f
style: remove unsed imports
otaviojava 08de315
feat: Use the CompositeRestriction
otaviojava 391ab6f
feat: remove filterable attribute
otaviojava 0a2a63a
feat: move restriction to metadmodel
otaviojava d4bc32c
feat: move ppattern to use internally
otaviojava 596f49b
chore: remove ISNULL condition
otaviojava 22b0f4a
Update api/src/main/java/jakarta/data/metamodel/TextAttribute.java
otaviojava 34c00e5
feat: create range class
otaviojava 785abd6
docs: update documentation on pattern
otaviojava d51a97e
feat: udpate using range
otaviojava 0265f04
feat: remove unsed imports
otaviojava 91f7e28
feat: update text attribute
otaviojava bd8b5b8
feat: update pattern
otaviojava e5bdf6e
feat: create restriction
otaviojava d6010ca
Update api/src/main/java/jakarta/data/metamodel/Pattern.java
otaviojava 3c4369b
Update api/src/main/java/jakarta/data/metamodel/BasicRestriction.java
otaviojava d0837ad
Update api/src/main/java/jakarta/data/metamodel/BasicRestriction.java
otaviojava 5f0d857
Update api/src/main/java/jakarta/data/metamodel/Pattern.java
otaviojava 97e2dbe
Update api/src/main/java/jakarta/data/metamodel/Pattern.java
otaviojava d332f7e
Update api/src/main/java/jakarta/data/metamodel/Pattern.java
otaviojava 1fff489
Update api/src/main/java/jakarta/data/metamodel/Pattern.java
otaviojava 1b072f6
Update api/src/main/java/jakarta/data/metamodel/MultipleRestriction.java
otaviojava 5d429a2
feat: reduce the scope with is annotation
otaviojava e37834d
Update api/src/main/java/jakarta/data/metamodel/Pattern.java
otaviojava 11e048a
Update api/src/main/java/jakarta/data/metamodel/Pattern.java
otaviojava 6b9d102
Update api/src/main/java/jakarta/data/metamodel/Pattern.java
otaviojava 225a806
docs: fix pattern documentation
otaviojava e3a79b5
Update api/src/main/java/jakarta/data/metamodel/MultipleRestriction.java
otaviojava e3c8d87
feat: moved text attribute
otaviojava 97586f0
Update api/src/main/java/jakarta/data/Pattern.java
otaviojava b5b61f0
feat: update pattern structure based on Gavin's point
otaviojava f0f551a
feat: create pattern structure bases on gavin suggestion
otaviojava da4cfdf
docs: update documentation in pattern
otaviojava a17d2ed
feat: update pattern name
otaviojava 6d2916b
feat: update module info
otaviojava ca058c4
feat: update structure from PR 895
otaviojava 13bd83d
feat: update to restrict
otaviojava d44817d
documentation: include restrict javadoc
otaviojava d973ec7
feat: create instances at TextAttribute using Restrict
otaviojava d8ada64
test: create scenario cases to pattern
otaviojava 0897e47
test: create test to CompositeRestriction
otaviojava 3c64b07
feat: remove unsed imports
otaviojava 216877a
test: create basic restrictionr record
otaviojava 5515485
test: create restrict test
otaviojava f0b8a5b
test: create test scenarios to Range
otaviojava 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* 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; | ||
|
||
/** | ||
* A basic restriction applies to a single field, representing conditions such as equality, | ||
* comparisons, range checks, and pattern matches. | ||
* | ||
* <p>The {@code BasicRestriction} interface provides methods for defining simple, singular restrictions | ||
* based on a specific field, an operator, and an optional comparison value. This interface supports | ||
* common operators (e.g., EQUAL, GREATER_THAN) and serves as a foundation for filtering | ||
* logic on individual fields.</p> | ||
* | ||
* @param <T> the type of the entity on which the restriction is applied. | ||
*/ | ||
public interface BasicRestriction<T> extends Restriction<T> { | ||
|
||
/** | ||
* The name of the field on which this restriction is applied. | ||
* | ||
* @return the field name as a String. | ||
*/ | ||
String field(); | ||
|
||
/** | ||
* The operator defining the type of comparison or condition for this restriction. | ||
* | ||
* @return the operator representing the restriction type (e.g., EQUAL, LIKE, BETWEEN). | ||
*/ | ||
Operator operator(); | ||
|
||
/** | ||
* The value used for comparison in this restriction, if applicable. | ||
* | ||
* @return the comparison value, or {@code null} if the restriction does not use a value (e.g., IS_NULL). | ||
*/ | ||
Object value(); | ||
} |
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,49 @@ | ||
/* | ||
* 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; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* A composite restriction that combines multiple {@link Restriction} instances using logical operators. | ||
* | ||
* <p>The {@code MultipleRestriction} interface allows for combining multiple restrictions, enabling complex | ||
* filtering scenarios where multiple conditions must be satisfied. Each contained {@link Restriction} | ||
* can be evaluated based on the logical operator specified by the {@link CompositeRestrictionType} type.</p> | ||
* | ||
* <p>This interface is useful for defining AND/OR conditions where multiple fields and restrictions | ||
* are evaluated together in a repository query.</p> | ||
* | ||
* @param <T> the type of the entity on which the restriction is applied. | ||
*/ | ||
public interface CompositeRestriction<T> extends Restriction<T> { | ||
|
||
/** | ||
* The list of restrictions that are combined in this composite restriction. | ||
* | ||
* @return a list of individual restrictions. | ||
*/ | ||
List<Restriction<? extends T>> restrictions(); | ||
|
||
/** | ||
* The logical operator used to combine the contained restrictions, such as AND or OR. | ||
* | ||
* @return the logical combination type for this composite restriction. | ||
*/ | ||
CompositeRestrictionType type(); | ||
} |
73 changes: 73 additions & 0 deletions
73
api/src/main/java/jakarta/data/CompositeRestrictionRecord.java
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,73 @@ | ||
/* | ||
* 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; | ||
|
||
import java.util.Iterator; | ||
import java.util.List; | ||
|
||
/** | ||
* A composite restriction representing a collection of individual {@link Restriction} | ||
* and {@link CompositeRestrictionType} instances, combined under a single logical operation. | ||
* | ||
* <p>This record allows multiple restrictions to be treated as a single entity, making | ||
* it easy to pass complex conditions to repository methods.</p> | ||
* | ||
* @param <T> the entity type that the restrictions apply to. | ||
*/ | ||
record CompositeRestrictionRecord<T>(CompositeRestrictionType type, List<Restriction<? extends T>> restrictions) | ||
implements Iterable<Restriction<? extends T>>, CompositeRestriction<T> { | ||
|
||
/** | ||
* Constructs a composite restriction with the specified operator and list of restrictions. | ||
* | ||
* @param restrictions the list of restrictions to combine. | ||
*/ | ||
public CompositeRestrictionRecord { | ||
restrictions = List.copyOf(restrictions); // Ensure immutability of the list | ||
} | ||
|
||
@Override | ||
public Iterator<Restriction<? extends T>> iterator() { | ||
return restrictions.iterator(); | ||
} | ||
|
||
/** | ||
* Creates a composite restriction where all specified restrictions must be true (AND logic). | ||
* | ||
* @param restrictions the individual restrictions to combine. | ||
* @param <T> the entity type that the restrictions apply to. | ||
* @return a CompositeRestriction representing the AND combination of the provided restrictions. | ||
*/ | ||
@SafeVarargs | ||
public static <T> CompositeRestrictionRecord<T> all(Restriction<T>... restrictions) { | ||
return new CompositeRestrictionRecord<>(CompositeRestrictionType.ALL, List.of(restrictions)); | ||
} | ||
|
||
/** | ||
* Creates a composite restriction where any of the specified restrictions may be true (OR logic). | ||
* | ||
* @param restrictions the individual restrictions to combine. | ||
* @param <T> the entity type that the restrictions apply to. | ||
* @return a CompositeRestriction representing the OR combination of the provided restrictions. | ||
*/ | ||
@SafeVarargs | ||
public static <T> CompositeRestrictionRecord<T> any(Restriction<T>... restrictions) { | ||
return new CompositeRestrictionRecord<>(CompositeRestrictionType.ANY, List.of(restrictions)); | ||
} | ||
|
||
} |
43 changes: 43 additions & 0 deletions
43
api/src/main/java/jakarta/data/CompositeRestrictionType.java
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,43 @@ | ||
/* | ||
* 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; | ||
|
||
|
||
/** | ||
* Represents the logical operators used to combine multiple restrictions in a query. | ||
* | ||
* <p>The `Restrict` enum defines two types of logical combinations:</p> | ||
* <ul> | ||
* <li><b>ALL</b> - Requires that all contained restrictions are satisfied (logical AND).</li> | ||
* <li><b>ANY</b> - Requires that at least one of the contained restrictions is satisfied (logical OR).</li> | ||
* </ul> | ||
* | ||
* <p>This enum is typically used in {@link CompositeRestriction} to specify how its list of | ||
* restrictions should be combined, allowing for flexible and complex query conditions.</p> | ||
*/ | ||
public enum CompositeRestrictionType { | ||
/** | ||
* Requires that all contained restrictions must be satisfied (logical AND). | ||
*/ | ||
ALL, | ||
|
||
/** | ||
* Requires that at least one of the contained restrictions must be satisfied (logical OR). | ||
*/ | ||
ANY | ||
} |
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,79 @@ | ||
/* | ||
* 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; | ||
|
||
|
||
/** | ||
* Enum representing common operators used to define query conditions in Jakarta Data queries. | ||
* The {@code Operator} enum provides a set of operations to specify how values should be compared, | ||
* matched, or restricted when filtering data, supporting flexible and expressive querying across | ||
* different contexts. | ||
*/ | ||
public enum Operator { | ||
|
||
/** | ||
* Matches records where the field value is exactly equal to the specified value. | ||
* Typically used for exact matching on unique identifiers, names, or other exact-value fields. | ||
*/ | ||
EQUAL, | ||
|
||
/** | ||
* Matches records where the field value is greater than the specified value. | ||
* Often applied to numerical fields (e.g., dates, prices) for retrieving values above a given threshold. | ||
*/ | ||
GREATER_THAN, | ||
|
||
/** | ||
* Matches records where the field value is greater than or equal to the specified value. | ||
* Useful for inclusive range queries, where the specified boundary is included in the results. | ||
*/ | ||
GREATER_THAN_EQUAL, | ||
|
||
/** | ||
* Matches records where the field value is contained within a specified collection of values. | ||
* Commonly used to match against multiple possible values, such as category or status lists. | ||
*/ | ||
IN, | ||
|
||
/** | ||
* Matches records where the field value is less than the specified value. | ||
* Frequently used in numerical comparisons to retrieve values below a certain threshold. | ||
*/ | ||
LESS_THAN, | ||
|
||
/** | ||
* Matches records where the field value is less than or equal to the specified value. | ||
* Suitable for inclusive range queries that include the specified boundary in the results. | ||
*/ | ||
LESS_THAN_EQUAL, | ||
|
||
/** | ||
* Matches records where the field value conforms to a specified pattern, often with wildcards. | ||
* Commonly applied to string fields for partial matches (e.g., names containing a substring). | ||
*/ | ||
LIKE, | ||
|
||
/** | ||
* Matches records where the field value falls within a specified range. | ||
* Typically used for range-based comparisons, such as finding dates between a start and end date. | ||
*/ | ||
BETWEEN | ||
} | ||
|
||
|
||
|
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.
Done.