X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FDBConnect%2FCache.pm;h=c133e8a3db641f6e713e8f06b28f388ee0dc9fa5;hb=53593baa211863fbf66540cf1bcc36c8fb37257f;hp=b04a5b4e20b0cc78cd6346562f98d8a607e8a18b;hpb=ffa9f969259970df45ea2353a94d1a67e8612731;p=kivitendo-erp.git diff --git a/SL/DBConnect/Cache.pm b/SL/DBConnect/Cache.pm index b04a5b4e2..c133e8a3d 100644 --- a/SL/DBConnect/Cache.pm +++ b/SL/DBConnect/Cache.pm @@ -35,14 +35,23 @@ sub reset { $dbh; } +sub reset_all { + $_->{AutoCommit} || $_->rollback for values %cache; +} + sub clear { %cache = (); } +sub disconnect_all_and_clear { + $_->disconnect for values %cache; + %cache = (); +} + sub _args2str { my (@args) = @_; - my ($dbconnect, $dbuser, $dbpasswd, $options) = @_; + my ($dbconnect, $dbuser, $dbpasswd, $options, $initial_sql) = @_; $dbconnect //= ''; $dbuser //= ''; $dbpasswd //= ''; @@ -52,7 +61,7 @@ sub _args2str { map { $_ => $options->{$_} } sort keys %$options; # deterministic order - join ';', apply { s/([;\\])/\\$1/g } $dbconnect, $dbuser, $dbpasswd, $options_str; + join ';', apply { $_ //= ''; s/([;\\])/\\$1/g } $dbconnect, $dbuser, $dbpasswd, $options_str, $initial_sql; } 1; @@ -67,26 +76,26 @@ SL::DBConnect::Cache - cached database handle pool =head1 SYNOPSIS - use SL::SBConnect::Cache; + use SL::DBConnect::Cache; - my $dbh = SL::DBConnct::Cache->get(@args); - SL::DBConnct::Cache->store($dbh, @args); + my $dbh = SL::DBConnect::Cache->get(@args); + SL::DBConnect::Cache->store($dbh, @args); # reset a cached handle - SL::DBConnct::Cache->reset($dbh); + SL::DBConnect::Cache->reset($dbh); # close a cached handle and forget it - SL::DBConnct::Cache->close($dbh); + SL::DBConnect::Cache->close($dbh); - SL::DBConnct::Cache->clear($dbh); + SL::DBConnect::Cache->clear($dbh); =head1 DESCRIPTION -Implementes a managed cache for DB connection handles. +Implements a managed cache for DB connection handles. The same would be possible with C<< DBI->connect_cached >>, but in that case, -we would have no control ver the cache. +we would have no control over the cache. =head1 METHODS @@ -106,7 +115,7 @@ Rollback the connection specified by C. =item * C -Emties the cache. If handles are not referenced otherwise, they will get +Empties the cache. If handles are not referenced otherwise, they will get dropped and closed. =back