Skip to content

Include Support to restrict #603

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

Merged
merged 116 commits into from
Jun 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
116 commits
Select commit Hold shift + click to select a range
ee46a41
chore: define the jakarta data api to 1.1.0-SNAPSHOT
otaviojava Jun 8, 2025
9c00e74
test: include repository test
otaviojava Jun 8, 2025
f9143ea
feat: update repository type
otaviojava Jun 8, 2025
518430a
test: include repositry type test
otaviojava Jun 8, 2025
5d2226e
feat: include execute restruction query
otaviojava Jun 8, 2025
64b16f7
style: remove unsed import
otaviojava Jun 8, 2025
d8358f0
test: include test scenarion on testrepository
otaviojava Jun 8, 2025
5fa2ec6
test: include abstract repository test
otaviojava Jun 8, 2025
8f6bbbb
feat: include executeRestriction at abstract semistructure proxy
otaviojava Jun 9, 2025
2b23500
feat: generate initial restriction entity metadata
otaviojava Jun 9, 2025
b35f35b
feat: include restriction converter two conditions
otaviojava Jun 9, 2025
9ba75f0
test: initial skeleton structure to restriction converter
otaviojava Jun 9, 2025
fa440db
test: generate product entity and generated data on product
otaviojava Jun 9, 2025
eeeb57a
test: update restriction converter
otaviojava Jun 9, 2025
9f1eb91
feat: update condition to return converter and literal
otaviojava Jun 10, 2025
c8472f0
test: update scenarion on test
otaviojava Jun 10, 2025
4c6b7c6
test: include not equals scenario
otaviojava Jun 10, 2025
566e99a
feat: include restriction converter
otaviojava Jun 10, 2025
3128457
feat: generate initial structure to criteria element
otaviojava Jun 10, 2025
12f11fd
feat: include greater than
otaviojava Jun 10, 2025
c922122
feat: update code
otaviojava Jun 10, 2025
25c0fb7
test include restriction converter
otaviojava Jun 10, 2025
eb3ff91
feat: implementation on restriction converter
otaviojava Jun 10, 2025
dc1789d
test: generate restriction converter
otaviojava Jun 10, 2025
394c4f1
test: update restriction converter
otaviojava Jun 10, 2025
a0f3d7c
feat: include support restrict
otaviojava Jun 10, 2025
ef44d0d
feat: update value converter value on retrict
otaviojava Jun 10, 2025
cb74766
style: remove imports from RestrictionConverter
otaviojava Jun 11, 2025
444e20a
feat: include implementation of between
otaviojava Jun 11, 2025
b464908
test: update between test
otaviojava Jun 11, 2025
9cf4ce2
test: generate test scenarion to negate between
otaviojava Jun 11, 2025
2c5064d
test: include like condition on criteria
otaviojava Jun 11, 2025
deaacef
test: include like conditions at restriction scenarios for test
otaviojava Jun 11, 2025
99d6add
feat: include support to like
otaviojava Jun 11, 2025
e192a61
feat: include support to null and not null
otaviojava Jun 11, 2025
e6463b1
test: update restriction converter
otaviojava Jun 11, 2025
d09212f
feat: include in on restriction
otaviojava Jun 11, 2025
a074ca9
test: update structure restriction
otaviojava Jun 11, 2025
d5f5c95
feat: update shouldExecuteNegatein
otaviojava Jun 11, 2025
42301d6
feat: includde composite restriction
otaviojava Jun 11, 2025
fe1a952
test: include restriction converter
otaviojava Jun 11, 2025
ef3156f
test: generate scenarion to all
otaviojava Jun 11, 2025
af7505a
feat: update restriction on converter
otaviojava Jun 11, 2025
5501bf0
feat: update restriction on converter
otaviojava Jun 11, 2025
4b92816
feat: generate logic to apply morgan's law
otaviojava Jun 11, 2025
2d29f15
test: update all
otaviojava Jun 11, 2025
9ad750f
feat: generate condition to any
otaviojava Jun 11, 2025
7ccb16c
head: include header at valueconverter
otaviojava Jun 11, 2025
5ca0c0a
style: enhance imports at the RestrictionConverter
otaviojava Jun 11, 2025
fc0bf32
feat: formatter restriction
otaviojava Jun 11, 2025
5b4ee48
test: update money condition
otaviojava Jun 11, 2025
5b440b5
test: include amount to test convertion
otaviojava Jun 11, 2025
571fbad
feat: include support to converter
otaviojava Jun 11, 2025
384d936
feat: update semistructure repository
otaviojava Jun 11, 2025
f14772c
test: start the test structure to restrict
otaviojava Jun 11, 2025
9ad5cde
test: include restrict page
otaviojava Jun 11, 2025
58d68f0
feat: include should restrict sort
otaviojava Jun 11, 2025
d95a373
test: generate scenarion to sort by annotation
otaviojava Jun 11, 2025
ab1f6c9
feat: update support to retrict
otaviojava Jun 11, 2025
0b95cd7
feat: include condition to restricion converter
otaviojava Jun 11, 2025
1cc74a4
feat: make restriction converter
otaviojava Jun 11, 2025
d49329c
feat: update proxy to work with restriction
otaviojava Jun 11, 2025
d78e7cf
docs: enhance documentation on restriction converter
otaviojava Jun 11, 2025
4cf8589
test: generate custom restriction repository
otaviojava Jun 12, 2025
de26144
feat: update custom repository
otaviojava Jun 12, 2025
ef4b05e
test: generate test on proxy
otaviojava Jun 12, 2025
aef7c02
feat: update scenarion
otaviojava Jun 12, 2025
752eb88
test: update custom repository scenario
otaviojava Jun 12, 2025
cd94c32
style: remove extra line
otaviojava Jun 13, 2025
3d23388
feat: update repository to valid only on first case
otaviojava Jun 13, 2025
383299c
feat: update repository type to support order with query and combined…
otaviojava Jun 13, 2025
b31ea6d
feat: update repository
otaviojava Jun 13, 2025
9bda238
feat: define order as valid code
otaviojava Jun 13, 2025
a340245
feat: remove order by repository
otaviojava Jun 13, 2025
3b0eb9b
style: remove reposiroty proxy
otaviojava Jun 13, 2025
247d4c5
feat: update repository proxy
otaviojava Jun 13, 2025
81bb85e
feat: update repository type
otaviojava Jun 13, 2025
0e69d59
feat: update repository type
otaviojava Jun 13, 2025
4289fde
feat: update special parameter
otaviojava Jun 13, 2025
6977f3c
feat: update special parameters
otaviojava Jun 13, 2025
8a49a66
feat: include retriction as parameter
otaviojava Jun 13, 2025
ad35c35
feat: include validation on limit
otaviojava Jun 13, 2025
e2a9141
feat: update base semistructure repository
otaviojava Jun 13, 2025
ceeb247
feat: update dynamir query
otaviojava Jun 13, 2025
1eddb03
feat: include biding to restructure
otaviojava Jun 13, 2025
17c8159
feat: update dynamic query on sort
otaviojava Jun 13, 2025
a58f9eb
feat: include retriction scenarion
otaviojava Jun 13, 2025
6e78405
feat: include validation on special parameters
otaviojava Jun 13, 2025
50e356f
test: generate special parameters
otaviojava Jun 13, 2025
e34f381
feat: include validation on sort
otaviojava Jun 13, 2025
c39520b
feat: update base semisructure
otaviojava Jun 13, 2025
c5fc19a
feat: include validation on crud repository proxy
otaviojava Jun 13, 2025
43f0235
test: generate a test scenarion on crud repository
otaviojava Jun 16, 2025
a4c3c56
feat: update repository priority validation
otaviojava Jun 16, 2025
94c5e22
feat: includ evalidation on delete on abstract repository
otaviojava Jun 16, 2025
701611c
test: update test repoisotry proxy
otaviojava Jun 16, 2025
fcf0591
test: update test repository proxy
otaviojava Jun 16, 2025
e2a84ba
feat: update test scenarion
otaviojava Jun 16, 2025
946d7f4
feat: update delete restriction
otaviojava Jun 18, 2025
c5e2089
feat: make the delete as public
otaviojava Jun 18, 2025
6e746ce
feat: implement the execute delete query restriction
otaviojava Jun 18, 2025
d63d81c
feat: remove special parameters#
otaviojava Jun 18, 2025
2fd579f
feat: update implementation restrict repository
otaviojava Jun 18, 2025
17d975c
feat: update restriction
otaviojava Jun 18, 2025
6ad9339
feat: update RepositoryType removing restriction
otaviojava Jun 18, 2025
4c5fc77
feat: update abstract repository proxy
otaviojava Jun 18, 2025
7cca913
test: update repository test of restriction
otaviojava Jun 18, 2025
ab6e0d8
test: remove proxy implementation
otaviojava Jun 18, 2025
c8403b2
feat: remove no used method
otaviojava Jun 18, 2025
04f327e
style: remove import on RepositoryType
otaviojava Jun 18, 2025
bb30b44
feat: update include support restrict
otaviojava Jun 19, 2025
94ffcb4
test: update abstrct structure repository
otaviojava Jun 19, 2025
1a8d597
feat: update abstract keyvalue
otaviojava Jun 19, 2025
1b7a028
docs: update changelog with the restriction api
otaviojava Jun 19, 2025
1e7b7d0
style: updsate base semistructure
otaviojava Jun 19, 2025
f59314b
style: remove imports on KeyValueRepositoryProxy
otaviojava Jun 19, 2025
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
5 changes: 5 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ and this project adheres to https://semver.org/spec/v2.0.0.html[Semantic Version

