View Full Version : Does Spring Framework support Select for Update
bongosdude
Sep 8th, 2004, 08:32 PM
Can someone show me how the 'Select for Update' work in Spring Framework?
Thanks.
Loumeister
Sep 8th, 2004, 11:05 PM
I think this is something that you do in your persistence framework. For instance, Hibernate allows for optimistic locking that actually defaults to use versioning which is better performing than SELECT FOR UPDATE.
Lou
Rod Johnson
Sep 9th, 2004, 04:19 AM
If using Spring JDBC you can simply use the "FOR UPDATE" syntax in your SQL queries. If you use Hibernate or another ORM tool with Spring, you should refer to the documentation on using pessimistic locking with that tool: Spring will leave locking to the persistence layer.
Spring JDBC does understand and correctly translate SQL exceptions resulting from SELECT FOR UPDATE NOWAIT btw.
trisberg
Sep 9th, 2004, 05:42 AM
There is also UpdatableSqlQuery that operates on an updatable ResultSet. It lets you map/update row values in an updateRow callback method. It is similar to the MappingSqlQuery class except that it lets you update the rows as they pass through.
private class MyUpdate extends UpdatableSqlQuery {
private final static String sql = "select id, price from booking where id > ?";
public MyUpdate(DataSource ds) {
super(ds, sql);
declareParameter(new SqlParameter("id", Types.INTEGER));
compile();
}
protected Object updateRow(ResultSet rs, int rowNum, Map context) throws SQLException {
BigDecimal price = rs.getBigDecimal(2);
price = price.multiply(new BigDecimal(1.1));
rs.updateBigDecimal(2, price);
return price;
}
}
Powered by vBulletin® Version 4.2.1 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.