|
From: <jue...@we...> - 2004-03-16 22:02:20
|
BTW, a further benefit of the "execute(StatementCallback)", =
"execute(PreparedStatementCallback)" and =
"execute(CallableStatementCallback)" methods is that they are modelled =
analogously to our Hibernate and JDO support, i.e. they are analogous to =
the "HibernateTemplate.execute(HibernateCallback)" and =
"JdoTemplate.execute(JdoCallback)" methods in that they provide a =
generic callback for implementing any kind of operation within a =
passed-in resource.
=20
As a side note, JdbcTemplate is now about 40 lines *shorter* than =
before, despite the introduction of the 5 new "execute" methods - due to =
the internal refactorings that the new methods allow for.
=20
Juergen
=20
________________________________
Von: spr...@li... im Auftrag =
von j=FCrgen h=F6ller [werk3AT]
Gesendet: Di 16.03.2004 20:56
An: spr...@li...
Betreff: Re: [Springframework-developer] JdbcTemplate update example
Thomas,
Do you mind dropping the "update(PreparedStatementCreator[])" method? It =
just seems so arbitrary: We'd need to provide "update" methods with =
multiple SQL statements etc then too, for consistency's sake... And I =
assume you don't mind renaming the "doWithResultSetFromXxx" methods to =
"query"?
Juergen
________________________________
Von: spr...@li... im Auftrag =
von j=FCrgen h=F6ller [werk3AT]
Gesendet: Di 16.03.2004 15:55
An: spr...@li...
Betreff: [Springframework-developer] Re: [Springframework-user] =
JdbcTemplate update example
In the course of this change, I suggest two further minor changes:
- The "doWithResultSetFromXxx" methods should really be named "query", =
just with overloaded ResultSetExtractor arguments. There is no strong =
difference to the other "query" methods that take all sorts of argument =
combinations (particularly since the introduction of "queryForList" =
etc). I don't think that this renaming will cause hassle, as I suspect =
that hardly anyone uses those methods anyway.
- I don't think that the "update" method that takes a =
PreparedStatementCreator array is very helpful: It doesn't use batching =
or reuse Statement instances but just executes the created =
PreparedStatements one-by-one. I suggest to remove that overloaded =
method: Application code should simply invoke =
"update(PreparedStatementCreator)" for each statement. I guess that the =
PreparedStatementCreator array version is rarely used too, and the =
replacement is straightforward.
Juergen
-----Original Message-----
From: j=FCrgen h=F6ller [werk3AT]
Sent: Tuesday, March 16, 2004 3:39 PM
To: 'spr...@li...';
spr...@li...
Subject: Re: [Springframework-user] JdbcTemplate update example
Will, everyone,
Our current JdbcTemplate does indeed not cover such use cases: It rather =
assumes that each operation will use its own (Prepared)Statement =
instance.
Therefore, I've added further JdbcTemplate methods that take generic =
callback actions:
- execute(StatementCallback)
- execute(String sql, PreparedStatementCallback)
- execute(String sql, CallableStatementCallback)
Each of the callback interfaces has a single "Object =
doInStatement(Statement)"-style method, allowing for any number of =
operations to be performed on the passed-in statement.
There also overloaded versions that take statement creators:
- execute(PreparedStatementCreator, PreparedStatementCallback)
- execute(CallableStatementCreator, CallableStatementCallback)
I've refactored all of JdbcTemplate's existing data access methods to =
use those generic execute methods with inner-class callback =
implementations: This has removed almost all internal code duplications =
that were necessary before.
I believe that this is an important addition: Reusing a statement =
instance for multiple executions with different parameters is a valid =
and quite common use case. And cleaning the JdbcTemplate internals is a =
nice side effect.
Awaiting your feedback! (I haven't committed that change yet, but intend =
to do so before the release this weekend.)
Juergen
-----Original Message-----
From: spr...@li...
[mailto:spr...@li...]On Behalf Of
Will Jaynes
Sent: Monday, March 15, 2004 8:10 PM
To: spr...@li...
Subject: [Springframework-user] JdbcTemplate update example
I'm converting some of my JDBC DAOs to Spring JdbcTempate usage. I'm
afraid I need an example of reusing a PreparedStatement over a number of
updates. The update methods for JdbcTemplate all seem to create a
PreparedStatement, so perhaps I can't use any of them.
The old code looks something like:
public void doAnUpdate(Connection conn, String[] ids) {
...
ps =3D conn.prepareStatement("Update A set B =3D null where id =3D ?");
for (int i=3D0; i<ids.length; i++)
ps.setString(id[i]);
ps.executeUpdate();
}
...
Thanks for any help,
Will
-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id=3D1470&alloc_id=3D3638&op=3Dcli=
ck
_______________________________________________
Springframework-user mailing list
Spr...@li...
https://lists.sourceforge.net/lists/listinfo/springframework-user
-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id=1470&alloc_id638&op=3Dick
_______________________________________________
Springframework-developer mailing list
Spr...@li...
https://lists.sourceforge.net/lists/listinfo/springframework-developer
-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id=1470&alloc_id638&op=3Dick
_______________________________________________
Springframework-developer mailing list
Spr...@li...
https://lists.sourceforge.net/lists/listinfo/springframework-developer
|