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

Visibility of SimpleJpaRepository.ExampleSpecification #3213

Closed
dabico opened this issue Oct 26, 2023 · 5 comments
Closed

Visibility of SimpleJpaRepository.ExampleSpecification #3213

dabico opened this issue Oct 26, 2023 · 5 comments
Labels
status: declined A suggestion or change that we don't feel we should currently apply

Comments

@dabico
Copy link

dabico commented Oct 26, 2023

Would it be possible to increase the visibility of SimpleJpaRepository.ExampleSpecification from private to protected?
I'm developing a custom repository that extends SimpleJpaRepository, and would like to reuse this inner class as opposed to copying it from the parent. The class in question:

/**
* {@link Specification} that gives access to the {@link Predicate} instance representing the values contained in the
* {@link Example}.
*
* @param <T>
* @author Christoph Strobl
* @since 1.10
*/
private static class ExampleSpecification<T> implements Specification<T> {
private static final long serialVersionUID = 1L;
private final Example<T> example;
private final EscapeCharacter escapeCharacter;
/**
* Creates new {@link ExampleSpecification}.
*
* @param example the example to base the specification of. Must not be {@literal null}.
* @param escapeCharacter the escape character to use for like expressions. Must not be {@literal null}.
*/
ExampleSpecification(Example<T> example, EscapeCharacter escapeCharacter) {
Assert.notNull(example, "Example must not be null");
Assert.notNull(escapeCharacter, "EscapeCharacter must not be null");
this.example = example;
this.escapeCharacter = escapeCharacter;
}
@Override
public Predicate toPredicate(Root<T> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
return QueryByExamplePredicateBuilder.getPredicate(root, cb, example, escapeCharacter);
}
}

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Oct 26, 2023
@gregturn
Copy link
Contributor

Fundamentally speaking, ExampleSpecification is an implementation detail to provide support for Query by Example.

I'd really to understand the use case you are attempting to solve that begs you to make changes and alterations to ExampleSpecification.

@gregturn gregturn added the status: waiting-for-feedback We need additional information before we can continue label Oct 26, 2023
@dabico
Copy link
Author

dabico commented Oct 26, 2023

Hi @gregturn

In short, I wanted to create an extension to the Specification and Example query APIs to support Stream.

Here are the methods and signatures:
https://github.com/seart-group/DL4SE/blob/274dbefd77f16b00cdace01d87a399a8308c7915/dl4se-server/src/main/java/ch/usi/si/seart/server/repository/support/JpaStreamExecutor.java

Here is the custom repository implementation:
https://github.com/seart-group/DL4SE/blob/274dbefd77f16b00cdace01d87a399a8308c7915/dl4se-server/src/main/java/ch/usi/si/seart/server/repository/support/ExtendedJpaRepositoryImpl.java

I would not be making changes to the class itself, in fact, it can be final for all I care, so long as its visible and can be instantiated from this custom SimpleJpaRepository extension.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Oct 26, 2023
@mp911de
Copy link
Member

mp911de commented Nov 2, 2023

Have you seen that you have all of this flexibility if you use the fluent findBy(Specification, q -> q.stream()) or findBy(Example, q -> q.stream()) API?

@dabico
Copy link
Author

dabico commented Nov 2, 2023

Have you seen that you have all of this flexibility if you use the fluent findBy(Specification, q -> q.stream()) or findBy(Example, q -> q.stream()) API?

HI @mp911de

I was not aware of this API, when was it introduced? I'm still on SB 2.7, and I don't think our organization will migrate to 3.X in the near future.

@mp911de
Copy link
Member

mp911de commented Nov 2, 2023

It has been introduced with version 3.0. Spring Data JPA 2.7 has reached its OSS EOL by now (Nov 2023) and we will ship only one final OSS release.
We generally avoid updates to API that has been released as changes to API that is available for quite a while asks for trouble.

Given that update, I'm closing the ticket.

@mp911de mp911de closed this as not planned Won't fix, can't repro, duplicate, stale Nov 2, 2023
@mp911de mp911de added status: declined A suggestion or change that we don't feel we should currently apply and removed status: waiting-for-triage An issue we've not yet triaged status: feedback-provided Feedback has been provided labels Nov 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: declined A suggestion or change that we don't feel we should currently apply
Projects
None yet
Development

No branches or pull requests

4 participants