- Define Java 21 as the minimum version to run JNoSQL

=== Added

- Include support to Restriction interface


== [1.1.8] - 2025-05-21

=== Removed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/
package org.eclipse.jnosql.mapping.core.query;

import jakarta.data.exceptions.MappingException;
import jakarta.data.restrict.Restriction;
import jakarta.enterprise.inject.spi.CDI;
import org.eclipse.jnosql.mapping.core.repository.ThrowingSupplier;
import org.eclipse.jnosql.mapping.metadata.EntityMetadata;
Expand Down Expand Up @@ -139,6 +139,18 @@ public abstract class AbstractRepositoryProxy<T, K> implements InvocationHandler
*/
protected abstract Object executeParameterBased(Object instance, Method method, Object[] params);


/**
* Executes a delete operation based on the method and parameters, specifically for methods that
* involve a {@link jakarta.data.restrict.Restriction} as a parameter.
*
* @param instance The instance on which the method was invoked.
* @param method The method being invoked, representing the delete operation.
* @param params The parameters of the method, including the restriction.
* @return The result of the delete operation.
*/
protected abstract Object executeDeleteRestriction(Object instance, Method method, Object[] params);

@Override
public Object invoke(Object instance, Method method, Object[] params) throws Throwable {

Expand Down Expand Up @@ -169,8 +181,6 @@ public Object invoke(Object instance, Method method, Object[] params) throws Thr
case DEFAULT_METHOD -> {
return unwrapInvocationTargetException(() -> InvocationHandler.invokeDefault(instance, method, params));
}
case ORDER_BY ->
throw new MappingException("Eclipse JNoSQL has not support for method that has OrderBy annotation");
case QUERY -> {
return unwrapInvocationTargetException(() -> executeQuery(instance, method, params));
}
Expand All @@ -188,6 +198,9 @@ public Object invoke(Object instance, Method method, Object[] params) throws Thr
return unwrapInvocationTargetException(() -> INSERT.invoke(new AnnotationOperation.Operation(method, params, repository())));
}
case DELETE -> {
if(params.length > 0 && params[0] instanceof Restriction<?>) {
return unwrapInvocationTargetException(() -> executeDeleteRestriction(instance, method, params));
}
return unwrapInvocationTargetException(() -> DELETE.invoke(new AnnotationOperation.Operation(method, params, repository())));
}
case UPDATE -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import jakarta.data.repository.Delete;
import jakarta.data.repository.Find;
import jakarta.data.repository.Insert;
import jakarta.data.repository.OrderBy;
import jakarta.data.repository.Query;
import jakarta.data.repository.Save;
import jakarta.data.repository.Update;
Expand Down Expand Up @@ -79,10 +78,6 @@ public enum RepositoryType {
* The method that belongs to the interface using a custom repository.
*/
CUSTOM_REPOSITORY(""),
/**
* Method that has {@link jakarta.data.repository.OrderBy} annotation
*/
ORDER_BY(""),
/**
* Method that has {@link Query} annotation
*/
Expand Down Expand Up @@ -162,19 +157,19 @@ public static RepositoryType of(Method method, Class<?> repositoryType) {
if (method.getReturnType().equals(CursoredPage.class)) {
return CURSOR_PAGINATION;
}
String methodName = method.getName();
if (FIND_ALL.keyword.equals(methodName)) {
return FIND_ALL;
}
if (method.getAnnotationsByType(OrderBy.class).length > 0) {
return method.getAnnotation(Find.class) == null? ORDER_BY: PARAMETER_BASED;
}

Predicate<RepositoryType> hasAnnotation = a -> method.getAnnotation(a.annotation) != null;
if (OPERATION_ANNOTATIONS.stream().anyMatch(hasAnnotation)) {
return OPERATION_ANNOTATIONS.stream()
.filter(hasAnnotation)
.findFirst().orElseThrow();
}

String methodName = method.getName();
if (FIND_ALL.keyword.equals(methodName)) {
return FIND_ALL;
}

return KEY_WORLD_METHODS.stream()
.filter(k -> methodName.startsWith(k.keyword))
.findFirst()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import jakarta.data.Order;
import jakarta.data.page.PageRequest;
import jakarta.data.Sort;
import jakarta.data.restrict.Restriction;

import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -33,17 +34,20 @@
* to apply pagination and sorting to your queries dynamically.
*/
public final class SpecialParameters {
static final SpecialParameters EMPTY = new SpecialParameters(null, null, Collections.emptyList());
static final SpecialParameters EMPTY = new SpecialParameters(null, null, Collections.emptyList(), null);

private final PageRequest pageRequest;

private final List<Sort<?>> sorts;
private final Limit limit;

private SpecialParameters(PageRequest pageRequest, Limit limit, List<Sort<?>> sorts) {
private final Restriction<?> restriction;

private SpecialParameters(PageRequest pageRequest, Limit limit, List<Sort<?>> sorts, Restriction<?> restriction) {
this.pageRequest = pageRequest;
this.sorts = sorts;
this.limit = limit;
this.restriction = restriction;
}

/**
Expand Down Expand Up @@ -71,7 +75,7 @@ public List<Sort<?>> sorts() {
* @return when there is no sort and PageRequest
*/
public boolean isEmpty() {
return this.sorts.isEmpty() && pageRequest == null && limit == null;
return this.sorts.isEmpty() && pageRequest == null && limit == null && restriction == null;
}

/**
Expand All @@ -89,7 +93,7 @@ public boolean isSortEmpty() {
* @return true if only have {@link PageRequest}
*/
public boolean hasOnlySort() {
return pageRequest == null && !sorts.isEmpty();
return pageRequest == null && !sorts.isEmpty() && restriction == null && limit == null;
}

/**
Expand All @@ -101,35 +105,47 @@ public Optional<Limit> limit() {
return Optional.ofNullable(limit);
}

/**
* Returns the Restriction instance or {@link Optional#empty()}
*
* @return the Restriction instance or {@link Optional#empty()}
*/
public Optional<Restriction<?>> restriction() {
return Optional.ofNullable(restriction);
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
SpecialParameters that = (SpecialParameters) o;
return Objects.equals(pageRequest, that.pageRequest) && Objects.equals(sorts, that.sorts);
return Objects.equals(pageRequest, that.pageRequest)
&& Objects.equals(sorts, that.sorts)
&& Objects.equals(limit, that.limit)
&& Objects.equals(restriction, that.restriction);
}

@Override
public int hashCode() {
return Objects.hash(pageRequest, sorts);
return Objects.hash(pageRequest, sorts, limit, restriction);
}

@Override
public String toString() {
return "SpecialParameters{" +
"PageRequest=" + pageRequest +
"pageRequest=" + pageRequest +
", sorts=" + sorts +
", limit=" + limit +
", restriction=" + restriction +
'}';
}

static SpecialParameters of(Object[] parameters, Function<String, String> sortParser) {
List<Sort<?>> sorts = new ArrayList<>();
PageRequest pageRequest = null;
Limit limit = null;
Restriction<?> restriction = null;
for (Object parameter : parameters) {
if (parameter instanceof Sort<?> sort) {
sorts.add(mapper(sort, sortParser));
Expand All @@ -141,6 +157,8 @@ static SpecialParameters of(Object[] parameters, Function<String, String> sortPa
Arrays.stream(sortArray).map(s -> mapper(s, sortParser)).forEach(sorts::add);
} else if (parameter instanceof PageRequest request) {
pageRequest = request;
} else if (parameter instanceof Restriction<?> restrictionParameter) {
restriction = restrictionParameter;
}else {
if (parameter instanceof Iterable<?> iterable) {
for (Object value : iterable) {
Expand All @@ -151,7 +169,7 @@ static SpecialParameters of(Object[] parameters, Function<String, String> sortPa
}
}
}
return new SpecialParameters(pageRequest, limit, sorts);
return new SpecialParameters(pageRequest, limit, sorts, restriction);
}

/**
Expand Down Expand Up @@ -189,6 +207,7 @@ public static boolean isSpecialParameter(Class<?> parameter) {
|| Limit.class.isAssignableFrom(parameter)
|| Order.class.isAssignableFrom(parameter)
|| PageRequest.class.isAssignableFrom(parameter)
|| Restriction.class.isAssignableFrom(parameter)
|| parameter.isArray() && Sort.class.isAssignableFrom(parameter.getComponentType());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/
package org.eclipse.jnosql.mapping.core.query;

import jakarta.data.restrict.Restriction;
import org.junit.jupiter.api.Test;

import java.lang.reflect.Method;
Expand Down Expand Up @@ -90,4 +91,11 @@ void shouldInvokeThrowsMappingException() throws Throwable {
assertThrows(UnsupportedOperationException.class, () -> proxy.invoke(proxy, method, new Object[]{}));
}

@Test
void shouldExecuteDeleteRestriction() throws Throwable {
Method method = TestRepository.class.getMethod("delete", Restriction.class);
Object result = proxy.invoke(proxy, method, new Object[]{(Restriction<String>) () -> null});
assertEquals("executeDeleteRestriction", result);
}

}
Loading