The current singleValue()
on the interface ResultQuerySpec expects 1 mandatory result, making confuse to get 0 or 1 results, wich is very common to have a query that returns 1 or 0 results, like this
SELECT somecolumn
FROM sometable
WHERE :somefilter
LIMIT 1
If that filter is not meet, the result is empty, and singleValue()
is not usefull
Current implementation:
default Object singleValue() {
return DataAccessUtils.requiredSingleResult(singleColumn());
}
The current implementation can be enhanced by just adding this extra method (using the existing DataAccessUtils method optionalResult.
default Object singleValue() {
return DataAccessUtils.requiredSingleResult(singleColumn());
}
default Optional<Object> optionalValue() {
return DataAccessUtils.optionalResult(singleColumn());
}
This will also help maintain coherence with the single()
and optional()
methods already provided on MappedQuerySpec.
Comment From: jhoeller
Good point, this goes together nicely with #33300 where we are enforcing non-null values contained in the result now.