-
Notifications
You must be signed in to change notification settings - Fork 38.5k
Add Optional Support to JdbcTemplate #724
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
Conversation
f4a89b9
to
eaac98c
Compare
Any reason why this PR has been open for almost 2 years without any comments? What is the hold up for getting this functionality into the next (or any) release? |
@coryfoo We were not allowed to use Java8 types in public interfaces since we are compatible with Java 6, 7 and 8. Only the current master can use Java8 directly. Thanks for the ping. |
6c93d4f
to
4908ad2
Compare
Hey, since we are on spring5/java8 now, could we look into this again? |
@golonzovsky the discussion in the JIRA turned up that this PR adds yet another set of methods to |
Extend `JdbcTemplate` to support `Optional` for cases where queries return one or no row. - Add a `queryForOptional` method for every `queryForObject` method in `JdbcOperations`. - Implement the new methods in `JdbcTemplate`. - Add tests for the new methods in `JdbcTemplate`. Issue: SPR-12662
Team Decision: JdbcTemplate and other similar in the Spring Framework were not originally designed with |
@rstoyanchev I would understand this if there weren't |
The As an additional thought, |
The last point is now scheduled in #27728. |
I struggle with these arguments:
|
I never said it was impossible, but only that the main reason wasn't the Stream API itself. Rather it is a feature request focused on something that otherwise requires a more involved integration. Once available, a feature will be used for a wider range of cases than what it was introduced for, and some may be well suited for I don't really follow what you mean on 3) as the queryForStream method does close the connection. |
I really struggle to see the value over existing
Sure, but with stream most of the choices are bad ones. You have to try really hard to find ones that aren't a bad idea. Reductions that don't result in scalar values come to find but even these are error prone and cumbersome due to the need to call
Methods that are likely ok
to close the statement and the connection you have to use
In my opinion this is quite error prone. I set up an example with datasource-proxy to illustrate the issue https://github.com/marschall/jdbctemplate-queryforstream/blob/master/src/main/java/com/github/marschall/jdbctemplate/queryforstream/Main.java |
Okay, you don't like how #18474 was implemented. Do you have a suggestion for an improvement? |
@rstoyanchev sure, I see several options, some of them more focusing on smaller changes, other on bigger ones:
Going back to the original requirements of #18474 all I see is the requirement to "write a table with millions of rows to an output stream". And the author claiming
without providing any more details. I don't see why this can not be done with either a Without any more details I don't see any requirements that can not be solved just as well with the existing methods. |
Extend
JdbcTemplate
to supportOptional
for cases where queriesreturn one or no row.
queryForOptional
method for everyqueryForObject
method inJdbcOperations
.JdbcTemplate
.JdbcTemplate
.Issue: SPR-12662
I have signed and agree to the terms of the SpringSource Individual
Contributor License Agreement.