|
From: Colin S. <col...@ex...> - 2004-12-04 19:20:24
|
Let's do the ConnectionCallback then. I'll try to add it tomorrow if you don't get to it; I'm working on some other code today. As for just converting SQL exceptions, I agree that there's no resource management, but I'm not so sure the templates are just about resource maangement. They're also all about automatic exception translation. I agree though that in the case you don't need any resources, it's probably just as easy to catch the SQLException yourself, and use a translator, as opposed to creating an anonymous class for the callback.. It's just a matter of getting at that translator easily. This is easy if yuo have a jdbcTemplate. If all you are workig with is the JdbcOperations interface it's harder, since it doesn't expose it, so you have to get it in separately... Colin jürgen höller [werk3AT] wrote: >We already have a StatementCallback and a PreparedStatementCallback, for example, letting you execute the same Statement object multiple times or whatever you want to do with it. User code is just responsible for closing ResultSets in that case. > >I've considered adding a ConnectionCallback before, passing a managed Connection object in and converting all SQLExceptions. User code would then be responsible for closing Statements and ResultSets accordingly. I wouldn't mind adding such a callback. > >However, a plain callback that just converts SQLExceptions doesn't really fit into JdbcTemplate, because there's no resource managed there. JdbcTemplate wouldn't do anything here; all that's needed is a SQLExceptionTranslator. Therefore, it's probably cleaner to use a try/catch block and delegate to a SQLExceptionTranslator when catching a SQLException. The translator could come from a bean property of type SQLExceptionTranslator, or from getJdbcTemplate().getExceptionTranslator() in a JdbcDaoSupport subclass. > >Juergen > > >________________________________ > >Von: spr...@li... im Auftrag von Colin Sampaleanu >Gesendet: Fr 03.12.2004 14:16 >An: spr...@li... >Betreff: Re: [Springframework-developer] JdbcOperationsCallback > > > >Sure, the whole point is that this is not something you are going to use >given the choice to use other methods on the template, but mainly when >you need to wrap existing code which throws SQLException. In the >particular case I needed yesterday, I actually also needed to pass a >connection to the other code. There could be a variant which gets a >connection for you, for this sort of case. I don't like the >possibility that people will now use this sort of method to write >old-style code which doesn't clean up resources properly, as you >mention, but on the other hand, if we document it well it will hopefully >be helpful for these kinds of situations. In this case, I ended up >having to manage the connection myself, and had to wrap to catch SQL >exceptions, etc.... > >Colin > > >Thomas Risberg wrote: > > > >>The only drawback that I can think of is that now you are responsible >>for closing any statements/resultsets that you open - you need to >>provide a try/finally block within the callback to properly close them >>in case of an exception being thrown. As long as we document this, we >>should be OK. >> >>Thomas >> >>Colin Sampaleanu wrote: >> >> >> >>>Does anybody think it doesn't make sense to add a >>>JdbcOperationsCallback interface, similar to some of the other >>>callbacks, which can be used via a new >>> jdbcTemplate.execute(JdbcOperationsCallback) >>>method? This could be used to wrap arbitrary code which throws SQL >>>exceptions, so that they are properly mapped. I've had a need for >>>something like this a few times... >>> >>> > > > >------------------------------------------------------- >SF email is sponsored by - The IT Product Guide >Read honest & candid reviews on hundreds of IT Products from real users. >Discover which products truly live up to the hype. Start reading now. >http://productguide.itmanagersjournal.com/ >_______________________________________________ >Springframework-developer mailing list >Spr...@li... >https://lists.sourceforge.net/lists/listinfo/springframework-developer > > > > >------------------------------------------------------- >SF email is sponsored by - The IT Product Guide >Read honest & candid reviews on hundreds of IT Products from real users. >Discover which products truly live up to the hype. Start reading now. >http://productguide.itmanagersjournal.com/ >_______________________________________________ >Springframework-developer mailing list >Spr...@li... >https://lists.sourceforge.net/lists/listinfo/springframework-developer > > |