-
Notifications
You must be signed in to change notification settings - Fork 38.3k
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
Add Optional Support to JdbcTemplate [SPR-12662] #17262
Comments
Philippe Marschall commented Here's the PR: |
Pekka Männistö commented Any news on this one? |
Sam Brannen commented Juergen Hoeller, what do you think about addressing this in the 5.0 time frame? |
Philippe Marschall commented I updated the PR since the master is now on 5 which has a minimum of Java 8. |
Philippe Marschall commented Any kind of feedback would be nice. |
Stéphane Nicoll commented My feedback is that there are a lot of method signatures in |
Kacper Stolc commented I'm a huge supporter of this feature. Spring Framework and Spring Data JPA use Optionals, so JDBC Template should also use it, because it makes code more clear. Catching exception in order to handle "no result" case is not very elegant (assuming we are searching for at most 1 result).
|
Stéphane Nicoll commented Kacper Stolc I don't think I meant anywhere it was a reason to dismiss this. |
Kacper Stolc commented
It might be a good idea to create separate ticket for removing unnecessary methods. |
Philippe Marschall commented @Kacper Stolc I don't think there are any not needed methods. I understood Stéphane Nicoll that current functionality would be provided without so many overloaded methods. Eg. something like
but that would be a new class that replaces JdbcTemplate. |
Philippe Marschall commented I updated the PR and resolved the merge conflict. To summarize so far
|
Juergen Hoeller commented On further review, instead of adding However, we're running out of time for 5.0, so I'd rather tackle this as a 5.1 topic (late 2017). |
@jhoeller If you don't mind, can you talk about the current plans on this? If a new abstraction is to be introduced, a possible inspiration could be fluent-jdbc. I find its API to be quite usable. |
Closing as discussed under #724. For the time being we have no plans to introduce a fluent alternative, that is other than the R2DBC |
Philippe Marschall opened SPR-12662 and commented
Problem
From time to time we find ourselves working on queries that may return either one for no row. We feel this situation is currently not well addressed with
JdbcTemplate
. Current options include:#queryForObject
and catchingEmptyResultDataAccessException
#query
or#queryForList
and checking the size of the listBoth of them feel rather cumbersome.
Proposal
We feel Java 8 Optionals are ideally suited for this problem. We therefore propose to add new
queryForOptional
methods with the following behaviourWe feel these semantics are natural match for
Optional
. Mapping both no row and SQLNULL
to an emptyOptional
may be a bit surprising at first however anOptional
can not contain Javanull
and returning Javanull
would seem against the sprit ofOptional
. We feel the name fits well into the existing naming pattern and gives users a clear indication of the behaviour to expect without having to read the Javadoc first.As the master in now on 5 which has a minimum of Java 8 these can be added directly to
JdbcTemplate
.Issue Links:
Referenced from: pull request #724
13 votes, 15 watchers
The text was updated successfully, but these errors were encountered: