You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-user@db.apache.org by T E Schmitz <ma...@numerixtechnology.de> on 2004/04/23 17:22:05 UTC

SELECT FOR UPDATE

Hello,

Is there any means of doing a SELECT for UPDATE, ie to lock a record in 
a transaction?

I mark every record with a 'LastUpdated' timestamp in order to be able 
to check whether it has been updated in the meantime in another session. 
Before any UPDATE or DELETE I re-read the record and compare timestamps. 
But the record really needs to be locked; otherwise there is still a 
window between the SELECT and the UPDATE during which another session 
could modify or delete it.

Does anyone know how to achieve this through Torque?

-- 


Regards,

Tarlika Elisabeth Schmitz

---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


Re: SELECT FOR UPDATE

Posted by T E Schmitz <ma...@numerixtechnology.de>.
Yes, I am doing the following in a transaction:

1) SELECT the record which is to be updated
2) compare timestamps of the newly read record and the one passed down
3) IF timestamps are equal (ie nobody else has updated the record in the 
meantime) THEN UPDATE the record as per passed object setting the 
timestamp to current time.


The above transaction will not be water-tight if the SELECT isn't a 
SELECT FOR UPDATE. Only a SELECT FOR UPDATE will lock the record. If the 
record isn't locked, it could be modified/deleted in another session 
between steps 1) and 3).


Regards,

Tarlika Elisabeth Schmitz


Dave Newton wrote:
> On Fri, 2004-04-23 at 11:22, T E Schmitz wrote:
> 
>>Is there any means of doing a SELECT for UPDATE, ie to lock a record in 
>>a transaction?
> 
> 
> Can you just do the entire operation in a transaction using the Torque
> transaction methods? 
> 
> http://db.apache.org/torque-31/apidocs/org/apache/torque/util/Transaction.html
> 
> HTH,
> Dave
> 
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org