File Coverage

blib/lib/Helios/ObjectDriver/DBI.pm
Criterion Covered Total %
statement 11 26 42.3
branch 0 12 0.0
condition n/a
subroutine 4 6 66.6
pod 0 1 0.0
total 15 45 33.3


line stmt bran cond sub pod time code
1             package Helios::ObjectDriver::DBI;
2              
3 1     1   20 use 5.008;
  1         3  
4 1     1   6 use strict;
  1         2  
  1         28  
5 1     1   6 use warnings;
  1         1  
  1         35  
6 1     1   6 use base qw(Data::ObjectDriver::Driver::DBI);
  1         1  
  1         816  
7              
8             our $VERSION = '2.61';
9              
10             # [LH] 2012-07-11: Changed the DBI connection creation to use connect_cached()
11             # instead of connect() to implement connection caching. Also added
12             # 'private_heliconn_$pid' option to ensure connections opened by separate
13             # processes stay separated.
14              
15              
16             my %Handles;
17             sub init_db {
18 0     0 0   my $driver = shift;
19 0           my $dbh;
20 0 0         if ($driver->reuse_dbh) {
21 0           $dbh = $Handles{$driver->dsn};
22             }
23 0 0         unless ($dbh) {
24 0           eval {
25             # [LH] 2012-07-11: Changed the DBI connection creation to use
26             # connect_cached() instead of connect() to implement connection
27             # caching. Also added 'private_heliconn_$pid' option to ensure
28             # connections opened by separate processes stay separated.
29             $dbh = DBI->connect_cached($driver->dsn, $driver->username, $driver->password,
30             { RaiseError => 1, PrintError => 0, AutoCommit => 1, 'private_heliconn_'.$$ => $$,
31 0 0         %{$driver->connect_options || {}} })
  0 0          
32             or Carp::croak("Connection error: " . $DBI::errstr);
33             };
34 0 0         if ($@) {
35 0           Carp::croak($@);
36             }
37             }
38 0 0         if ($driver->reuse_dbh) {
39 0           $Handles{$driver->dsn} = $dbh;
40             }
41 0           $driver->dbd->init_dbh($dbh);
42 0           $driver->{__dbh_init_by_driver} = 1;
43 0           return $dbh;
44             }
45              
46              
47       0     sub DESTROY {
48             # [LH] 2012-07-11: Removed DBI->disconnect() call.
49             # Unlike in the base Data::ObjectDriver::Driver::DBI
50             # we don't want to disconnect the database connection
51             # EVEN IF we created it.
52             # We'll let DBI handle disconnection exclusively
53             }
54              
55             1;
56             __END__