Open amatosg opened 3 months ago
this are the proposed methods that I'm currently using for my needs. Complexity is reduced from 356% to 6% in the most extreme cases. I guess it could be improved :wink:
Missing: relational and enum specifications. I tried but it doesn't work
protected Specification<ENTITY> getStringSpecification(
Specification<ENTITY> specification,
StringFilter filter,
SingularAttribute<ENTITY, String> attribute
) {
if (stringFilter != null) {
specification = specification.and(buildStringSpecification(filter, attribute));
}
return specification;
}
protected Specification<ENTITY> getBooleanSpecification(
Specification<ENTITY> specification,
BooleanFilter filter,
SingularAttribute<ENTITY, Boolean> attribute
) {
if (booleanFilter != null) {
specification = specification.and(buildSpecification(filter, attribute));
}
return specification;
}
protected Specification<ENTITY> getUuidSpecification(
Specification<ENTITY> specification,
UUIDFilter filter,
SingularAttribute<ENTITY, UUID> attribute
) {
if (stringFilter != null) {
specification = specification.and(buildSpecification(filter, attribute));
}
return specification;
}
protected Specification<ENTITY> getDistinctSpecification(Specification<ENTITY> specification, Boolean distinct) {
if (distinct != null) {
specification = specification.and(distinct(distinct));
}
return specification;
}
protected Specification<ENTITY> getLongSpecification(
Specification<ENTITY> specification,
LongFilter filter,
SingularAttribute<ENTITY, Long> attribute
) {
if (longFilter != null) {
specification = specification.and(buildRangeSpecification(filter, attribute));
}
return specification;
}
protected Specification<ENTITY> getIntegerSpecification(
Specification<ENTITY> specification,
IntegerFilter filter,
SingularAttribute<ENTITY, Integer> attribute) {
if (integerFilter != null) {
specification = specification.and(buildRangeSpecification(filter, attribute));
}
return specification;
}
protected Specification<ENTITY> getZonedDateTimeSpecification(
Specification<ENTITY> specification,
ZonedDateTimeFilter filter,
SingularAttribute<ENTITY, ZonedDateTime> attribute) {
if (zonedDateTimeFilter != null) {
specification = specification.and(buildRangeSpecification(filter, attribute));
}
return specification;
}
protected Specification<ENTITY> getLocalDateSpecification(
Specification<ENTITY> specification,
LocalDateFilter filter,
SingularAttribute<ENTITY, LocalDate> attribute) {
if (zonedDateTimeFilter != null) {
specification = specification.and(buildRangeSpecification(filter, attribute));
}
return specification;
}
protected Specification<ENTITY> getBigDecimalSpecification(
Specification<ENTITY> specification,
BigDecimalFilter filter,
SingularAttribute<ENTITY, BigDecimal> attribute) {
if (bigDecimalFilter != null) {
specification = specification.and(buildRangeSpecification(filter, attribute));
}
return specification;
}
Overview of the feature request
Remove many, many lines of code and move them to the abstract class
QueryService
.Motivation for or Use Case
This feature is important because the code will be less complex, therefore cleaner and more redeable and maintainable.
Instead of having many, many
if
statements,there would be only one line:
The
QueryService
abstract class would have this method (or something similar)This can be applied to other specifications (booleans, ranged, etc)
Related issues or PR