Skip to content

Commit

Permalink
Simplify as JpaFilterConverter now only has one helper method
Browse files Browse the repository at this point in the history
  • Loading branch information
Artur- committed Dec 18, 2024
1 parent 7fd7590 commit 2f7a5db
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 33 deletions.
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) {
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

0 comments on commit 2f7a5db

Please sign in to comment.