-
-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Simplify QueryService #26913
Comments
DanielFran
added
area: enhancement 🔧
theme: jhipster-lib
and removed
area: triage
theme: undefined
labels
Aug 6, 2024
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 😉 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;
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
The text was updated successfully, but these errors were encountered: