X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/1c103b3a9a96a045a221760af82bc99093b3076c..87eebe6:/SL/DB.pm diff --git a/SL/DB.pm b/SL/DB.pm index 861fe6a52..90e08c582 100644 --- a/SL/DB.pm +++ b/SL/DB.pm @@ -38,9 +38,7 @@ sub create { my %_dateformats = ( 'yy-mm-dd' => 'ISO', 'yyyy-mm-dd' => 'ISO', 'mm/dd/yy' => 'SQL, US', - 'mm-dd-yy' => 'POSTGRES, US', 'dd/mm/yy' => 'SQL, EUROPEAN', - 'dd-mm-yy' => 'POSTGRES, EUROPEAN', 'dd.mm.yy' => 'GERMAN' ); @@ -128,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