File Coverage

blib/lib/Helios/ObjectDriver/DBI.pm
Criterion Covered Total %
statement 12 12 100.0
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 16 16 100.0


line stmt bran cond sub pod time code
1             package Helios::ObjectDriver::DBI;
2              
3 1     1   13 use 5.008;
  1         3  
  1         30  
4 1     1   4 use strict;
  1         1  
  1         20  
5 1     1   4 use warnings;
  1         1  
  1         19  
6 1     1   3 use base qw(Data::ObjectDriver::Driver::DBI);
  1         1  
  1         502  
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             my $driver = shift;
19             my $dbh;
20             if ($driver->reuse_dbh) {
21             $dbh = $Handles{$driver->dsn};
22             }
23             unless ($dbh) {
24             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             %{$driver->connect_options || {}} })
32             or Carp::croak("Connection error: " . $DBI::errstr);
33             };
34             if ($@) {
35             Carp::croak($@);
36             }
37             }
38             if ($driver->reuse_dbh) {
39             $Handles{$driver->dsn} = $dbh;
40             }
41             $driver->dbd->init_dbh($dbh);
42             $driver->{__dbh_init_by_driver} = 1;
43             return $dbh;
44             }
45              
46              
47             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__