Getting benifits of database transactions in an OO way?
Leif K-Brooks
eurleif at ecritters.biz
Sat Aug 21 21:31:22 EDT 2004
Paul Rubin wrote:
> Leif K-Brooks <eurleif at ecritters.biz> writes:
>>Right now, the Person.save_data method also commits the current
>>database transaction. But that seems to remove the benifit of having a
>>database with transactions: If something dies between the call to
>>fred.save_data() and barney.save_data(), Fred's $10 will end up in a
>>black hole somewhere.
>
>
> You have to use transactions for that. E.g.
>
> import people
> this_transaction = people.begin_transaction()
> fred = this_transaction.find_by_name('Fred Flintstone')
> barney = this_transaction.find_by_name('Barney Rubble')
> fred.money -= 10
> barney.money += 10
> this_transaction.finish_transaction()
How woould begin_transaction() and finish_transaction() be implemented?
They couldn't be simple wrappers for PostgreSQL transaction handling,
since it's not very object-oriented (the whole connection has one
transaction at a time).
More information about the Python-list
mailing list