Re: [Catalyst] how to implement Transactions (over different db tables) in a Catalyst project
Kakimoto I recommend you read this article http://blog.urth.org/2009/07/what-is-catalyst-really.html It might help you understand more when its a Catalyst Issue or a another component issue! And help you better trouble shoot your problems. Apparently Catalyst will help you send a request to the data model and return the request result to a view The content of the request and its semantic apparently from this conversation and the article is the Model responsibility So if the Model is Transaction capable, you will have transaction! Can transactions be implemented at the Catalyst/glue level, apparently Catalyst was not conceived to do so! I hope this helped! ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] how to implement Transactions (over different db tables) in a Catalyst project
kakim...@tpg.com.au wrote: Sorry, after reading it again after the many responses to this thread, I realised it's ok. It's _NOT OK_, as you didn't get it first time. So it's obviously not clear *enough*. Please supply the DBIC list with a doc patch to make it more clear and explicit. Thanks t0m ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] how to implement Transactions (over different db tables) in a Catalyst project
On 6 Jul 2009, at 06:30, kakim...@tpg.com.au wrote: In the past, when I had to work with just DBI, I would manually start a transaction and commit it at the end if no exceptions occur. In the case of the latter, I will call a rollback. 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 How do I do it here in Catalyst/DbiX::Class land? I tried to read up the http://kobesearch.cpan.org/htdocs/DBIx-Class/DBIx/Class/ Storage.html#txn_do doc but I can't see how the example can apply to Catalyst. It says, $schema-txn_do($coderef) to get the schema but in catalyst, we access the database tables directly. For example, $c-model('myAppDB') gets the schema I'm a bit confused and have looked in a few places. Can anyone please educate me? $c-model('myAppDB')-txn_do( sub { my $rs = $c-model('myAppDB::Table')-search(..); # Etc etc die(Rollback) if $foo; # Exceptions cause rollback # Etc etc # If you get here, to the end, transaction is committed for you. }); Can you please supply a doc patch for one or two of the places you looked to find this information which will explain it more clearly for the next person? Cheers t0m ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] how to implement Transactions (over different db tables) in a Catalyst project
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 helpd...@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 bobtf...@bobtfish.net 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@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] how to implement Transactions (over different db tables) in a Catalyst project
Tomas Doran wrote: $c-model('myAppDB')-txn_do( sub { my $rs = $c-model('myAppDB::Table')-search(..); # Etc etc die(Rollback) if $foo; # Exceptions cause rollback # Etc etc # If you get here, to the end, transaction is committed for you. }); And I'm crap. You need $c-model('myAppDB')-schema-txn_do( sub { Cheers t0m ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] how to implement Transactions (over different db tables) in a Catalyst project
hi Tomas and everyone:) I still have some questions as per my prev post. Can you please help me out? :) 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. .snip. And I'm crap. You need $c-model('myAppDB')-schema-txn_do( sub { Cheers ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] how to implement Transactions (over different db tables) in a Catalyst project
So, in the case of an exception, an automatic rollback will take place. I have tested this in my application and it seems that way. Can anyone confirm this? Thank you:) 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@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] how to implement Transactions (over different db tables) in a Catalyst project
On 6 Jul 2009, at 12:38, kakim...@tpg.com.au wrote: So, in the case of an exception, an automatic rollback will take place. I have tested this in my application and it seems that way. Did you look what the code does? http://cpansearch.perl.org/src/RIBASUSHI/DBIx-Class-0.08107/lib/DBIx/Class/Storage.pm and http://cpansearch.perl.org/src/RIBASUSHI/DBIx-Class-0.08107/t/81transactions.t See sub txn_do. It begins a transaction, runs your coderef inside an eval, rolls back the transaction if the eval raises an exception. However, this is NOT a Catalyst question. Please subscribe to the DBIx::Class users list at: http://lists.scsys.co.uk/mailman/listinfo/dbix-class/ and ask these questions there. Many of the subscribers are the same, but many Catalyst users don't use DBIx::Class, and many knowledgeable DBIC users are not subscribed here. It's just good hygiene to ask the questions in the appropriate places. Questions specific to Catalyst::Model::DBIC::Schema are fine here, but you must realise that everything after C $c-model(MyDBICSchema) or C $c-model(MyDBICSchema::MyResultSetClass) is handled by DBIx::Class and has nothing to do with Catalyst? Thanks, /joel ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] how to implement Transactions (over different db tables) in a Catalyst project
On 6 Jul 2009, at 12:32, kakim...@tpg.com.au wrote: hi Tomas and everyone:) I still have some questions as per my prev post. Can you please help me out? :) Sorry, this is too far into DBIC land for this list IMO. Please ask on that list. Cheers t0m ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] how to implement Transactions (over different db tables) in a Catalyst project
On 6 Jul 2009, at 12:38, kakim...@tpg.com.au wrote: So, in the case of an exception, an automatic rollback will take place. I have tested this in my application and it seems that way. Can anyone confirm this? Did you even look for this in the manual? http://search.cpan.org/~ribasushi/DBIx-Class-0.08107/lib/DBIx/Class/ Storage.pm#txn_do If not, why not. If so, how is this not clear? Cheers t0m ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] how to implement Transactions (over different db tables) in a Catalyst project
Did you look what the code does? http://cpansearch.perl.org/src/RIBASUSHI/DBIx-Class-0.08107/lib/DBIx/Class/Storage.pm and http://cpansearch.perl.org/src/RIBASUSHI/DBIx-Class-0.08107/t/81transactions.t If the API doc is written well, I suppose one doens't need to look at the source code (unless forced to). I must admit that I didn't fallback to looking at the regression test. I will do so next time:) See sub txn_do. It begins a transaction, runs your coderef inside an eval, rolls back the transaction if the eval raises an exception. Yes I did but at that point in time, the documentation on txn_do wasn't that clear. I think someone must have updated it since this question was raised. However, this is NOT a Catalyst question. Please subscribe to the DBIx::Class users list at: http://lists.scsys.co.uk/mailman/listinfo/dbix-class/ and ask these questions there. Many of the subscribers are the same, but many Catalyst users don't use DBIx::Class, and many knowledgeable DBIC users are not subscribed here. It's just good hygiene to ask the questions in the appropriate places. there's somethign wrong with the mailing list for Dbix::Class as I have not been able to get replies /mails. I have contacted the admin in the past and never got any reply. I will retry. Nevertheless, given that Dbix::Class is of the choice for catalyst, I figured the grey area here may see my questions lucky enough to have some replies from the many who use Dbix::Class for their Catalyst apps. ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] how to implement Transactions (over different db tables) in a Catalyst project
Did you even look for this in the manual? http://search.cpan.org/~ribasushi/DBIx-Class-0.08107/lib/DBIx/Class/ Storage.pm#txn_do If not, why not. If so, how is this not clear? Well, it's really clear now . I suppose someone has updated the documentation since I posted this thread up. ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] how to implement Transactions (over different db tables) in a Catalyst project
On Monday 06 July 2009 05:37:49 pm kakim...@tpg.com.au wrote: Did you even look for this in the manual? http://search.cpan.org/~ribasushi/DBIx-Class-0.08107/lib/DBIx/Class/ Storage.pm#txn_do If not, why not. If so, how is this not clear? Well, it's really clear now . I suppose someone has updated the documentation since I posted this thread up. That's the same version of the same doc as you mentioned in the first post of the thread :) Andrew ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] how to implement Transactions (over different db tables) in a Catalyst project
On Mon, Jul 6, 2009 at 3:36 PM, kakim...@tpg.com.au wrote: However, this is NOT a Catalyst question. Please subscribe to the DBIx::Class users list at: http://lists.scsys.co.uk/mailman/listinfo/dbix-class/ and ask these questions there. Many of the subscribers are the same, but many Catalyst users don't use DBIx::Class, and many knowledgeable DBIC users are not subscribed here. It's just good hygiene to ask the questions in the appropriate places. there's somethign wrong with the mailing list for Dbix::Class as I have not been able to get replies /mails. I have contacted the admin in the past and never got any reply. I will retry. Nevertheless, given that Dbix::Class is of the choice for catalyst, I figured the grey area here may see my questions lucky enough to have some replies from the many who use Dbix::Class for their Catalyst apps. Considering the same people/software/servers run both the DBIC list and the Catalyst list, I'm going to assume you're both lazy and inept. Doubly so for re-asking the question immediately on the Catalyst list. You are not entitled to get free help just because you can compose an email. あなたは怠け者。 ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] how to implement Transactions (over different db tables) in a Catalyst project
On Tue, Jul 7th, 2009 at 8:54 AM, J. Shirley jshir...@gmail.com wrote: On Mon, Jul 6, 2009 at 3:36 PM, kakim...@tpg.com.au wrote: there's somethign wrong with the mailing list for Dbix::Class as I have not been able to get replies /mails. I have contacted the admin in the past and never got any reply. I will retry. Sorry if it caused any inconvenience , guys:( Considering the same people/software/servers run both the DBIC list and the Catalyst list, I'm going to assume you're both lazy and inept. Doubly so for re-asking the question immediately on the Catalyst list. You are not entitled to get free help just because you can compose an email. $B$$J$?$OBU$1T!#(B ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
[Catalyst] how to implement Transactions (over different db tables) in a Catalyst project
hi , everyone, i m trying to put transactions in place for my catalyst project. For example, I would like to create a new user subscription. What this does is, - create two new Address objects (Address db table) where one's for billing address and another for main contact. - create a new User Subscriptions object (and link the two new Address objects by IDs into attributes, billing_address_id and main_contact_address_id). What I have refered to: http://search.cpan.org/~ribasushi/DBIx-Class-0.08107/lib/DBIx/Class/Manual/Cookbook.pod http://kobesearch.cpan.org/htdocs/DBIx-Class/DBIx/Class/Storage.html#txn_do http://kobesearch.cpan.org/htdocs/DBIx-Class/DBIx/Class/Storage.html#txn_begin http://kobesearch.cpan.org/htdocs/DBIx-Class/DBIx/Class/Storage.html#txn_commit http://search.cpan.org/~ribasushi/DBIx-Class-0.08107/lib/DBIx/Class/Storage.pm In the past, when I had to work with just DBI, I would manually start a transaction and commit it at the end if no exceptions occur. In the case of the latter, I will call a rollback. How do I do it here in Catalyst/DbiX::Class land? I tried to read up the http://kobesearch.cpan.org/htdocs/DBIx-Class/DBIx/Class/Storage.html#txn_do doc but I can't see how the example can apply to Catalyst. It says, $schema-txn_do($coderef) to get the schema but in catalyst, we access the database tables directly. For example, my $rs = $c-model('myAppDB::UserSusbcriptions')-search( .. ); I'm a bit confused and have looked in a few places. Can anyone please educate me? thank you:) K.akimoto ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/