Hello,

I thought I understood how to organize several write operations within a
transaction but it still doesn't work the way I do it.
Here is what I have so far:

In my base class:
sub init_db {
    my $self = shift;
    my $db;
    if (not $self->my_db) {
        $self->my_db( MyApp::DB->new() );
    }
    return $self->my_db;
}
{ # closure
    my $db;
    sub my_db {
        my $self = shift;
        if(@_) {
            $db = $_[0];
        }
        return $db;
    }
}
The idea is that I don't have to write
'db => $db' in every call.

In my script (run through mod_perl if it makes a difference):

my $db = MyApp::DB->new;
$self->my_db($db); # a new db for a new transaction
$db->begin_work;  # Start transaction

... create two objects and save them ...

die "Does it roll back?";
$db->commit;

But when I run this script the two records are saved to the database and
not rolled back.

Edit: It is even more mysterious: The saved records are only there as
long as apache isn't restartet. I tried clearing the cache, calling the
records in different ways, no matter they are there. After a restart
they are not. It looks as if the rollback is not done at the "die" of
the script but the 'kill' of the server ?!?

I have basically two questions:
- What is wrong with my code? Why doesn't it work
- Are there better variants for init_db? Ideally I would like to share a
  db throughout a mod_perl request but not longer.
  This way I would just wrap every handler that writes to the database
  within a $db->begin_work / $db->commit and could be sure that either
  everything or nothing is saved.

Any ideas?

Thanks
- Michael

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Rose-db-object mailing list
Rose-db-object@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rose-db-object

Reply via email to