I'm new to Jdbi and just started to use it for one of my projects. I have a use case that I think is pretty common but not sure the best way to solve it using jdbi3. The use case is when querying for data, I want to return a Optional<T> when there is 0 or 1 result row, but throw an exception when there are multiple rows in the result set.
I can use findOnly(), then catch the IllegalStateException and match on the message, but that feels like a hack. There's also findFirst(), but it stops on the first row and doesn't check if there are actually multiple rows in the result set. And I don't think I want to incur the overhead of collecting into a list and then do checks on that... Does anyone also have this use case and a good solution for it?
On the other hand, this seems like a low-hanging fruit. Is there a reason why there isn't an API for it in jdb3?