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

Add Criteria-Based Filtering #894

Closed
wants to merge 57 commits into from
Closed
Show file tree
Hide file tree
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 Nov 5, 2024
e48ca60
feat: create filter and criteria
otaviojava Nov 5, 2024
a5bdaa3
feat: include header to CriteriaRepository
otaviojava Nov 5, 2024
113d0c2
feat: rename core classes to Restriction and Operator
otaviojava Nov 6, 2024
592a100
feat: include logical operator
otaviojava Nov 6, 2024
4cb44d3
feat: create restriction proposal
otaviojava Nov 6, 2024
8b8898f
feat: create and update queries at RestrictionRepository
otaviojava Nov 6, 2024
8ceb3a5
style: inclulde header license
otaviojava Nov 6, 2024
ef4fd7b
feat: update structure based on the discussion on meeting today
otaviojava Nov 6, 2024
ee8b4fd
refact: convert restriction to interface
otaviojava Nov 6, 2024
076062f
feat: update the implementation using record metamodel
otaviojava Nov 6, 2024
7697efd
feat: move attribute to defult method
otaviojava Nov 6, 2024
4be722f
style: remove unsed imports
otaviojava Nov 6, 2024
08de315
feat: Use the CompositeRestriction
otaviojava Nov 6, 2024
391ab6f
feat: remove filterable attribute
otaviojava Nov 6, 2024
0a2a63a
feat: move restriction to metadmodel
otaviojava Nov 6, 2024
d4bc32c
feat: move ppattern to use internally
otaviojava Nov 6, 2024
596f49b
chore: remove ISNULL condition
otaviojava Nov 6, 2024
22b0f4a
Update api/src/main/java/jakarta/data/metamodel/TextAttribute.java
otaviojava Nov 6, 2024
34c00e5
feat: create range class
otaviojava Nov 6, 2024
785abd6
docs: update documentation on pattern
otaviojava Nov 6, 2024
d51a97e
feat: udpate using range
otaviojava Nov 6, 2024
0265f04
feat: remove unsed imports
otaviojava Nov 6, 2024
91f7e28
feat: update text attribute
otaviojava Nov 7, 2024
bd8b5b8
feat: update pattern
otaviojava Nov 7, 2024
e5bdf6e
feat: create restriction
otaviojava Nov 7, 2024
d6010ca
Update api/src/main/java/jakarta/data/metamodel/Pattern.java
otaviojava Nov 7, 2024
3c4369b
Update api/src/main/java/jakarta/data/metamodel/BasicRestriction.java
otaviojava Nov 7, 2024
d0837ad
Update api/src/main/java/jakarta/data/metamodel/BasicRestriction.java
otaviojava Nov 7, 2024
5f0d857
Update api/src/main/java/jakarta/data/metamodel/Pattern.java
otaviojava Nov 7, 2024
97e2dbe
Update api/src/main/java/jakarta/data/metamodel/Pattern.java
otaviojava Nov 7, 2024
d332f7e
Update api/src/main/java/jakarta/data/metamodel/Pattern.java
otaviojava Nov 7, 2024
1fff489
Update api/src/main/java/jakarta/data/metamodel/Pattern.java
otaviojava Nov 7, 2024
1b072f6
Update api/src/main/java/jakarta/data/metamodel/MultipleRestriction.java
otaviojava Nov 7, 2024
5d429a2
feat: reduce the scope with is annotation
otaviojava Nov 7, 2024
e37834d
Update api/src/main/java/jakarta/data/metamodel/Pattern.java
otaviojava Nov 7, 2024
11e048a
Update api/src/main/java/jakarta/data/metamodel/Pattern.java
otaviojava Nov 7, 2024
6b9d102
Update api/src/main/java/jakarta/data/metamodel/Pattern.java
otaviojava Nov 7, 2024
225a806
docs: fix pattern documentation
otaviojava Nov 7, 2024
e3a79b5
Update api/src/main/java/jakarta/data/metamodel/MultipleRestriction.java
otaviojava Nov 11, 2024
e3c8d87
feat: moved text attribute
otaviojava Nov 12, 2024
97586f0
Update api/src/main/java/jakarta/data/Pattern.java
otaviojava Nov 13, 2024
b5b61f0
feat: update pattern structure based on Gavin's point
otaviojava Nov 13, 2024
f0f551a
feat: create pattern structure bases on gavin suggestion
otaviojava Nov 13, 2024
da4cfdf
docs: update documentation in pattern
otaviojava Nov 13, 2024
a17d2ed
feat: update pattern name
otaviojava Nov 13, 2024
6d2916b
feat: update module info
otaviojava Nov 13, 2024
ca058c4
feat: update structure from PR 895
otaviojava Nov 13, 2024
13bd83d
feat: update to restrict
otaviojava Nov 13, 2024
d44817d
documentation: include restrict javadoc
otaviojava Nov 13, 2024
d973ec7
feat: create instances at TextAttribute using Restrict
otaviojava Nov 13, 2024
d8ada64
test: create scenario cases to pattern
otaviojava Nov 17, 2024
0897e47
test: create test to CompositeRestriction
otaviojava Nov 17, 2024
3c64b07
feat: remove unsed imports
otaviojava Nov 17, 2024
216877a
test: create basic restrictionr record
otaviojava Nov 17, 2024
5515485
test: create restrict test
otaviojava Nov 17, 2024
f0b8a5b
test: create test scenarios to Range
otaviojava Nov 17, 2024
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
53 changes: 53 additions & 0 deletions api/src/main/java/jakarta/data/BasicRestriction.java
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;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


/**
* 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();
}
49 changes: 49 additions & 0 deletions api/src/main/java/jakarta/data/CompositeRestriction.java
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 api/src/main/java/jakarta/data/CompositeRestrictionRecord.java
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 api/src/main/java/jakarta/data/CompositeRestrictionType.java
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
}
79 changes: 79 additions & 0 deletions api/src/main/java/jakarta/data/Operator.java
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
}



8 changes: 4 additions & 4 deletions api/src/main/java/jakarta/data/Order.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
*/
package jakarta.data;

import java.util.Iterator;
import java.util.List;

import jakarta.data.metamodel.StaticMetamodel;
import jakarta.data.repository.OrderBy;

import java.util.Iterator;
import java.util.List;

/**
* <p>Requests sorting on various entity attributes.</p>
*
Expand Down Expand Up @@ -169,4 +169,4 @@ public Iterator<Sort<? super T>> iterator() {
public String toString() {
return sorts.toString();
}
}
}
Loading