Skip to content
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

NamedParameterJdbcTemplate: add methods to simplify usage when no parameter is needed [SPR-10256] #14889

Closed
spring-issuemaster opened this issue Feb 4, 2013 · 0 comments
Assignees
Milestone

Comments

@spring-issuemaster
Copy link
Collaborator

@spring-issuemaster spring-issuemaster commented Feb 4, 2013

Michael Isvy opened SPR-10256 and commented

When working with NamedParameterJdbcTemplate, we typically inject an instance of it in a DAO/Repository and use it in 10-20 methods that require accessing the database.
Most of those methods use parameters (which is why we use a NamedParameterJdbcTemplate). However, among the 20 methods inside my DAO, it's common that I have 3-4 of them that use SQL queries without parameters.

In that case, the syntax could be improved.

We currently do:

return this.namedParameterJdbcTemplate.query(
				"SELECT id, name FROM types ORDER BY name", new HashMap<String,Object>(),
				ParameterizedBeanPropertyRowMapper.newInstance(Pet.class));

Inside NamedParameterJdbcTemplate, we could create some methods that do not take a HashMap as a parameter. We would then do instead:

return this.namedParameterJdbcTemplate.query(
				"SELECT id, name FROM types ORDER BY name", ParameterizedBeanPropertyRowMapper.newInstance(Pet.class));

Note: in the first code sample, replacing the empty HashMap with null is not an option because the method call then becomes ambiguous as 2 methods could be selected.


Referenced from: commits 3fa6723

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.