Table locking with ActiveRecord

Hi,

what is the preferred way to lock a table for writes using
ActiveRecord? I have a custom id field (i.e. not auto_increment) which
uniqueness I would like to protect in the following way:
begin transaction and lock table for writes
  select latest id from table
  insert new row with id = latest_id+1
commit and unlock

As far as I can see this functionality isn't provided by the current
ActiveRecord version and I am a bit unsure how to implement it in a
"Rails way". I am using MySQL 5 wiht InnoDB as a storage engine.

Cheers,
Phil