Results 1 to 4 of 4

Thread: Does Spring Framework support Select for Update

  1. #1
    Join Date
    Sep 2004
    Posts
    14

    Default Does Spring Framework support Select for Update

    Can someone show me how the 'Select for Update' work in Spring Framework?

    Thanks.

  2. #2
    Join Date
    Aug 2004
    Posts
    218

    Default

    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

  3. #3
    Join Date
    Aug 2004
    Location
    San Mateo, CA
    Posts
    1,265

    Default

    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.
    Rod Johnson - GM, SpringSource Division, VMware
    http://www.springsource.com
    Spring From the Source

  4. #4
    Join Date
    Aug 2004
    Posts
    1,104

    Default

    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.
    Code:
    	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;
    		}
    		
    	}
    Thomas Risberg
    SpringSource by Pivotal
    http://www.springsource.org

Similar Threads

  1. Spring MVC Web Framework versus Struts
    By biguniverse in forum Web Flow
    Replies: 27
    Last Post: Aug 29th, 2012, 03:57 AM
  2. hibernate pagination
    By oliverchua in forum Data
    Replies: 8
    Last Post: Sep 23rd, 2005, 06:06 PM
  3. Replies: 3
    Last Post: Sep 8th, 2005, 03:41 PM
  4. Spring Framework 1.2 Released
    By Colin Sampaleanu in forum Announcements
    Replies: 0
    Last Post: May 13th, 2005, 11:20 PM
  5. Replies: 14
    Last Post: Feb 21st, 2005, 05:41 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •