view · edit · sidebar · attach · print · history

ODBA - Transaction Rollback

<< TransparentHashAccess | Index | NamedAccess >>

Only tested with postgres backend

 require 'odba'

 class Container
   attr_accessor :foo
 end
 class Foo
   include ODBA::Persistable
   attr_accessor :bar
 end

 ODBA.storage.dbi = DBI.connect('DBI:pg:test', 'hwyss', '')

 container = Container.new
 container.foo = foo = ODBA.cache.fetch_named('foo', container) { Foo.new }
 foo.bar = 'before transaction'
 foo.odba_store

 begin
   ODBA.transaction {
     foo.bar = 'after transaction'
     foo.odba_store
     raise 'some silly error'
   }
 rescue RuntimeError
 end
 container.foo.bar

returns

 'before transaction'
view · edit · sidebar · attach · print · history
Page last modified on March 15, 2011, at 03:42 PM