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

feat: Add interfaces for CRUD services #20743

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,6 @@
public class CrudRepositoryService<T, ID, R extends CrudRepository<T, ID> & JpaSpecificationExecutor<T>>
extends ListRepositoryService<T, ID, R> implements CrudService<T, ID> {

/**
* Creates the service using the given repository and filter converter.
*
* @param repository
* the JPA repository
* @param jpaFilterConverter
* the JPA filter converter
*/
public CrudRepositoryService(R repository,
JpaFilterConverter jpaFilterConverter) {
super(repository, jpaFilterConverter);
}

/**
* Creates the service using the given repository.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import com.vaadin.flow.spring.data.filter.PropertyStringFilter;

/**
* Utility class for converting Hilla {@link Filter} specifications into JPA
* Utility class for converting {@link Filter} specifications into JPA
* filter specifications. This class can be used to implement filtering for
* custom {@link com.vaadin.flow.spring.data.ListService} or
* {@link com.vaadin.flow.spring.data.CrudService} implementations that use JPA
Expand All @@ -33,7 +33,7 @@ public class JpaFilterConverter {
* the entity class
* @return a JPA filter specification for the given filter
*/
public <T> Specification<T> toSpec(Filter rawFilter, Class<T> entity) {
public static <T> Specification<T> toSpec(Filter rawFilter, Class<T> entity) {
Artur- marked this conversation as resolved.
Show resolved Hide resolved
if (rawFilter == null) {
return Specification.anyOf();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
public class ListRepositoryService<T, ID, R extends CrudRepository<T, ID> & JpaSpecificationExecutor<T>>
implements ListService<T>, GetService<T, ID>, CountService {

private final JpaFilterConverter jpaFilterConverter;

private final R repository;

private final Class<T> entityClass;
Expand All @@ -33,26 +31,12 @@ public class ListRepositoryService<T, ID, R extends CrudRepository<T, ID> & JpaS
*
* @param repository
* the JPA repository
* @param jpaFilterConverter
* the JPA filter converter
*/
public ListRepositoryService(R repository,
JpaFilterConverter jpaFilterConverter) {
this.jpaFilterConverter = jpaFilterConverter;
public ListRepositoryService(R repository) {
this.repository = repository;
this.entityClass = resolveEntityClass();
}

/**
* Creates the service using the given repository.
*
* @param repository
* the JPA repository
*/
public ListRepositoryService(R repository) {
this(repository, new JpaFilterConverter());
}

/**
* Accessor for the repository instance.
*
Expand Down Expand Up @@ -98,7 +82,7 @@ public long count(@Nullable Filter filter) {
* @return a JPA specification
*/
protected Specification<T> toSpec(@Nullable Filter filter) {
return jpaFilterConverter.toSpec(filter, entityClass);
return JpaFilterConverter.toSpec(filter, entityClass);
}

@SuppressWarnings("unchecked")
Expand Down
Loading