Hi everybody,
i would like to select a table row and lock it in same time. I read on some post that this can be done by executing a SELECT ... FOR UPDATE query. I tried this but it does not work with SimpleJDBCTemplate. Here is what i did :
Does anyone has had this problem? may i have an example?Code:@Override @Transactional(isolation=Isolation.REPEATABLE_READ ) public Delivery findForUpdateByDeliveryStatus(DeliveryStatus statusToFind, DeliveryStatus newStatus) { String sql = "select * from delivery where status = ? order by creation_date desc limit 1 FOR UPDATE NOWAIT"; List<Delivery> deliveries = super.getSimpleJdbcTemplate().query(sql, new DeliveryParameterizedRowMapper(), statusToFind.value()); Delivery del = deliveries.get(0); this.updateStatus(del, newStatus); return del; } public int[] updateStatus(Delivery delivery, DeliveryStatus status) { String sql = "UPDATE "+Delivery.TABLE_NAME+" SET "+ColumnName.STATUS.value()+" ='"+status.value()+"' " + "WHERE "+ColumnName.DELIVERY_ID+" = "+delivery.getDeliveryId(); return this.insertBatchSQL(sql); } private int[] insertBatchSQL(final String sql){ return super.getJdbcTemplate().batchUpdate(new String[]{sql}); }
Thanks for your help,


Reply With Quote
