|
From: Thomas R. <tho...@tr...> - 2006-03-11 17:36:27
|
I'm looking at adding support for named parameters to
SimpleJdbcTemplate and need some opinions from an API perspective.
The code changes involved are straight forward but I don't want to
turn the SimpleJdbcTemplate into a ComplexJdbcTemplate.
To start with we have a couple of options:
- add support to the existing class
- don't bother with named parameter support for this class at all
The scond one would mean that all named parameter support would only
be available from NamedParameterJdbcTemplate without any of the Java
5 features. But this:
List<Beer> l = simpleJdbcTemplate.query(
"select * from beers where id in ( :ids )",
beerMapper,
argMap);
would be kind of nice to support.
There are 8 methods in the current implementation taking an
'Object... args' as the last argument. We could simply double that
adding a corresponding method taking a Map for the arguments. This
is where I'm leaning currently. Another option would be to leave
the API as is but detect the type of the first object in the
'Object... args' array is. If it's a Map do the named parameter
support. Don't like this since the API does not give much help to
the user here.
Couple of additional issues:
- What if you pass a query like "select * from beers where id = :id"
to a method without named parameter support. We could just accept
named parameters everywhere and simply replace them with '?'
placeholders before executing the query. Some Oracle JDBC drivers
actually supports this usage as well.
- There is no convenient way to set options on the JdbcTemplate if
you use the SimpleJdbcTemplate - like nativeJdbcExtractor or
fetchSize. Should we expose these methods or leav it as is forcing
the user to inject a JdbcTemplate with these settings specified?
Thomas
|