X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/30d4e2f70ea5fe8c6457b862f13e5835953e9e5c..7cfa1f2ab3091d8b44e91aa5ce12c70052250003:/SL/DB.pm diff --git a/SL/DB.pm b/SL/DB.pm index dd551636b..90e08c582 100644 --- a/SL/DB.pm +++ b/SL/DB.pm @@ -126,4 +126,65 @@ sub _flatten_settings { return %flattened; } +sub with_transaction { + my ($self, $code, @args) = @_; + + return $self->in_transaction ? $code->(@args) : $self->do_transaction(sub { $code->(@args) }); +} + 1; +__END__ + +=pod + +=encoding utf8 + +=head1 NAME + +SL::DB - Database access class for all RDB objects + +=head1 FUNCTIONS + +=over 4 + +=item C + +Registers the database information with Rose, creates a cached +connection and executes initial SQL statements. Those can include +setting the time & date format to the user's preferences. + +=item C + +Forwards the call to L which connects to the +database. This indirection allows L to route +the calls through L if this is enabled in the +configuration. + +=item C + +Executes C<$code_ref> within a transaction, starting one if none is +currently active. This is just a shortcut for the following code: + + # Verbose code in caller (an RDBO instance): + my $worker = sub { + # do stuff with $self + }; + return $self->db->in_transaction ? $worker->() : $self->db->do_transaction($worker); + +Now the version using C: + + return $self->db->with_transaction(sub { + # do stuff with $self + }); + +=back + +=head1 BUGS + +Nothing here yet. + +=head1 AUTHOR + +Moritz Bunkus Em.bunkus@linet-services.deE + +=cut