
kakimoto at tpg
Jul 6, 2009, 2:21 AM
Post #4 of 18
(1756 views)
Permalink
|
|
Re: how to implement Transactions (over different db tables) in a Catalyst project
[In reply to]
|
|
hello there, Tomas, Thank you :) Yes, you're quite right there:) Prior to receiving this reply, I actually wrapped my existing code in the subroutine within an sub for the txn_do. sub save_complete_records { ... eval { $c->model('myAppDB')->schema->txn_do( sub { ... $c->forward( '/subscriptions/_save_address', [ { 'policy_id' => $policy_id, } ] ); ... } if ($@) { $c->log->debug(' Exception manually trapped here : ' . $@ ); $c->model('myAppDB')->schema->txn_rollback or die "Cannot ROLL BACK - Address module"; $c->log->debug(' manually rolled back' ); $c->error( q{ An error has occured with the listing. If this problem } . q{persists please contact our helpdesk at helpdesk [at] insuranceline}. q{com.nz.} ); } } To test, I purposedly entered a very long string for one of the database attributes to make the transaction fail. I have the following questions: 1) I looked at the terminal with all the debug messages. I noticed that the exception was caught and eventhough the roll back was done, I do not see the print outs from the liens within the "if ($@)" (exception handling) section above. Why is that? 2) I noticed that whilst the rollback was successful. the sequence do not get rolled back. IS this desired behaviour of DBIx::Class? To illustrate, before the exception was caught, an entry was made in my User_Subscriptions database table. The ID was printed out and I took note of it. When the operation was complete, I queried my User_Subscriptions database table (using psql for postgresql for an entry of the noted ID). No entry of the noted ID was returned. I went back to the webpage and entered the form with valid attributes and yes, all necessary objects were created in the database backend and the sequence in the User_Subscriptions database table had increased by 1. Any ideas, Tomas and everyone? :) thank you :) k. akimoto On Mon, Jul 6th, 2009 at 6:18 PM, Tomas Doran <bobtfish [at] bobtfish> wrote: > This is fairly easy to get wrong - txn_do forces you to have a block > > which comprises the transaction scope, or your code won't compile. > > It will start a transaction at the start of the block, and commit it > > at the end if an exception hasn't been encountered during the > transaction > _______________________________________________ List: Catalyst [at] lists Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst [at] lists/ Dev site: http://dev.catalyst.perl.org/
|