Sep 24th, 2012, 04:08 AM
Why can't a Spring Data Specification return a null Predicate?
Why can't a Spring Data Specification return a null Predicate? Would't it be sensible to not add it to criteria query if Specification.toPredicate returns null?
I have the following use case:
String q = "<some search query>" // this can be something like "Davy Jones" or "31-12-2011"
Page<Receipt> page = receiptRepository.findAll(where(receiptDateEquals( q)).or(customerNameContains(q)), pageable);
Think about q as a generic query string submitted via a web search form.
Then in the receiptDateEquals specification I'm converting the search query to a date, if it succeeds fine and return the appropriate predicate, otherwise return no predicate / null.
It's off course debatable if I should the date conversion in the specification or in the controller itself.
I would like to opt for a central place in the specification itself so calling controller actions don't have to take care.
That's why I wonder why the Sepcifciation.toPredicate can'y just return null if needed.