How to get default expression from CriteriaBuilder inside Specification
I building a search query for area, whether it's just greater than start bound, lesser than end bound or between them. I am refactoring the method and wrapping if clauses inside the single Specification predicate body. Before that an Specification was returned in each case.
private Specification whereArea(Specification spec, ListingSearchDTO dto) {
return (root, _, builder) -> {
Path area = root.get("apartment").get("area");
if (dto.getM2From() != null && dto.getM2To() != null)
return builder.between(area, dto.getM2From(), dto.getM2To());
if (dto.getM2From() != null)
return builder.ge(area, dto.getM2From());
if (dto.getM2To() != null)
return builder.le(area, dto.getM2To());
return builder.; // return something here
};
}
What should I return as the default result? I can't seem to find anything about that in the docs.