|
From: Thomas R. <tho...@tr...> - 2004-07-17 18:30:23
|
We could add an update(PreparedStatementCreator, KeyHolder) method to
JdbcTemplate - should we get rid of the update(PreparedStatementCreator,
List) at the same time to keep things simpler? This would force the use
of the KeyHolder.
Thomas
jürgen höller [werk3AT] wrote:
>Oh, I didn't notice this. I was just wondering because JdbcTemplate's update(PreparedStatementCreator, List) method still takes a List for generated keys... Shouldn't it use a KeyHolder too? KeyHolder and co would have to reside in the core package then, I guess, because jdbc.core.support is intended to refer to jdbc.core but not the other way round. jdbc.support would be OK too, provided that KeyHolder does not depend on jdbc.core.
>
>Juergen
>
>
>________________________________
>
>Von: spr...@li... im Auftrag von Thomas Risberg
>Gesendet: Sa 17.07.2004 19:31
>An: spr...@li...
>Betreff: Re: [Springframework-developer] Generated keys support
>
>
>
>I added a KeyHolder interface and a GeneratedKeyHolder class (in
>jdbc.support). They are used by the SqlUpdate.update(Object[],
>KeyHolder) method.
>
>Here is an example:
>
> SqlUpdate su = new SqlUpdate(dataSource, "insert into Show2
>(name) values(?)");
> su.declareParameter(new SqlParameter("name", Types.VARCHAR));
> su.setReturnGeneratedKeys(true);
> su.setGeneratedKeysColumnNames(new String[] {"id"}); //this has
>no effect for MySQL only DB2
> su.compile();
> Object[] val = {"Sven"};
> KeyHolder kh = new GeneratedKeyHolder();
> int updateCnt = su.update(val, kh);
> int myKey = kh.getKey().intValue();
> System.out.println("Key: " + myKey);
> List myKeys = kh.getKeyList();
> System.out.println(myKeys);
>
>Direct JdbcTemplate use would look like:
>
> KeyHolder kh = new GeneratedKeyHolder();
> int rowsAffected =
>getJdbcTemplate().update(newPreparedStatementCreator(args),
>kh.getKeyList());
>
>
>Thomas
>
>jürgen höller [werk3AT] wrote:
>
>
>
>>Thomas,
>>
>>We discussed changing the List argument for generated keys into a GeneratedKeysHolder class or the like, for easier access to a single generated key (the typical use case). If we change that, we should do so before 1.1 RC1, even if this means having 1.1 RC1 mid or late next week rather than on Monday.
>>
>>Juergen
>>
>>
>>-------------------------------------------------------
>>This SF.Net email is sponsored by BEA Weblogic Workshop
>>FREE Java Enterprise J2EE developer tools!
>>Get your free copy of BEA WebLogic Workshop 8.1 today.
>>http://ads.osdn.com/?ad_idG21&alloc_id040&op=click
>>_______________________________________________
>>Springframework-developer mailing list
>>Spr...@li...
>>https://lists.sourceforge.net/lists/listinfo/springframework-developer
>>
>>
>>
>>
>>
>>
>>
>
>
>
>-------------------------------------------------------
>This SF.Net email is sponsored by BEA Weblogic Workshop
>FREE Java Enterprise J2EE developer tools!
>Get your free copy of BEA WebLogic Workshop 8.1 today.
>http://ads.osdn.com/?ad_id=4721&alloc_id=10040&op=click
>_______________________________________________
>Springframework-developer mailing list
>Spr...@li...
>https://lists.sourceforge.net/lists/listinfo/springframework-developer
>
>
>
>
>-------------------------------------------------------
>This SF.Net email is sponsored by BEA Weblogic Workshop
>FREE Java Enterprise J2EE developer tools!
>Get your free copy of BEA WebLogic Workshop 8.1 today.
>http://ads.osdn.com/?ad_idG21&alloc_id040&op=click
>_______________________________________________
>Springframework-developer mailing list
>Spr...@li...
>https://lists.sourceforge.net/lists/listinfo/springframework-developer
>
>
>
>
>
|